Skip to content

Commit

Permalink
Suppress warnings in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
CreepySkeleton committed Mar 5, 2020
1 parent 54f2072 commit bfc850e
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 28 deletions.
80 changes: 52 additions & 28 deletions clap_derive/src/derives/from_argmatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
}
}
}
24 changes: 24 additions & 0 deletions clap_derive/src/derives/into_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions clap_derive/src/derives/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bfc850e

Please sign in to comment.