Skip to content

Commit dc5ec7a

Browse files
CreepySkeletonTeXitoi
authored andcommitted
Emit error about raw removal
1 parent a91109c commit dc5ec7a

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

structopt-derive/src/attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl Attrs {
244244

245245
MethodCall(name, args) => self.methods.push(Method {
246246
name: name.into(),
247-
args: quote!(#args),
247+
args: quote!(#(#args),*),
248248
}),
249249

250250
RenameAll(_, casing_lit) => {

structopt-derive/src/parse.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,22 @@ impl Parse for StructOptAttr {
121121
}
122122
}
123123

124+
"raw" => {
125+
match nested.parse::<LitBool>() {
126+
Ok(bool_token) => {
127+
let expr = ExprLit { attrs: vec![], lit: Lit::Bool(bool_token) };
128+
let expr = Expr::Lit(expr);
129+
Ok(MethodCall(name, vec![expr]))
130+
}
131+
132+
Err(_) => span_error!(name.span(),
133+
"`#[structopt(raw(...))` attributes are deprecated in structopt 3.0, only `raw(true)` and `raw(false)` are allowed")
134+
}
135+
}
136+
124137
_ => {
125-
let method_args = nested.parse_terminated(Expr::parse)?;
126-
Ok(MethodCall(name, method_args))
138+
let method_args: Punctuated<_, Token![,]> = nested.parse_terminated(Expr::parse)?;
139+
Ok(MethodCall(name, Vec::from_iter(method_args)))
127140
}
128141
}
129142
} else {

tests/raw_bool_literal.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>
2+
//
3+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6+
// option. This file may not be copied, modified, or distributed
7+
// except according to those terms.
8+
9+
use structopt::clap;
10+
use structopt::StructOpt;
11+
12+
#[test]
13+
fn raw_bool_literal() {
14+
#[derive(StructOpt, Debug, PartialEq)]
15+
#[structopt(no_version, name = "raw_bool")]
16+
struct Opt {
17+
#[structopt(raw(false))]
18+
a: String,
19+
#[structopt(raw(true))]
20+
b: String,
21+
}
22+
23+
assert_eq!(
24+
Opt {
25+
a: "one".into(),
26+
b: "--help".into()
27+
},
28+
Opt::from_iter(&["test", "one", "--", "--help"])
29+
);
30+
}

tests/ui/raw.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>
2+
//
3+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6+
// option. This file may not be copied, modified, or distributed
7+
// except according to those terms.
8+
9+
use structopt::StructOpt;
10+
11+
#[derive(StructOpt, Debug)]
12+
struct Opt {
13+
#[structopt(raw(case_insensitive = "true"))]
14+
s: String,
15+
}
16+
17+
fn main() {}

tests/ui/raw.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: `#[structopt(raw(...))` attributes are deprecated in structopt 3.0, only `raw(true)` and `raw(false)` are allowed
2+
--> $DIR/raw.rs:13:17
3+
|
4+
13 | #[structopt(raw(case_insensitive = "true"))]
5+
| ^^^

0 commit comments

Comments
 (0)