Skip to content

Commit b8ca734

Browse files
committed
fix(derive): Allow clippy::almost_swapped
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 #4735. This change backports that fix the the `v3-master` branch. Fixes: #4857
1 parent f617f13 commit b8ca734

4 files changed

Lines changed: 7 additions & 0 deletions

File tree

clap_derive/src/derives/args.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub fn gen_for_struct(
8484
clippy::nursery,
8585
clippy::cargo,
8686
clippy::suspicious_else_formatting,
87+
clippy::almost_swapped,
8788
)]
8889
impl #impl_generics clap::Args for #struct_name #ty_generics #where_clause {
8990
fn augment_args<'b>(#app_var: clap::Command<'b>) -> clap::Command<'b> {
@@ -128,6 +129,7 @@ pub fn gen_from_arg_matches_for_struct(
128129
clippy::nursery,
129130
clippy::cargo,
130131
clippy::suspicious_else_formatting,
132+
clippy::almost_swapped,
131133
)]
132134
impl #impl_generics clap::FromArgMatches for #struct_name #ty_generics #where_clause {
133135
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {

clap_derive/src/derives/into_app.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub fn gen_for_struct(
5454
clippy::nursery,
5555
clippy::cargo,
5656
clippy::suspicious_else_formatting,
57+
clippy::almost_swapped,
5758
)]
5859
#[allow(deprecated)]
5960
impl #impl_generics clap::CommandFactory for #struct_name #ty_generics #where_clause {
@@ -99,6 +100,7 @@ pub fn gen_for_enum(enum_name: &Ident, generics: &Generics, attrs: &[Attribute])
99100
clippy::nursery,
100101
clippy::cargo,
101102
clippy::suspicious_else_formatting,
103+
clippy::almost_swapped,
102104
)]
103105
impl #impl_generics clap::CommandFactory for #enum_name #ty_generics #where_clause {
104106
fn into_app<'b>() -> clap::Command<'b> {

clap_derive/src/derives/subcommand.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub fn gen_for_enum(
7272
clippy::nursery,
7373
clippy::cargo,
7474
clippy::suspicious_else_formatting,
75+
clippy::almost_swapped,
7576
)]
7677
impl #impl_generics clap::Subcommand for #enum_name #ty_generics #where_clause {
7778
fn augment_subcommands <'b>(__clap_app: clap::Command<'b>) -> clap::Command<'b> {
@@ -118,6 +119,7 @@ fn gen_from_arg_matches_for_enum(
118119
clippy::nursery,
119120
clippy::cargo,
120121
clippy::suspicious_else_formatting,
122+
clippy::almost_swapped,
121123
)]
122124
impl #impl_generics clap::FromArgMatches for #name #ty_generics #where_clause {
123125
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {

clap_derive/src/derives/value_enum.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub fn gen_for_enum(name: &Ident, attrs: &[Attribute], e: &DataEnum) -> TokenStr
5959
clippy::nursery,
6060
clippy::cargo,
6161
clippy::suspicious_else_formatting,
62+
clippy::almost_swapped,
6263
)]
6364
impl clap::ValueEnum for #name {
6465
#value_variants

0 commit comments

Comments
 (0)