mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 15:27:16 +00:00
Merge pull request #4952 from epage/derive
fix(derive): Don't warn when people bring types into scope
This commit is contained in:
commit
468ab556a6
8 changed files with 82 additions and 8 deletions
|
@ -4030,7 +4030,7 @@ impl Command {
|
||||||
}
|
}
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
for mut sc in &mut self.subcommands {
|
for sc in &mut self.subcommands {
|
||||||
debug!("Command::_build_bin_names:iter: bin_name set...");
|
debug!("Command::_build_bin_names:iter: bin_name set...");
|
||||||
|
|
||||||
if sc.usage_name.is_none() {
|
if sc.usage_name.is_none() {
|
||||||
|
|
|
@ -86,7 +86,13 @@ pub fn gen_for_struct(
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
|
#[allow(
|
||||||
|
dead_code,
|
||||||
|
unreachable_code,
|
||||||
|
unused_variables,
|
||||||
|
unused_braces,
|
||||||
|
unused_qualifications,
|
||||||
|
)]
|
||||||
#[allow(
|
#[allow(
|
||||||
clippy::style,
|
clippy::style,
|
||||||
clippy::complexity,
|
clippy::complexity,
|
||||||
|
@ -99,6 +105,7 @@ pub fn gen_for_struct(
|
||||||
clippy::suspicious_else_formatting,
|
clippy::suspicious_else_formatting,
|
||||||
clippy::almost_swapped,
|
clippy::almost_swapped,
|
||||||
)]
|
)]
|
||||||
|
#[automatically_derived]
|
||||||
impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
|
impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
|
||||||
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
|
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
|
||||||
Self::from_arg_matches_mut(&mut __clap_arg_matches.clone())
|
Self::from_arg_matches_mut(&mut __clap_arg_matches.clone())
|
||||||
|
@ -121,7 +128,13 @@ pub fn gen_for_struct(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
|
#[allow(
|
||||||
|
dead_code,
|
||||||
|
unreachable_code,
|
||||||
|
unused_variables,
|
||||||
|
unused_braces,
|
||||||
|
unused_qualifications,
|
||||||
|
)]
|
||||||
#[allow(
|
#[allow(
|
||||||
clippy::style,
|
clippy::style,
|
||||||
clippy::complexity,
|
clippy::complexity,
|
||||||
|
@ -134,6 +147,7 @@ pub fn gen_for_struct(
|
||||||
clippy::suspicious_else_formatting,
|
clippy::suspicious_else_formatting,
|
||||||
clippy::almost_swapped,
|
clippy::almost_swapped,
|
||||||
)]
|
)]
|
||||||
|
#[automatically_derived]
|
||||||
impl #impl_generics clap::Args for #item_name #ty_generics #where_clause {
|
impl #impl_generics clap::Args for #item_name #ty_generics #where_clause {
|
||||||
fn group_id() -> Option<clap::Id> {
|
fn group_id() -> Option<clap::Id> {
|
||||||
#group_id
|
#group_id
|
||||||
|
|
|
@ -29,7 +29,13 @@ pub fn gen_for_struct(
|
||||||
let app_var = Ident::new("__clap_app", Span::call_site());
|
let app_var = Ident::new("__clap_app", Span::call_site());
|
||||||
|
|
||||||
let tokens = quote! {
|
let tokens = quote! {
|
||||||
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
|
#[allow(
|
||||||
|
dead_code,
|
||||||
|
unreachable_code,
|
||||||
|
unused_variables,
|
||||||
|
unused_braces,
|
||||||
|
unused_qualifications,
|
||||||
|
)]
|
||||||
#[allow(
|
#[allow(
|
||||||
clippy::style,
|
clippy::style,
|
||||||
clippy::complexity,
|
clippy::complexity,
|
||||||
|
@ -42,6 +48,7 @@ pub fn gen_for_struct(
|
||||||
clippy::suspicious_else_formatting,
|
clippy::suspicious_else_formatting,
|
||||||
clippy::almost_swapped,
|
clippy::almost_swapped,
|
||||||
)]
|
)]
|
||||||
|
#[automatically_derived]
|
||||||
impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
|
impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
|
||||||
fn command<'b>() -> clap::Command {
|
fn command<'b>() -> clap::Command {
|
||||||
let #app_var = clap::Command::new(#name);
|
let #app_var = clap::Command::new(#name);
|
||||||
|
@ -69,7 +76,13 @@ pub fn gen_for_enum(
|
||||||
let app_var = Ident::new("__clap_app", Span::call_site());
|
let app_var = Ident::new("__clap_app", Span::call_site());
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
|
#[allow(
|
||||||
|
dead_code,
|
||||||
|
unreachable_code,
|
||||||
|
unused_variables,
|
||||||
|
unused_braces,
|
||||||
|
unused_qualifications,
|
||||||
|
)]
|
||||||
#[allow(
|
#[allow(
|
||||||
clippy::style,
|
clippy::style,
|
||||||
clippy::complexity,
|
clippy::complexity,
|
||||||
|
@ -82,6 +95,7 @@ pub fn gen_for_enum(
|
||||||
clippy::suspicious_else_formatting,
|
clippy::suspicious_else_formatting,
|
||||||
clippy::almost_swapped,
|
clippy::almost_swapped,
|
||||||
)]
|
)]
|
||||||
|
#[automatically_derived]
|
||||||
impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
|
impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
|
||||||
fn command<'b>() -> clap::Command {
|
fn command<'b>() -> clap::Command {
|
||||||
let #app_var = clap::Command::new(#name)
|
let #app_var = clap::Command::new(#name)
|
||||||
|
|
|
@ -86,6 +86,10 @@ fn gen_for_struct(
|
||||||
let args = args::gen_for_struct(item, item_name, generics, fields)?;
|
let args = args::gen_for_struct(item, item_name, generics, fields)?;
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
|
#[automatically_derived]
|
||||||
|
#[allow(
|
||||||
|
unused_qualifications,
|
||||||
|
)]
|
||||||
impl #impl_generics clap::Parser for #item_name #ty_generics #where_clause {}
|
impl #impl_generics clap::Parser for #item_name #ty_generics #where_clause {}
|
||||||
|
|
||||||
#into_app
|
#into_app
|
||||||
|
@ -105,6 +109,7 @@ fn gen_for_enum(
|
||||||
let subcommand = subcommand::gen_for_enum(item, item_name, generics, variants)?;
|
let subcommand = subcommand::gen_for_enum(item, item_name, generics, variants)?;
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
|
#[automatically_derived]
|
||||||
impl #impl_generics clap::Parser for #item_name #ty_generics #where_clause {}
|
impl #impl_generics clap::Parser for #item_name #ty_generics #where_clause {}
|
||||||
|
|
||||||
#into_app
|
#into_app
|
||||||
|
|
|
@ -66,7 +66,13 @@ pub fn gen_for_enum(
|
||||||
let has_subcommand = gen_has_subcommand(variants)?;
|
let has_subcommand = gen_has_subcommand(variants)?;
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
|
#[allow(
|
||||||
|
dead_code,
|
||||||
|
unreachable_code,
|
||||||
|
unused_variables,
|
||||||
|
unused_braces,
|
||||||
|
unused_qualifications,
|
||||||
|
)]
|
||||||
#[allow(
|
#[allow(
|
||||||
clippy::style,
|
clippy::style,
|
||||||
clippy::complexity,
|
clippy::complexity,
|
||||||
|
@ -79,6 +85,7 @@ pub fn gen_for_enum(
|
||||||
clippy::suspicious_else_formatting,
|
clippy::suspicious_else_formatting,
|
||||||
clippy::almost_swapped,
|
clippy::almost_swapped,
|
||||||
)]
|
)]
|
||||||
|
#[automatically_derived]
|
||||||
impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
|
impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
|
||||||
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
|
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
|
||||||
Self::from_arg_matches_mut(&mut __clap_arg_matches.clone())
|
Self::from_arg_matches_mut(&mut __clap_arg_matches.clone())
|
||||||
|
@ -92,7 +99,13 @@ pub fn gen_for_enum(
|
||||||
#update_from_arg_matches
|
#update_from_arg_matches
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
|
#[allow(
|
||||||
|
dead_code,
|
||||||
|
unreachable_code,
|
||||||
|
unused_variables,
|
||||||
|
unused_braces,
|
||||||
|
unused_qualifications,
|
||||||
|
)]
|
||||||
#[allow(
|
#[allow(
|
||||||
clippy::style,
|
clippy::style,
|
||||||
clippy::complexity,
|
clippy::complexity,
|
||||||
|
@ -105,6 +118,7 @@ pub fn gen_for_enum(
|
||||||
clippy::suspicious_else_formatting,
|
clippy::suspicious_else_formatting,
|
||||||
clippy::almost_swapped,
|
clippy::almost_swapped,
|
||||||
)]
|
)]
|
||||||
|
#[automatically_derived]
|
||||||
impl #impl_generics clap::Subcommand for #item_name #ty_generics #where_clause {
|
impl #impl_generics clap::Subcommand for #item_name #ty_generics #where_clause {
|
||||||
fn augment_subcommands <'b>(__clap_app: clap::Command) -> clap::Command {
|
fn augment_subcommands <'b>(__clap_app: clap::Command) -> clap::Command {
|
||||||
#augmentation
|
#augmentation
|
||||||
|
|
|
@ -51,7 +51,13 @@ pub fn gen_for_enum(
|
||||||
let to_possible_value = gen_to_possible_value(item, &lits);
|
let to_possible_value = gen_to_possible_value(item, &lits);
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
|
#[allow(
|
||||||
|
dead_code,
|
||||||
|
unreachable_code,
|
||||||
|
unused_variables,
|
||||||
|
unused_braces,
|
||||||
|
unused_qualifications,
|
||||||
|
)]
|
||||||
#[allow(
|
#[allow(
|
||||||
clippy::style,
|
clippy::style,
|
||||||
clippy::complexity,
|
clippy::complexity,
|
||||||
|
@ -64,6 +70,7 @@ pub fn gen_for_enum(
|
||||||
clippy::suspicious_else_formatting,
|
clippy::suspicious_else_formatting,
|
||||||
clippy::almost_swapped,
|
clippy::almost_swapped,
|
||||||
)]
|
)]
|
||||||
|
#[automatically_derived]
|
||||||
impl clap::ValueEnum for #item_name {
|
impl clap::ValueEnum for #item_name {
|
||||||
#value_variants
|
#value_variants
|
||||||
#to_possible_value
|
#to_possible_value
|
||||||
|
|
|
@ -7,6 +7,7 @@ use quote::quote;
|
||||||
pub fn parser(name: &Ident) -> proc_macro2::TokenStream {
|
pub fn parser(name: &Ident) -> proc_macro2::TokenStream {
|
||||||
let into_app = into_app(name);
|
let into_app = into_app(name);
|
||||||
quote!(
|
quote!(
|
||||||
|
#[automatically_derived]
|
||||||
impl clap::Parser for #name {}
|
impl clap::Parser for #name {}
|
||||||
#into_app
|
#into_app
|
||||||
)
|
)
|
||||||
|
@ -15,6 +16,7 @@ pub fn parser(name: &Ident) -> proc_macro2::TokenStream {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn into_app(name: &Ident) -> proc_macro2::TokenStream {
|
pub fn into_app(name: &Ident) -> proc_macro2::TokenStream {
|
||||||
quote! {
|
quote! {
|
||||||
|
#[automatically_derived]
|
||||||
impl clap::CommandFactory for #name {
|
impl clap::CommandFactory for #name {
|
||||||
fn command<'b>() -> clap::Command {
|
fn command<'b>() -> clap::Command {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
@ -29,6 +31,7 @@ pub fn into_app(name: &Ident) -> proc_macro2::TokenStream {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn from_arg_matches(name: &Ident) -> proc_macro2::TokenStream {
|
pub fn from_arg_matches(name: &Ident) -> proc_macro2::TokenStream {
|
||||||
quote! {
|
quote! {
|
||||||
|
#[automatically_derived]
|
||||||
impl clap::FromArgMatches for #name {
|
impl clap::FromArgMatches for #name {
|
||||||
fn from_arg_matches(_m: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
|
fn from_arg_matches(_m: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
@ -44,6 +47,7 @@ pub fn from_arg_matches(name: &Ident) -> proc_macro2::TokenStream {
|
||||||
pub fn subcommand(name: &Ident) -> proc_macro2::TokenStream {
|
pub fn subcommand(name: &Ident) -> proc_macro2::TokenStream {
|
||||||
let from_arg_matches = from_arg_matches(name);
|
let from_arg_matches = from_arg_matches(name);
|
||||||
quote! {
|
quote! {
|
||||||
|
#[automatically_derived]
|
||||||
impl clap::Subcommand for #name {
|
impl clap::Subcommand for #name {
|
||||||
fn augment_subcommands(_cmd: clap::Command) -> clap::Command {
|
fn augment_subcommands(_cmd: clap::Command) -> clap::Command {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
@ -63,6 +67,7 @@ pub fn subcommand(name: &Ident) -> proc_macro2::TokenStream {
|
||||||
pub fn args(name: &Ident) -> proc_macro2::TokenStream {
|
pub fn args(name: &Ident) -> proc_macro2::TokenStream {
|
||||||
let from_arg_matches = from_arg_matches(name);
|
let from_arg_matches = from_arg_matches(name);
|
||||||
quote! {
|
quote! {
|
||||||
|
#[automatically_derived]
|
||||||
impl clap::Args for #name {
|
impl clap::Args for #name {
|
||||||
fn augment_args(_cmd: clap::Command) -> clap::Command {
|
fn augment_args(_cmd: clap::Command) -> clap::Command {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
@ -78,6 +83,7 @@ pub fn args(name: &Ident) -> proc_macro2::TokenStream {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn value_enum(name: &Ident) -> proc_macro2::TokenStream {
|
pub fn value_enum(name: &Ident) -> proc_macro2::TokenStream {
|
||||||
quote! {
|
quote! {
|
||||||
|
#[automatically_derived]
|
||||||
impl clap::ValueEnum for #name {
|
impl clap::ValueEnum for #name {
|
||||||
fn value_variants<'a>() -> &'a [Self]{
|
fn value_variants<'a>() -> &'a [Self]{
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
|
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
|
||||||
// MIT/Apache 2.0 license.
|
// MIT/Apache 2.0 license.
|
||||||
|
|
||||||
|
#![deny(unused_qualifications)]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
@ -51,3 +52,16 @@ fn warning_never_enum() {
|
||||||
Opt::try_parse_from(["test", "foo", "foo"]).unwrap()
|
Opt::try_parse_from(["test", "foo", "foo"]).unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn warning_unused_qualifications() {
|
||||||
|
// This causes `clap::Args` within the derive to be unused qualifications
|
||||||
|
use clap::Args;
|
||||||
|
|
||||||
|
#[derive(Args, Clone, Copy, Debug, Default)]
|
||||||
|
#[group(skip)]
|
||||||
|
pub struct Compose<L: Args> {
|
||||||
|
#[command(flatten)]
|
||||||
|
pub left: L,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue