Repository: clap-rs/clap
Pull request #1726 (2020-03-05 09:17:25)

Derive clippy
<!--
If your PR closes some issues, please write `Closes #XXXX`
where `XXXX` is the number of the issue you want to fix.
Each issue goes on it's own line.
-->

With this, our CI logs will hopefully become clean.


Patch:
diff --git a/clap_derive/examples/skip.rs b/clap_derive/examples/skip.rs
index efb17740..216cbe46 100644
--- a/clap_derive/examples/skip.rs
+++ b/clap_derive/examples/skip.rs
@@ -27,7 +27,7 @@ enum Kind {
 
 impl Default for Kind {
     fn default() -> Self {
-        return Kind::B;
+        Kind::B
     }
 }
 
diff --git a/clap_derive/src/derives/from_argmatches.rs b/clap_derive/src/derives/from_argmatches.rs
index 1201d931..40113029 100644
--- a/clap_derive/src/derives/from_argmatches.rs
+++ b/clap_derive/src/derives/from_argmatches.rs
@@ -16,6 +16,58 @@ use syn::{punctuated::Punctuated, spanned::Spanned, Token};
 
 use super::{sub_type, Attrs, Kind, ParserKind, Ty};
 
+pub fn gen_for_struct(
+    struct_name: &syn::Ident,
+    fields: &Punctuated<syn::Field, Token![,]>,
+    parent_attribute: &Attrs,
+) -> proc_macro2::TokenStream {
+    let constructor = gen_constructor(fields, parent_attribute);
+
+    quote! {
+        #[allow(dead_code, unreachable_code, unused_variables)]
+        #[allow(
+            clippy::style,
+            clippy::complexity,
+            clippy::pedantic,
+            clippy::restriction,
+            clippy::perf,
+            clippy::deprecated,
+            clippy::nursery,
+            clippy::cargo
+        )]
+        #[deny(clippy::correctness)]
+        impl ::clap::FromArgMatches for #struct_name {
+            fn from_arg_matches(matches: &::clap::ArgMatches) -> Self {
+                #struct_name #constructor
+            }
+        }
+    }
+}
+
+pub fn gen_for_enum(name: &syn::Ident) -> proc_macro2::TokenStream {
+    quote! {
+        #[allow(dead_code, unreachable_code, unused_variables)]
+        #[allow(
+            clippy::style,
+            clippy::complexity,
+            clippy::pedantic,
+            clippy::restriction,
+            clippy::perf,
+            clippy::deprecated,
+            clippy::nursery,
+            clippy::cargo
+        )]
+        #[deny(clippy::correctness)]
+        impl ::clap::FromArgMatches for #name {
+            fn from_arg_matches(matches: &::clap::ArgMatches) -> Self {
+                let (name, subcmd) = matches.subcommand();
+                <#name as ::clap::Subcommand>::from_subcommand(name, subcmd)
+                    .unwrap()
+            }
+        }
+    }
+}
+
 pub fn gen_constructor(
     fields: &Punctuated<syn::Field, Token![,]>,
     parent_attribute: &Attrs,
@@ -155,31 +207,3 @@ pub fn gen_constructor(
         #( #fields ),*
     }}
 }
-
-pub fn gen_for_struct(
-    struct_name: &syn::Ident,
-    fields: &Punctuated<syn::Field, Token![,]>,
-    parent_attribute: &Attrs,
-) -> proc_macro2::TokenStream {
-    let constructor = gen_constructor(fields, parent_attribute);
-
-    quote! {
-        impl ::clap::FromArgMatches for #struct_name {
-            fn from_arg_matches(matches: &::clap::ArgMatches) -> Self {
-                #struct_name #constructor
-            }
-        }
-    }
-}
-
-pub fn gen_for_enum(name: &syn::Ident) -> proc_macro2::TokenStream {
-    quote! {
-        impl ::clap::FromArgMatches for #name {
-            fn from_arg_matches(matches: &::clap::ArgMatches) -> Self {
-                let (name, subcmd) = matches.subcommand();
-                <#name as ::clap::Subcommand>::from_subcommand(name, subcmd)
-                    .unwrap()
-            }
-        }
-    }
-}
diff --git a/clap_derive/src/derives/into_app.rs b/clap_derive/src/derives/into_app.rs
index a705b3b5..da4c8c1a 100644
--- a/clap_derive/src/derives/into_app.rs
+++ b/clap_derive/src/derives/into_app.rs
@@ -34,6 +34,18 @@ pub fn gen_for_struct(
     let augment_clap = gen_augment_clap_fn(fields, &attrs);
 
     let tokens = quote! {
+        #[allow(dead_code, unreachable_code, unused_variables)]
+        #[allow(
+            clippy::style,
+            clippy::complexity,
+            clippy::pedantic,
+            clippy::restriction,
+            clippy::perf,
+            clippy::deprecated,
+            clippy::nursery,
+            clippy::cargo
+        )]
+        #[deny(clippy::correctness)]
         impl ::clap::IntoApp for #struct_name {
             #into_app
             #augment_clap
