Skip to content

Commit

Permalink
Emit dummy impls on error (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
CreepySkeleton authored and TeXitoi committed Sep 2, 2019
1 parent 14937e8 commit 40e9ab4
Show file tree
Hide file tree
Showing 39 changed files with 177 additions and 58 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# v0.3.1 (2019-08-31)
* Fix error messages ([#241](https://github.com/TeXitoi/structopt/issues/241))
* Fix "`skip` plus long doc comment" bug ([#245](https://github.com/TeXitoi/structopt/issues/245))
* Now `structopt` emits dummy `StructOpt` implementation along with an error. It suppresses
meaningless errors like `from_args method is not found for Opt`

# v0.3.0 (2019-08-30)

Expand Down
2 changes: 1 addition & 1 deletion structopt-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ syn = { version = "1", features = ["full"] }
quote = "1"
proc-macro2 = "1"
heck = "0.3.0"
proc-macro-error = "0.2"
proc-macro-error = "0.2.6"

[features]
paw = []
Expand Down
14 changes: 13 additions & 1 deletion structopt-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
};

use proc_macro2::{Span, TokenStream};
use proc_macro_error::{call_site_error, filter_macro_errors, span_error};
use proc_macro_error::{call_site_error, filter_macro_errors, set_dummy, span_error};
use quote::{quote, quote_spanned};
use syn::{punctuated::Punctuated, spanned::Spanned, token::Comma, *};

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

let struct_name = &input.ident;

set_dummy(Some(quote! {
impl ::structopt::StructOpt for #struct_name {
fn clap<'a, 'b>() -> ::structopt::clap::App<'a, 'b> {
unimplemented!()
}
fn from_clap(_matches: &::structopt::clap::ArgMatches) -> Self {
unimplemented!()
}
}
}));

match input.data {
Struct(DataStruct {
fields: syn::Fields::Named(ref fields),
Expand Down
5 changes: 4 additions & 1 deletion tests/ui-1.39_post/opt_opt_nonpositional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ struct Opt {
n: Option<Option<u32>>,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-1.39_post/opt_vec_nonpositional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ struct Opt {
n: Option<Vec<u32>>,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
9 changes: 6 additions & 3 deletions tests/ui-1.39_post/subcommand_opt_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(StructOpt, Debug)]
#[structopt(name = "make-cookie")]
struct MakeCookie {
#[structopt(short)]
Expand All @@ -18,7 +18,7 @@ struct MakeCookie {
cmd: Option<Option<Command>>,
}

#[derive(StructOpt)]
#[derive(StructOpt, Debug)]
enum Command {
#[structopt(name = "pound")]
/// Pound acorns into flour for cookie dough.
Expand All @@ -30,4 +30,7 @@ enum Command {
},
}

fn main() {}
fn main() {
let opt = MakeCookie::from_args();
println!("{:?}", opt);
}
9 changes: 6 additions & 3 deletions tests/ui-1.39_post/subcommand_opt_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(StructOpt, Debug)]
#[structopt(name = "make-cookie")]
struct MakeCookie {
#[structopt(short)]
Expand All @@ -18,7 +18,7 @@ struct MakeCookie {
cmd: Option<Vec<Command>>,
}

#[derive(StructOpt)]
#[derive(StructOpt, Debug)]
enum Command {
#[structopt(name = "pound")]
/// Pound acorns into flour for cookie dough.
Expand All @@ -30,4 +30,7 @@ enum Command {
},
}

fn main() {}
fn main() {
let opt = MakeCookie::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/bool_default_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
b: bool,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/bool_required.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
b: bool,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/flatten_and_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ struct Opt {
opts: DaemonOpts,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/flatten_and_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ struct Opt {
opts: DaemonOpts,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/flatten_and_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ struct Opt {
opts: DaemonOpts,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/non_existent_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
debug: bool,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/option_default_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
n: Option<u32>,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/option_required.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
n: Option<u32>,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/parse_empty_try_from_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
s: String,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/parse_function_is_not_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
s: String,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/parse_literal_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
s: String,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/parse_not_zero_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
s: String,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui/raw.rs → tests/ui-common/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ struct Opt {
s: String,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
2 changes: 1 addition & 1 deletion tests/ui/raw.stderr → tests/ui-common/raw.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: `#[structopt(raw(...))` attributes are deprecated in structopt 3.0, only `raw(true)` and `raw(false)` are allowed
error: `#[structopt(raw(...))` attributes are deprecated in structopt 0.3, only `raw(true)` and `raw(false)` are allowed
--> $DIR/raw.rs:13:17
|
13 | #[structopt(raw(case_insensitive = "true"))]
Expand Down
5 changes: 4 additions & 1 deletion tests/ui-common/rename_all_wrong_casing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
s: String,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
9 changes: 6 additions & 3 deletions tests/ui-common/skip_flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(StructOpt, Debug)]
#[structopt(name = "make-cookie")]
struct MakeCookie {
#[structopt(short)]
Expand All @@ -18,7 +18,7 @@ struct MakeCookie {
cmd: Command,
}

#[derive(StructOpt)]
#[derive(StructOpt, Debug)]
enum Command {
#[structopt(name = "pound")]
/// Pound acorns into flour for cookie dough.
Expand All @@ -36,4 +36,7 @@ impl Default for Command {
}
}

fn main() {}
fn main() {
let opt = MakeCookie::from_args();
println!("{:?}", opt);
}
9 changes: 6 additions & 3 deletions tests/ui-common/skip_subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(StructOpt, Debug)]
#[structopt(name = "make-cookie")]
struct MakeCookie {
#[structopt(short)]
Expand All @@ -18,7 +18,7 @@ struct MakeCookie {
cmd: Command,
}

#[derive(StructOpt)]
#[derive(StructOpt, Debug)]
enum Command {
#[structopt(name = "pound")]
/// Pound acorns into flour for cookie dough.
Expand All @@ -36,4 +36,7 @@ impl Default for Command {
}
}

fn main() {}
fn main() {
let opt = MakeCookie::from_args();
println!("{:?}", opt);
}
7 changes: 5 additions & 2 deletions tests/ui-common/skip_with_other_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "test")]
pub struct Opts {
pub struct Opt {
#[structopt(long)]
a: u32,
#[structopt(skip, long)]
b: u32,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
7 changes: 5 additions & 2 deletions tests/ui-common/skip_without_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ enum Kind {

#[derive(StructOpt, Debug)]
#[structopt(name = "test")]
pub struct Opts {
pub struct Opt {
#[structopt(short)]
number: u32,
#[structopt(skip)]
k: Kind,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/struct_flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
s: String,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/struct_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
s: String,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/struct_subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct Opt {
s: String,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
5 changes: 4 additions & 1 deletion tests/ui-common/structopt_empty_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ struct Opt {
debug: bool,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}

5 changes: 4 additions & 1 deletion tests/ui-common/structopt_name_value_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ struct Opt {
debug: bool,
}

fn main() {}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}

0 comments on commit 40e9ab4

Please sign in to comment.