From 215677bfa7648faea32fec6586eb4984f074e43f Mon Sep 17 00:00:00 2001 From: tormol Date: Wed, 5 Oct 2016 19:35:15 +0200 Subject: [PATCH 1/4] style: remove #[allow("warning that apparently doesn't exist")] I say "apparently" because it's listed on https://manishearth.github.io/rust-clippy/master/ and not as deprecated. --- tests/tests.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tests.rs b/tests/tests.rs index c059e05d..d0735a0d 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -115,7 +115,6 @@ arg_enum!{ } #[test] -#[cfg_attr(feature = "lints", allow(single_match))] fn test_enums() { let v1_lower = "valone"; let v1_camel = "ValOne"; From 102fb7d2ce9df949e9b332fa87437c0ee31de760 Mon Sep 17 00:00:00 2001 From: tormol Date: Wed, 5 Oct 2016 11:46:55 +0200 Subject: [PATCH 2/4] style: fix lints in yaml-related functions --- src/app/mod.rs | 31 +++++++++++++------------------ src/args/arg.rs | 2 +- src/args/subcommand.rs | 2 +- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index d9526114..8e87c0a8 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1422,16 +1422,14 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> { a = a.setting(s.parse().expect("unknown AppSetting found in YAML file")); } } - } else { - if let Some(v) = yaml["settings"].as_str() { - a = a.setting(v.parse().expect("unknown AppSetting found in YAML file")); - } else if yaml["settings"] != Yaml::BadValue { - panic!("Failed to convert YAML value {:?} to a string", - yaml["settings"]); - } + } else if let Some(v) = yaml["settings"].as_str() { + a = a.setting(v.parse().expect("unknown AppSetting found in YAML file")); + } else if yaml["settings"] != Yaml::BadValue { + panic!("Failed to convert YAML value {:?} to a string", + yaml["settings"]); } if let Some(v) = yaml["global_setting"].as_str() { - a = a.setting(v.parse().ok().expect("unknown AppSetting found in YAML file")); + a = a.setting(v.parse().expect("unknown AppSetting found in YAML file")); } else if yaml["global_setting"] != Yaml::BadValue { panic!("Failed to convert YAML value {:?} to an AppSetting", yaml["setting"]); @@ -1440,17 +1438,14 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> { for ys in v { if let Some(s) = ys.as_str() { a = a.global_setting(s.parse() - .ok() .expect("unknown AppSetting found in YAML file")); } } - } else { - if let Some(v) = yaml["global_settings"].as_str() { - a = a.global_setting(v.parse().expect("unknown AppSetting found in YAML file")); - } else if yaml["global_settings"] != Yaml::BadValue { - panic!("Failed to convert YAML value {:?} to a string", - yaml["global_settings"]); - } + } else if let Some(v) = yaml["global_settings"].as_str() { + a = a.global_setting(v.parse().expect("unknown AppSetting found in YAML file")); + } else if yaml["global_settings"] != Yaml::BadValue { + panic!("Failed to convert YAML value {:?} to a string", + yaml["global_settings"]); } macro_rules! vec_or_str { @@ -1481,12 +1476,12 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> { if let Some(v) = yaml["args"].as_vec() { for arg_yaml in v { - a = a.arg(Arg::from_yaml(&arg_yaml.as_hash().unwrap())); + a = a.arg(Arg::from_yaml(arg_yaml.as_hash().unwrap())); } } if let Some(v) = yaml["subcommands"].as_vec() { for sc_yaml in v { - a = a.subcommand(SubCommand::from_yaml(&sc_yaml)); + a = a.subcommand(SubCommand::from_yaml(sc_yaml)); } } if let Some(v) = yaml["groups"].as_vec() { diff --git a/src/args/arg.rs b/src/args/arg.rs index e1a35887..2f2b8a89 100644 --- a/src/args/arg.rs +++ b/src/args/arg.rs @@ -141,7 +141,7 @@ impl<'a, 'b> Arg<'a, 'b> { /// ``` /// [`Arg`]: ./struct.Arg.html #[cfg(feature = "yaml")] - pub fn from_yaml<'y>(y: &'y BTreeMap) -> Arg<'y, 'y> { + pub fn from_yaml(y: &BTreeMap) -> Arg { // We WANT this to panic on error...so expect() is good. let name_yml = y.keys().nth(0).unwrap(); let name_str = name_yml.as_str().unwrap(); diff --git a/src/args/subcommand.rs b/src/args/subcommand.rs index 06d0769b..4b9a6a3d 100644 --- a/src/args/subcommand.rs +++ b/src/args/subcommand.rs @@ -62,7 +62,7 @@ impl<'a> SubCommand<'a> { /// let sc = SubCommand::from_yaml(sc_yaml); /// ``` #[cfg(feature = "yaml")] - pub fn from_yaml<'y>(yaml: &'y Yaml) -> App<'y, 'y> { + pub fn from_yaml(yaml: &Yaml) -> App { App::from_yaml(yaml) } } From 7f797e68d8f721dff9553ba0ba5616efc456ebb5 Mon Sep 17 00:00:00 2001 From: tormol Date: Wed, 5 Oct 2016 19:32:59 +0200 Subject: [PATCH 3/4] style: fix lints in code that's not compiled if the opt-out feature "color" is set --- src/fmt.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fmt.rs b/src/fmt.rs index 8b1ccf19..3f52efd9 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -13,9 +13,9 @@ const STDERR: i32 = libc::STDERR_FILENO; #[cfg(all(feature = "color", not(target_os = "windows")))] const STDOUT: i32 = libc::STDOUT_FILENO; -#[cfg(any(not(feature = "color"), target_os = "windows"))] +#[cfg(target_os = "windows")] const STDERR: i32 = 0; -#[cfg(any(not(feature = "color"), target_os = "windows"))] +#[cfg(target_os = "windows")] const STDOUT: i32 = 0; #[doc(hidden)] @@ -127,6 +127,7 @@ impl> Format { } #[cfg(any(not(feature = "color"), target_os = "windows"))] +#[allow(match_same_arms)] impl Format { fn format(&self) -> &T { match *self { From 5778871951e92cb2d0f747b6de9d241dfed6013c Mon Sep 17 00:00:00 2001 From: tormol Date: Wed, 5 Oct 2016 19:28:44 +0200 Subject: [PATCH 4/4] style: remove the `.ok()` in `result.ok().expect("...")` clippy doesn't check doc-tests and `include!()`d files, so there might bee more un-reported lint. --- clap-test.rs | 6 +++--- src/app/mod.rs | 4 ++-- tests/app_settings.rs | 2 +- tests/hidden_args.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clap-test.rs b/clap-test.rs index 0de3790e..41f2172e 100644 --- a/clap-test.rs +++ b/clap-test.rs @@ -57,7 +57,7 @@ mod test { // Now we check the output of print_help() let mut help = vec![]; - sc.write_help(&mut help).ok().expect("failed to print help"); + sc.write_help(&mut help).expect("failed to print help"); assert_eq!(str::from_utf8(&help).unwrap(), out); } @@ -67,7 +67,7 @@ mod test { // Now we check the output of print_help() let mut help = vec![]; - a.write_help(&mut help).ok().expect("failed to print help"); + a.write_help(&mut help).expect("failed to print help"); assert_eq!(str::from_utf8(&help).unwrap(), out); } @@ -77,7 +77,7 @@ mod test { // Now we check the output of print_version() let mut ver = vec![]; - a.write_version(&mut ver).ok().expect("failed to print help"); + a.write_version(&mut ver).expect("failed to print help"); assert_eq!(str::from_utf8(&ver).unwrap(), out); } diff --git a/src/app/mod.rs b/src/app/mod.rs index 8e87c0a8..440ab8fd 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1013,7 +1013,7 @@ impl<'a, 'b> App<'a, 'b> { /// use std::io; /// let mut app = App::new("myprog"); /// let mut out = io::stdout(); - /// app.write_help(&mut out).ok().expect("failed to write to stdout"); + /// app.write_help(&mut out).expect("failed to write to stdout"); /// ``` /// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html pub fn write_help(&self, w: &mut W) -> ClapResult<()> { @@ -1029,7 +1029,7 @@ impl<'a, 'b> App<'a, 'b> { /// use std::io; /// let mut app = App::new("myprog"); /// let mut out = io::stdout(); - /// app.write_version(&mut out).ok().expect("failed to write to stdout"); + /// app.write_version(&mut out).expect("failed to write to stdout"); /// ``` /// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html pub fn write_version(&self, w: &mut W) -> ClapResult<()> { diff --git a/tests/app_settings.rs b/tests/app_settings.rs index 14fb7cc6..5e3c4ac5 100644 --- a/tests/app_settings.rs +++ b/tests/app_settings.rs @@ -88,7 +88,7 @@ fn unified_help() { // Now we check the output of print_help() let mut help = vec![]; - app.write_help(&mut help).ok().expect("failed to print help"); + app.write_help(&mut help).expect("failed to print help"); assert_eq!(&*String::from_utf8_lossy(&*help), &*String::from("test 1.3\n\ Kevin K. tests stuff diff --git a/tests/hidden_args.rs b/tests/hidden_args.rs index cf52e485..0d0c7ccf 100644 --- a/tests/hidden_args.rs +++ b/tests/hidden_args.rs @@ -16,7 +16,7 @@ fn hidden_args() { // Now we check the output of print_help() let mut help = vec![]; - app.write_help(&mut help).ok().expect("failed to print help"); + app.write_help(&mut help).expect("failed to print help"); assert_eq!(&*String::from_utf8_lossy(&*help), &*String::from("test 1.3\n\ Kevin K. tests stuff