Skip to content

Commit

Permalink
fix(derive): Allow clippy::almost_swapped
Browse files Browse the repository at this point in the history
As of Rust 1.69, the `clippy::almost_swapped` lint was enhanced and now
triggers on certain derive macros inside clap. To avoid the need for the
user to allow these lints outside of the macro (which generally requires
a module level `allow`), the allow was added to the generated code for
the v4 branch in clap-rs#4735.

This change backports that fix the the `v3-master` branch.

Fixes: clap-rs#4857
  • Loading branch information
hds committed Apr 27, 2023
1 parent f617f13 commit b8ca734
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clap_derive/src/derives/args.rs
Expand Up @@ -84,6 +84,7 @@ pub fn gen_for_struct(
clippy::nursery,
clippy::cargo,
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
impl #impl_generics clap::Args for #struct_name #ty_generics #where_clause {
fn augment_args<'b>(#app_var: clap::Command<'b>) -> clap::Command<'b> {
Expand Down Expand Up @@ -128,6 +129,7 @@ pub fn gen_from_arg_matches_for_struct(
clippy::nursery,
clippy::cargo,
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
impl #impl_generics clap::FromArgMatches for #struct_name #ty_generics #where_clause {
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
Expand Down
2 changes: 2 additions & 0 deletions clap_derive/src/derives/into_app.rs
Expand Up @@ -54,6 +54,7 @@ pub fn gen_for_struct(
clippy::nursery,
clippy::cargo,
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
#[allow(deprecated)]
impl #impl_generics clap::CommandFactory for #struct_name #ty_generics #where_clause {
Expand Down Expand Up @@ -99,6 +100,7 @@ pub fn gen_for_enum(enum_name: &Ident, generics: &Generics, attrs: &[Attribute])
clippy::nursery,
clippy::cargo,
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
impl #impl_generics clap::CommandFactory for #enum_name #ty_generics #where_clause {
fn into_app<'b>() -> clap::Command<'b> {
Expand Down
2 changes: 2 additions & 0 deletions clap_derive/src/derives/subcommand.rs
Expand Up @@ -72,6 +72,7 @@ pub fn gen_for_enum(
clippy::nursery,
clippy::cargo,
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
impl #impl_generics clap::Subcommand for #enum_name #ty_generics #where_clause {
fn augment_subcommands <'b>(__clap_app: clap::Command<'b>) -> clap::Command<'b> {
Expand Down Expand Up @@ -118,6 +119,7 @@ fn gen_from_arg_matches_for_enum(
clippy::nursery,
clippy::cargo,
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
impl #impl_generics clap::FromArgMatches for #name #ty_generics #where_clause {
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
Expand Down
1 change: 1 addition & 0 deletions clap_derive/src/derives/value_enum.rs
Expand Up @@ -59,6 +59,7 @@ pub fn gen_for_enum(name: &Ident, attrs: &[Attribute], e: &DataEnum) -> TokenStr
clippy::nursery,
clippy::cargo,
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
impl clap::ValueEnum for #name {
#value_variants
Expand Down

0 comments on commit b8ca734

Please sign in to comment.