Skip to content

Commit 40e9ab4

Browse files
CreepySkeletonTeXitoi
authored andcommitted
Emit dummy impls on error (#248)
1 parent 14937e8 commit 40e9ab4

39 files changed

Lines changed: 177 additions & 58 deletions

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# v0.3.1 (2019-08-31)
22
* Fix error messages ([#241](https://github.com/TeXitoi/structopt/issues/241))
33
* Fix "`skip` plus long doc comment" bug ([#245](https://github.com/TeXitoi/structopt/issues/245))
4+
* Now `structopt` emits dummy `StructOpt` implementation along with an error. It suppresses
5+
meaningless errors like `from_args method is not found for Opt`
46

57
# v0.3.0 (2019-08-30)
68

structopt-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ syn = { version = "1", features = ["full"] }
1818
quote = "1"
1919
proc-macro2 = "1"
2020
heck = "0.3.0"
21-
proc-macro-error = "0.2"
21+
proc-macro-error = "0.2.6"
2222

2323
[features]
2424
paw = []

structopt-derive/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
};
2323

2424
use proc_macro2::{Span, TokenStream};
25-
use proc_macro_error::{call_site_error, filter_macro_errors, span_error};
25+
use proc_macro_error::{call_site_error, filter_macro_errors, set_dummy, span_error};
2626
use quote::{quote, quote_spanned};
2727
use syn::{punctuated::Punctuated, spanned::Spanned, token::Comma, *};
2828

@@ -519,6 +519,18 @@ fn impl_structopt(input: &DeriveInput) -> TokenStream {
519519
use syn::Data::*;
520520

521521
let struct_name = &input.ident;
522+
523+
set_dummy(Some(quote! {
524+
impl ::structopt::StructOpt for #struct_name {
525+
fn clap<'a, 'b>() -> ::structopt::clap::App<'a, 'b> {
526+
unimplemented!()
527+
}
528+
fn from_clap(_matches: &::structopt::clap::ArgMatches) -> Self {
529+
unimplemented!()
530+
}
531+
}
532+
}));
533+
522534
match input.data {
523535
Struct(DataStruct {
524536
fields: syn::Fields::Named(ref fields),

tests/ui-1.39_post/opt_opt_nonpositional.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ struct Opt {
1414
n: Option<Option<u32>>,
1515
}
1616

17-
fn main() {}
17+
fn main() {
18+
let opt = Opt::from_args();
19+
println!("{:?}", opt);
20+
}

tests/ui-1.39_post/opt_vec_nonpositional.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ struct Opt {
1414
n: Option<Vec<u32>>,
1515
}
1616

17-
fn main() {}
17+
fn main() {
18+
let opt = Opt::from_args();
19+
println!("{:?}", opt);
20+
}

tests/ui-1.39_post/subcommand_opt_opt.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use structopt::StructOpt;
1010

11-
#[derive(StructOpt)]
11+
#[derive(StructOpt, Debug)]
1212
#[structopt(name = "make-cookie")]
1313
struct MakeCookie {
1414
#[structopt(short)]
@@ -18,7 +18,7 @@ struct MakeCookie {
1818
cmd: Option<Option<Command>>,
1919
}
2020

21-
#[derive(StructOpt)]
21+
#[derive(StructOpt, Debug)]
2222
enum Command {
2323
#[structopt(name = "pound")]
2424
/// Pound acorns into flour for cookie dough.
@@ -30,4 +30,7 @@ enum Command {
3030
},
3131
}
3232

33-
fn main() {}
33+
fn main() {
34+
let opt = MakeCookie::from_args();
35+
println!("{:?}", opt);
36+
}

tests/ui-1.39_post/subcommand_opt_vec.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use structopt::StructOpt;
1010

11-
#[derive(StructOpt)]
11+
#[derive(StructOpt, Debug)]
1212
#[structopt(name = "make-cookie")]
1313
struct MakeCookie {
1414
#[structopt(short)]
@@ -18,7 +18,7 @@ struct MakeCookie {
1818
cmd: Option<Vec<Command>>,
1919
}
2020

21-
#[derive(StructOpt)]
21+
#[derive(StructOpt, Debug)]
2222
enum Command {
2323
#[structopt(name = "pound")]
2424
/// Pound acorns into flour for cookie dough.
@@ -30,4 +30,7 @@ enum Command {
3030
},
3131
}
3232

33-
fn main() {}
33+
fn main() {
34+
let opt = MakeCookie::from_args();
35+
println!("{:?}", opt);
36+
}

tests/ui-common/bool_default_value.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ struct Opt {
1515
b: bool,
1616
}
1717

18-
fn main() {}
18+
fn main() {
19+
let opt = Opt::from_args();
20+
println!("{:?}", opt);
21+
}

tests/ui-common/bool_required.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ struct Opt {
1515
b: bool,
1616
}
1717

18-
fn main() {}
18+
fn main() {
19+
let opt = Opt::from_args();
20+
println!("{:?}", opt);
21+
}

tests/ui-common/flatten_and_doc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ struct Opt {
2424
opts: DaemonOpts,
2525
}
2626

27-
fn main() {}
27+
fn main() {
28+
let opt = Opt::from_args();
29+
println!("{:?}", opt);
30+
}

0 commit comments

Comments
 (0)