From bfc850e99a26747de847fcc15b4786836e8dc4c0 Mon Sep 17 00:00:00 2001 From: CreepySkeleton Date: Thu, 5 Mar 2020 11:35:21 +0300 Subject: [PATCH] Suppress warnings in generated code --- clap_derive/src/derives/from_argmatches.rs | 80 ++++++++++++++-------- clap_derive/src/derives/into_app.rs | 24 +++++++ clap_derive/src/derives/subcommand.rs | 12 ++++ 3 files changed, 88 insertions(+), 28 deletions(-) diff --git a/clap_derive/src/derives/from_argmatches.rs b/clap_derive/src/derives/from_argmatches.rs index 1201d9314c9..40113029cee 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, + 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, parent_attribute: &Attrs, @@ -155,31 +207,3 @@ pub fn gen_constructor( #( #fields ),* }} } - -pub fn gen_for_struct( - struct_name: &syn::Ident, - fields: &Punctuated, - 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 a705b3b580d..da4c8c1afc9 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 6e167b08097..7b04eb7a079 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