@@ -47,6 +59,18 @@ pub fn gen_for_enum(name: &syn::Ident) -> TokenStream {
     let app_name = env::var("CARGO_PKG_NAME").ok().unwrap_or_default();
 
     quote! {
+        #[allow(dead_code, unreachable_code, unused_variables)]
+        #[allow(
+            clippy::style,
+            clippy::complexity,
+            clippy::pedantic,
+            clippy::restriction,
+            clippy::perf,
+            clippy::deprecated,
+            clippy::nursery,
+            clippy::cargo
+        )]
+        #[deny(clippy::correctness)]
         impl ::clap::IntoApp for #name {
             fn into_app<'b>() -> ::clap::App<'b> {
                 let app = ::clap::App::new(#app_name)
diff --git a/clap_derive/src/derives/subcommand.rs b/clap_derive/src/derives/subcommand.rs
index 6e167b08..7b04eb7a 100644
--- a/clap_derive/src/derives/subcommand.rs
+++ b/clap_derive/src/derives/subcommand.rs
@@ -21,6 +21,18 @@ pub fn gen_for_enum(name: &Ident, attrs: &[Attribute], e: &DataEnum) -> TokenStr
     let augment_subcommands = gen_augment_subcommands(&e.variants, &attrs);
 
     quote! {
+        #[allow(dead_code, unreachable_code, unused_variables)]
+        #[allow(
+            clippy::style,
+            clippy::complexity,
+            clippy::pedantic,
+            clippy::restriction,
+            clippy::perf,
+            clippy::deprecated,
+            clippy::nursery,
+            clippy::cargo
+        )]
+        #[deny(clippy::correctness)]
         impl ::clap::Subcommand for #name {
             #augment_subcommands
             #from_subcommand
diff --git a/examples/14_groups.rs b/examples/14_groups.rs
index e72da1cc..b9c3b54a 100644
--- a/examples/14_groups.rs
+++ b/examples/14_groups.rs
@@ -80,7 +80,7 @@ fn main() {
     if matches.is_present("config") {
         let input = matches
             .value_of("INPUT_FILE")
-            .unwrap_or(matches.value_of("SPEC_IN").unwrap());
+            .unwrap_or_else(|| matches.value_of("SPEC_IN").unwrap());
         println!(
             "Doing work using input {} and config {}",
             input,


Test patch:
diff --git a/clap_derive/tests/options.rs b/clap_derive/tests/options.rs
index 08c58d10..34d2eae2 100644
--- a/clap_derive/tests/options.rs
+++ b/clap_derive/tests/options.rs
@@ -12,6 +12,8 @@
 // commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
 // MIT/Apache 2.0 license.
 
+#![allow(clippy::option_option)]
+
 use clap::Clap;
 
 #[test]
diff --git a/clap_generate/tests/completions.rs b/clap_generate/tests/completions.rs
index 05b1e66e..5409ae96 100644
--- a/clap_generate/tests/completions.rs
+++ b/clap_generate/tests/completions.rs
@@ -17,7 +17,7 @@ macro_rules! assert_eq {
     };
 }
 
-static BASH: &'static str = r#"_myapp() {
+static BASH: &str = r#"_myapp() {
     local i cur prev opts cmds
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
@@ -100,7 +100,7 @@ static BASH: &'static str = r#"_myapp() {
 complete -F _myapp -o bashdefault -o default myapp
 "#;
 
-static ZSH: &'static str = r#"#compdef myapp
+static ZSH: &str = r#"#compdef myapp
 
 autoload -U is-at-least
 
@@ -178,7 +178,7 @@ _myapp__test_commands() {
 
 _myapp "$@""#;
 
-static FISH: &'static str = r#"complete -c myapp -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
+static FISH: &str = r#"complete -c myapp -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
 complete -c myapp -n "__fish_use_subcommand" -s V -l version -d 'Prints version information'
 complete -c myapp -n "__fish_use_subcommand" -f -a "test" -d 'tests things'
 complete -c myapp -n "__fish_use_subcommand" -f -a "help" -d 'Prints this message or the help of the given subcommand(s)'
@@ -189,7 +189,7 @@ complete -c myapp -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints
 complete -c myapp -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information'
 "#;
 
-static POWERSHELL: &'static str = r#"
+static POWERSHELL: &str = r#"
 using namespace System.Management.Automation
 using namespace System.Management.Automation.Language
 
@@ -241,7 +241,7 @@ Register-ArgumentCompleter -Native -CommandName 'my_app' -ScriptBlock {
 }
 "#;
 
-static ELVISH: &'static str = r#"
+static ELVISH: &str = r#"
 edit:completion:arg-completer[my_app] = [@words]{
     fn spaces [n]{
         repeat $n ' ' | joins ''
@@ -283,7 +283,7 @@ edit:completion:arg-completer[my_app] = [@words]{
 }
 "#;
 
-static ELVISH_SPECIAL_CMDS: &'static str = r#"
+static ELVISH_SPECIAL_CMDS: &str = r#"
 edit:completion:arg-completer[my_app] = [@words]{
     fn spaces [n]{
         repeat $n ' ' | joins ''
@@ -340,7 +340,7 @@ edit:completion:arg-completer[my_app] = [@words]{
 }
 "#;
 
-static POWERSHELL_SPECIAL_CMDS: &'static str = r#"
+static POWERSHELL_SPECIAL_CMDS: &str = r#"
 using namespace System.Management.Automation
 using namespace System.Management.Automation.Language
 
@@ -409,7 +409,7 @@ Register-ArgumentCompleter -Native -CommandName 'my_app' -ScriptBlock {
 }
 "#;
 
-static ZSH_SPECIAL_CMDS: &'static str = r#"#compdef my_app
+static ZSH_SPECIAL_CMDS: &str = r#"#compdef my_app
 
 autoload -U is-at-least
 
@@ -520,7 +520,7 @@ _my_app__test_commands() {
 
 _my_app "$@""#;
 
-static FISH_SPECIAL_CMDS: &'static str = r#"complete -c my_app -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
+static FISH_SPECIAL_CMDS: &str = r#"complete -c my_app -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
 complete -c my_app -n "__fish_use_subcommand" -s V -l version -d 'Prints version information'
 complete -c my_app -n "__fish_use_subcommand" -f -a "test" -d 'tests things'
 complete -c my_app -n "__fish_use_subcommand" -f -a "some_cmd" -d 'tests other things'
@@ -538,7 +538,7 @@ complete -c my_app -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints
 complete -c my_app -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information'
 "#;
 
-static BASH_SPECIAL_CMDS: &'static str = r#"_my_app() {
+static BASH_SPECIAL_CMDS: &str = r#"_my_app() {
     local i cur prev opts cmds
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
@@ -661,7 +661,7 @@ static BASH_SPECIAL_CMDS: &'static str = r#"_my_app() {
 complete -F _my_app -o bashdefault -o default my_app
 "#;
 
-static FISH_SPECIAL_HELP: &'static str = r#"complete -c my_app -n "__fish_use_subcommand" -l single-quotes -d 'Can be \'always\', \'auto\', or \'never\''
+static FISH_SPECIAL_HELP: &str = r#"complete -c my_app -n "__fish_use_subcommand" -l single-quotes -d 'Can be \'always\', \'auto\', or \'never\''
 complete -c my_app -n "__fish_use_subcommand" -l double-quotes -d 'Can be "always", "auto", or "never"'
 complete -c my_app -n "__fish_use_subcommand" -l backticks -d 'For more information see `echo test`'
 complete -c my_app -n "__fish_use_subcommand" -l backslash -d 'Avoid \'\\n\''
@@ -671,7 +671,7 @@ complete -c my_app -n "__fish_use_subcommand" -s h -l help -d 'Prints help infor
 complete -c my_app -n "__fish_use_subcommand" -s V -l version -d 'Prints version information'
 "#;
 
-static ZSH_SPECIAL_HELP: &'static str = r#"#compdef my_app
+static ZSH_SPECIAL_HELP: &str = r#"#compdef my_app
 
 autoload -U is-at-least
 
diff --git a/tests/app_settings.rs b/tests/app_settings.rs
index 266c064e..68bc4f89 100644
--- a/tests/app_settings.rs
+++ b/tests/app_settings.rs
@@ -788,7 +788,7 @@ fn external_subcommand_looks_like_built_in() {
             assert_eq!(name, "install-update");
             assert_eq!(args.values_of_lossy(""), Some(vec!["foo".to_string()]));
         }
-        _ => assert!(false),
+        _ => panic!("external_subcommand didn't work"),
     }
 }
 
diff --git a/tests/require.rs b/tests/require.rs
index 1589fb92..ae8f9a6a 100644
--- a/tests/require.rs
+++ b/tests/require.rs
@@ -708,25 +708,23 @@ fn issue_1158_conflicting_requirements_rev() {
 fn issue_1643_args_mutually_require_each_other() {
     use clap::*;
 
-    fn main() {
-        let app = App::new("test")
-            .arg(
-                Arg::with_name("relation_id")
-                    .help("The relation id to get the data from")
-                    .long("relation-id")
-                    .short('r')
-                    .takes_value(true)
-                    .requires("remote_unit_name"),
-            )
-            .arg(
-                Arg::with_name("remote_unit_name")
-                    .help("The name of the remote unit to get data from")
-                    .long("remote-unit")
-                    .short('u')
-                    .takes_value(true)
-                    .requires("relation_id"),
-            );
-
-        app.get_matches_from(&["test", "-u", "hello"]);
-    }
+    let app = App::new("test")
+        .arg(
+            Arg::with_name("relation_id")
+                .help("The relation id to get the data from")
+                .long("relation-id")
+                .short('r')
+                .takes_value(true)
+                .requires("remote_unit_name"),
+        )
+        .arg(
+            Arg::with_name("remote_unit_name")
+                .help("The name of the remote unit to get data from")
+                .long("remote-unit")
+                .short('u')
+                .takes_value(true)
+                .requires("relation_id"),
+        );
+
+    app.get_matches_from(&["test", "-u", "hello", "-r", "farewell"]);
 }