Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 committed Jan 18, 2021
1 parent d36d6dd commit 941ddc6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
13 changes: 6 additions & 7 deletions clap_derive/src/attrs.rs
Expand Up @@ -118,7 +118,7 @@ impl Method {
Method { name, args }
}

fn from_lit_or_env(ident: Ident, lit: Option<LitStr>, env_var: &str) -> Option<Self> {
fn from_lit_or_env(ident: Ident, lit: Option<LitStr>, env_var: &str) -> Self {
let mut lit = match lit {
Some(lit) => lit,

Expand All @@ -139,7 +139,7 @@ impl Method {
lit = LitStr::new(&edited, lit.span());
}

Some(Method::new(ident, quote!(#lit)))
Method::new(ident, quote!(#lit))
}
}

Expand Down Expand Up @@ -372,17 +372,16 @@ impl Attrs {

About(ident, about) => {
let method = Method::from_lit_or_env(ident, about, "CARGO_PKG_DESCRIPTION");
if let Some(m) = method {
self.methods.push(m);
}
self.methods.push(method);
}

Author(ident, author) => {
self.author = Method::from_lit_or_env(ident, author, "CARGO_PKG_AUTHORS");
self.author = Some(Method::from_lit_or_env(ident, author, "CARGO_PKG_AUTHORS"));
}

Version(ident, version) => {
self.version = Method::from_lit_or_env(ident, version, "CARGO_PKG_VERSION");
self.version =
Some(Method::from_lit_or_env(ident, version, "CARGO_PKG_VERSION"));
}

NameLitStr(name, lit) => {
Expand Down
22 changes: 11 additions & 11 deletions clap_derive/tests/arg_enum.rs
Expand Up @@ -21,7 +21,7 @@ fn basic() {
struct Opt {
#[clap(arg_enum)]
arg: ArgChoice,
};
}

assert_eq!(
Opt {
Expand Down Expand Up @@ -51,7 +51,7 @@ fn multi_word_is_renamed_kebab() {
struct Opt {
#[clap(arg_enum)]
arg: ArgChoice,
};
}

assert_eq!(
Opt {
Expand Down Expand Up @@ -80,7 +80,7 @@ fn variant_with_defined_casing() {
struct Opt {
#[clap(arg_enum)]
arg: ArgChoice,
};
}

assert_eq!(
Opt {
Expand All @@ -103,7 +103,7 @@ fn casing_is_propogated_from_parent() {
struct Opt {
#[clap(arg_enum)]
arg: ArgChoice,
};
}

assert_eq!(
Opt {
Expand All @@ -127,7 +127,7 @@ fn casing_propogation_is_overridden() {
struct Opt {
#[clap(arg_enum)]
arg: ArgChoice,
};
}

assert_eq!(
Opt {
Expand All @@ -150,7 +150,7 @@ fn case_insensitive() {
struct Opt {
#[clap(arg_enum, case_insensitive(true))]
arg: ArgChoice,
};
}

assert_eq!(
Opt {
Expand All @@ -177,7 +177,7 @@ fn case_insensitive_set_to_false() {
struct Opt {
#[clap(arg_enum, case_insensitive(false))]
arg: ArgChoice,
};
}

assert_eq!(
Opt {
Expand All @@ -200,7 +200,7 @@ fn alias() {
struct Opt {
#[clap(arg_enum, case_insensitive(false))]
arg: ArgChoice,
};
}

assert_eq!(
Opt {
Expand Down Expand Up @@ -228,7 +228,7 @@ fn multiple_alias() {
struct Opt {
#[clap(arg_enum, case_insensitive(false))]
arg: ArgChoice,
};
}

assert_eq!(
Opt {
Expand Down Expand Up @@ -262,7 +262,7 @@ fn option() {
struct Opt {
#[clap(arg_enum)]
arg: Option<ArgChoice>,
};
}

assert_eq!(Opt { arg: None }, Opt::parse_from(&[""]));
assert_eq!(
Expand Down Expand Up @@ -292,7 +292,7 @@ fn vector() {
struct Opt {
#[clap(arg_enum, short, long)]
arg: Vec<ArgChoice>,
};
}

assert_eq!(Opt { arg: vec![] }, Opt::parse_from(&[""]));
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions src/parse/matches/arg_matches.rs
Expand Up @@ -1026,7 +1026,7 @@ impl<'a> Default for Values<'a> {
// This is never called because the iterator is empty:
fn to_str_slice(_: &OsString) -> &str {
unreachable!()
};
}
Values {
iter: EMPTY[..].iter().flatten().map(to_str_slice),
}
Expand Down Expand Up @@ -1087,7 +1087,7 @@ impl Default for OsValues<'_> {
// This is never called because the iterator is empty:
fn to_str_slice(_: &OsString) -> &OsStr {
unreachable!()
};
}
OsValues {
iter: EMPTY[..].iter().flatten().map(to_str_slice),
}
Expand Down

0 comments on commit 941ddc6

Please sign in to comment.