Skip to content

Commit

Permalink
fix(derive): Don't warn when people bring types into scope
Browse files Browse the repository at this point in the history
Fixes #4951
  • Loading branch information
epage committed Jun 5, 2023
1 parent 5661b6b commit 103ae5c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 7 deletions.
16 changes: 14 additions & 2 deletions clap_derive/src/derives/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ pub fn gen_for_struct(
};

Ok(quote! {
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
#[allow(
dead_code,
unreachable_code,
unused_variables,
unused_braces,
unused_qualifications,
)]
#[allow(
clippy::style,
clippy::complexity,
Expand Down Expand Up @@ -122,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(
clippy::style,
clippy::complexity,
Expand Down
16 changes: 14 additions & 2 deletions clap_derive/src/derives/into_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ pub fn gen_for_struct(
let app_var = Ident::new("__clap_app", Span::call_site());

let tokens = quote! {
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
#[allow(
dead_code,
unreachable_code,
unused_variables,
unused_braces,
unused_qualifications,
)]
#[allow(
clippy::style,
clippy::complexity,
Expand Down Expand Up @@ -70,7 +76,13 @@ pub fn gen_for_enum(
let app_var = Ident::new("__clap_app", Span::call_site());

Ok(quote! {
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
#[allow(
dead_code,
unreachable_code,
unused_variables,
unused_braces,
unused_qualifications,
)]
#[allow(
clippy::style,
clippy::complexity,
Expand Down
3 changes: 3 additions & 0 deletions clap_derive/src/derives/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ fn gen_for_struct(

Ok(quote! {
#[automatically_derived]
#[allow(
unused_qualifications,
)]
impl #impl_generics clap::Parser for #item_name #ty_generics #where_clause {}

#into_app
Expand Down
16 changes: 14 additions & 2 deletions clap_derive/src/derives/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ pub fn gen_for_enum(
let has_subcommand = gen_has_subcommand(variants)?;

Ok(quote! {
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
#[allow(
dead_code,
unreachable_code,
unused_variables,
unused_braces,
unused_qualifications,
)]
#[allow(
clippy::style,
clippy::complexity,
Expand All @@ -93,7 +99,13 @@ pub fn gen_for_enum(
#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(
clippy::style,
clippy::complexity,
Expand Down
8 changes: 7 additions & 1 deletion clap_derive/src/derives/value_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ pub fn gen_for_enum(
let to_possible_value = gen_to_possible_value(item, &lits);

Ok(quote! {
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
#[allow(
dead_code,
unreachable_code,
unused_variables,
unused_braces,
unused_qualifications,
)]
#[allow(
clippy::style,
clippy::complexity,
Expand Down
14 changes: 14 additions & 0 deletions tests/derive/deny_warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
// MIT/Apache 2.0 license.

#![deny(unused_qualifications)]
#![deny(warnings)]

use clap::Parser;
Expand Down Expand Up @@ -51,3 +52,16 @@ fn warning_never_enum() {
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,
}
}

0 comments on commit 103ae5c

Please sign in to comment.