Repository: clap-rs/clap (rust)

Issue:
`clippy::almost_swapped` check failing on latest nightly
### Please complete the following tasks

- [X] I have searched the [discussions](https://github.com/clap-rs/clap/discussions)
- [X] I have searched the [open](https://github.com/clap-rs/clap/issues) and [rejected](https://github.com/clap-rs/clap/issues?q=is%3Aissue+label%3AS-wont-fix+is%3Aclosed) issues

### Rust Version

rustc 1.69.0-nightly (d962ea578 2023-02-26)

### Clap Version

4.1.4

### Minimal reproducible code

```rust
use clap::Parser;

#[derive(Parser, Debug)]
struct SomeArgs {
    name: Vec<String>,
}
```


### Steps to reproduce the bug with the above code

`cargo clippy`

### Actual Behaviour

```sh
$ cargo clippy 
    Checking `<project>` v0.1.0 (`<path>`)
error: this looks like you are trying to swap `arg` and `name: Vec<String>`
 --> src/main.rs:5:5
  |
5 |     name: Vec<String>,
  |     ^^^^^^^^^^^^^^^^^ help: try: `std::mem::swap(&mut arg, &mut name: Vec<String>)`
  |
  = note: or maybe you should use `std::mem::replace`?
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped
note: the lint level is defined here
 --> src/main.rs:3:10
  |
3 | #[derive(Parser, Debug)]
  |          ^^^^^^
  = note: `#[deny(clippy::almost_swapped)]` implied by `#[deny(clippy::correctness)]`
  = note: this error originates in the derive macro `Parser` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `<project>` due to previous error
```

### Expected Behaviour

No clippy errors

### Additional Context

```sh
$ cargo expand
```

```rust
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
use clap::Parser;
struct SomeArgs {
    name: Vec<String>,
}
impl clap::Parser for SomeArgs {}
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
#[allow(
    clippy::style,
    clippy::complexity,
    clippy::pedantic,
    clippy::restriction,
    clippy::perf,
    clippy::deprecated,
    clippy::nursery,
    clippy::cargo,
    clippy::suspicious_else_formatting,
)]
#[deny(clippy::correctness)]
impl clap::CommandFactory for SomeArgs {
    fn command<'b>() -> clap::Command {
        let __clap_app = clap::Command::new("op-reth");
        <Self as clap::Args>::augment_args(__clap_app)
    }
    fn command_for_update<'b>() -> clap::Command {
        let __clap_app = clap::Command::new("op-reth");
        <Self as clap::Args>::augment_args_for_update(__clap_app)
    }
}
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
#[allow(
    clippy::style,
    clippy::complexity,
    clippy::pedantic,
    clippy::restriction,
    clippy::perf,
    clippy::deprecated,
    clippy::nursery,
    clippy::cargo,
    clippy::suspicious_else_formatting,
)]
#[deny(clippy::correctness)]
impl clap::FromArgMatches for SomeArgs {
    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())
    }
    fn from_arg_matches_mut(
        __clap_arg_matches: &mut clap::ArgMatches,
    ) -> ::std::result::Result<Self, clap::Error> {
        #![allow(deprecated)]
        let v = SomeArgs {
            name: __clap_arg_matches
                .remove_many::<String>("name")
                .map(|v| v.collect::<Vec<_>>())
                .unwrap_or_else(Vec::new),
        };
        ::std::result::Result::Ok(v)
    }
    fn update_from_arg_matches(
        &mut self,
        __clap_arg_matches: &clap::ArgMatches,
    ) -> ::std::result::Result<(), clap::Error> {
        self.update_from_arg_matches_mut(&mut __clap_arg_matches.clone())
    }
    fn update_from_arg_matches_mut(
        &mut self,
        __clap_arg_matches: &mut clap::ArgMatches,
    ) -> ::std::result::Result<(), clap::Error> {
        #![allow(deprecated)]
        if __clap_arg_matches.contains_id("name") {
            #[allow(non_snake_case)]
            let name = &mut self.name;
            *name = __clap_arg_matches
                .remove_many::<String>("name")
                .map(|v| v.collect::<Vec<_>>())
                .unwrap_or_else(Vec::new);
        }
        ::std::result::Result::Ok(())
    }
}
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
#[allow(
    clippy::style,
    clippy::complexity,
    clippy::pedantic,
    clippy::restriction,
    clippy::perf,
    clippy::deprecated,
    clippy::nursery,
    clippy::cargo,
    clippy::suspicious_else_formatting,
)]
#[deny(clippy::correctness)]
impl clap::Args for SomeArgs {
    fn group_id() -> Option<clap::Id> {
        Some(clap::Id::from("SomeArgs"))
    }
    fn augment_args<'b>(__clap_app: clap::Command) -> clap::Command {
        {
            let __clap_app = __clap_app
                .group(
                    clap::ArgGroup::new("SomeArgs")
                        .multiple(true)
                        .args({
                            let members: [clap::Id; 1usize] = [clap::Id::from("name")];
                            members
                        }),
                );
            let __clap_app = __clap_app
                .arg({
                    #[allow(deprecated)]
                    let arg = clap::Arg::new("name")
                        .value_name("NAME")
                        .num_args(1..)
                        .value_parser({
                            use ::clap::builder::via_prelude::*;
                            let auto = ::clap::builder::_AutoValueParser::<
                                String,
                            >::new();
                            (&&&&&&auto).value_parser()
                        })
                        .action(clap::ArgAction::Append);
                    let arg = arg;
                    let arg = arg;
                    arg
                });
            __clap_app
        }
    }
    fn augment_args_for_update<'b>(__clap_app: clap::Command) -> clap::Command {
        {
            let __clap_app = __clap_app
                .group(
                    clap::ArgGroup::new("SomeArgs")
                        .multiple(true)
                        .args({
                            let members: [clap::Id; 1usize] = [clap::Id::from("name")];
                            members
                        }),
                );
            let __clap_app = __clap_app
                .arg({
                    #[allow(deprecated)]
                    let arg = clap::Arg::new("name")
                        .value_name("NAME")
                        .num_args(1..)
                        .value_parser({
                            use ::clap::builder::via_prelude::*;
                            let auto = ::clap::builder::_AutoValueParser::<
                                String,
                            >::new();
                            (&&&&&&auto).value_parser()
                        })
                        .action(clap::ArgAction::Append);
                    let arg = arg;
                    let arg = arg.required(false);
                    arg
                });
            __clap_app
        }
    }
}
#[automatically_derived]
impl ::core::fmt::Debug for SomeArgs {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(
            f,
            "SomeArgs",
            "name",
            &&self.name,
        )
    }
}
```

### Debug Output

_No response_

Pull request:
fix(derive): Allow `clippy::almost_swapped`
<!--
Thanks for helping out!

Please link the appropriate issue from your PR.

If you don't have an issue, we'd recommend starting with one first so the PR can focus on the
implementation (unless its an obvious bug or documentation fix that will have
little conversation).
-->

Closes #4733 


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index d7af8269..84dad97c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -160,7 +160,7 @@ dependencies = [
 
 [[package]]
 name = "clap_complete"
-version = "4.1.4"
+version = "4.1.3"
 dependencies = [
  "clap 4.1.6",
  "clap_lex 0.3.2",
diff --git a/clap_complete/CHANGELOG.md b/clap_complete/CHANGELOG.md
index ad528d55..4e28f29e 100644
--- a/clap_complete/CHANGELOG.md
+++ b/clap_complete/CHANGELOG.md
@@ -7,12 +7,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 <!-- next-header -->
 ## [Unreleased] - ReleaseDate
 
-## [4.1.4] - 2023-02-27
-
-### Features
-
-- *(zsh)* Allow sourcing completion
-
 ## [4.1.3] - 2023-02-23
 
 ### Fixes
@@ -123,8 +117,7 @@ MSRV changed to 1.64.0
 ## [3.0.1] - 2022-01-03
 
 <!-- next-url -->
-[Unreleased]: https://github.com/clap-rs/clap/compare/clap_complete-v4.1.4...HEAD
-[4.1.4]: https://github.com/clap-rs/clap/compare/clap_complete-v4.1.3...clap_complete-v4.1.4
+[Unreleased]: https://github.com/clap-rs/clap/compare/clap_complete-v4.1.3...HEAD
 [4.1.3]: https://github.com/clap-rs/clap/compare/clap_complete-v4.1.2...clap_complete-v4.1.3
 [4.1.2]: https://github.com/clap-rs/clap/compare/clap_complete-v4.1.1...clap_complete-v4.1.2
 [4.1.1]: https://github.com/clap-rs/clap/compare/clap_complete-v4.1.0...clap_complete-v4.1.1
diff --git a/clap_complete/Cargo.toml b/clap_complete/Cargo.toml
index c0d18918..8382a722 100644
--- a/clap_complete/Cargo.toml
+++ b/clap_complete/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "clap_complete"
-version = "4.1.4"
+version = "4.1.3"
 description = "Generate shell completion scripts for your clap::Command"
 repository = "https://github.com/clap-rs/clap/tree/master/clap_complete"
 categories = ["command-line-interface"]
diff --git a/clap_complete/README.md b/clap_complete/README.md
index 9b85d357..bfb6f48a 100644
--- a/clap_complete/README.md
+++ b/clap_complete/README.md
@@ -5,16 +5,16 @@
 
 [![Crates.io](https://img.shields.io/crates/v/clap_complete?style=flat-square)](https://crates.io/crates/clap_complete)
 [![Crates.io](https://img.shields.io/crates/d/clap_complete?style=flat-square)](https://crates.io/crates/clap_complete)
-[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.1.4/LICENSE-APACHE)
-[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.1.4/LICENSE-MIT)
+[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.1.3/LICENSE-APACHE)
+[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.1.3/LICENSE-MIT)
 
 Dual-licensed under [Apache 2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT).
 
 1. [About](#about)
 2. [API Reference](https://docs.rs/clap_complete)
 3. [Questions & Discussions](https://github.com/clap-rs/clap/discussions)
-4. [CONTRIBUTING](https://github.com/clap-rs/clap/blob/clap_complete-v4.1.4/clap_complete/CONTRIBUTING.md)
-5. [Sponsors](https://github.com/clap-rs/clap/blob/clap_complete-v4.1.4/README.md#sponsors)
+4. [CONTRIBUTING](https://github.com/clap-rs/clap/blob/clap_complete-v4.1.3/clap_complete/CONTRIBUTING.md)
+5. [Sponsors](https://github.com/clap-rs/clap/blob/clap_complete-v4.1.3/README.md#sponsors)
 
 ## About
 
diff --git a/clap_complete/src/shells/zsh.rs b/clap_complete/src/shells/zsh.rs
index a41eb885..e9b8fdc6 100644
--- a/clap_complete/src/shells/zsh.rs
+++ b/clap_complete/src/shells/zsh.rs
@@ -43,11 +43,7 @@ _{name}() {{
 
 {subcommand_details}
 
-if [ \"$funcstack[1]\" = \"_{name}\" ]; then
-    _{name} \"$@\"
-else
-    compdef _{name} {name}
-fi
+_{name} \"$@\"
 ",
                 name = bin_name,
                 initial_args = get_args_of(cmd, None),
diff --git a/clap_derive/src/derives/args.rs b/clap_derive/src/derives/args.rs
index b5d51bfc..d019cd7a 100644
--- a/clap_derive/src/derives/args.rs
+++ b/clap_derive/src/derives/args.rs
@@ -109,6 +109,7 @@ pub fn gen_for_struct(
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
         #[deny(clippy::correctness)]
         impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
@@ -144,6 +145,7 @@ pub fn gen_for_struct(
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
         #[deny(clippy::correctness)]
         impl #impl_generics clap::Args for #item_name #ty_generics #where_clause {
diff --git a/clap_derive/src/derives/into_app.rs b/clap_derive/src/derives/into_app.rs
index a45667ab..4241ac0e 100644
--- a/clap_derive/src/derives/into_app.rs
+++ b/clap_derive/src/derives/into_app.rs
@@ -36,6 +36,7 @@ pub fn gen_for_struct(item: &Item, item_name: &Ident, generics: &Generics) -> To
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
         #[deny(clippy::correctness)]
         impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
@@ -72,6 +73,7 @@ pub fn gen_for_enum(item: &Item, item_name: &Ident, generics: &Generics) -> Toke
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
         #[deny(clippy::correctness)]
         impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
diff --git a/clap_derive/src/derives/subcommand.rs b/clap_derive/src/derives/subcommand.rs
index 8a44e0c4..e5bf16de 100644
--- a/clap_derive/src/derives/subcommand.rs
+++ b/clap_derive/src/derives/subcommand.rs
@@ -80,6 +80,7 @@ pub fn gen_for_enum(
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
         #[deny(clippy::correctness)]
         impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
@@ -106,6 +107,7 @@ pub fn gen_for_enum(
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
         #[deny(clippy::correctness)]
         impl #impl_generics clap::Subcommand for #item_name #ty_generics #where_clause {
diff --git a/clap_derive/src/derives/value_enum.rs b/clap_derive/src/derives/value_enum.rs
index a1411d02..1e2daf39 100644
--- a/clap_derive/src/derives/value_enum.rs
+++ b/clap_derive/src/derives/value_enum.rs
@@ -65,6 +65,7 @@ pub fn gen_for_enum(item: &Item, item_name: &Ident, variants: &[(&Variant, Item)
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
         #[deny(clippy::correctness)]
         impl clap::ValueEnum for #item_name {


Test patch:
diff --git a/clap_complete/tests/snapshots/aliases.zsh b/clap_complete/tests/snapshots/aliases.zsh
index 63764e56..403bbfe8 100644
--- a/clap_complete/tests/snapshots/aliases.zsh
+++ b/clap_complete/tests/snapshots/aliases.zsh
@@ -37,8 +37,4 @@ _my-app_commands() {
     _describe -t commands 'my-app commands' commands "$@"
 }
 
-if [ "$funcstack[1]" = "_my-app" ]; then
-    _my-app "$@"
-else
-    compdef _my-app my-app
-fi
+_my-app "$@"
diff --git a/clap_complete/tests/snapshots/basic.zsh b/clap_complete/tests/snapshots/basic.zsh
index 408bb7e4..217ed938 100644
--- a/clap_complete/tests/snapshots/basic.zsh
+++ b/clap_complete/tests/snapshots/basic.zsh
@@ -97,8 +97,4 @@ _my-app__test_commands() {
     _describe -t commands 'my-app test commands' commands "$@"
 }
 
-if [ "$funcstack[1]" = "_my-app" ]; then
-    _my-app "$@"
-else
-    compdef _my-app my-app
-fi
+_my-app "$@"
diff --git a/clap_complete/tests/snapshots/feature_sample.zsh b/clap_complete/tests/snapshots/feature_sample.zsh
index 72b85e11..3b4a7b64 100644
--- a/clap_complete/tests/snapshots/feature_sample.zsh
+++ b/clap_complete/tests/snapshots/feature_sample.zsh
@@ -104,8 +104,4 @@ _my-app__test_commands() {
     _describe -t commands 'my-app test commands' commands "$@"
 }
 
-if [ "$funcstack[1]" = "_my-app" ]; then
-    _my-app "$@"
-else
-    compdef _my-app my-app
-fi
+_my-app "$@"
diff --git a/clap_complete/tests/snapshots/quoting.zsh b/clap_complete/tests/snapshots/quoting.zsh
index 95ed7eb6..4afe4438 100644
--- a/clap_complete/tests/snapshots/quoting.zsh
+++ b/clap_complete/tests/snapshots/quoting.zsh
@@ -211,8 +211,4 @@ _my-app__help__help_commands() {
     _describe -t commands 'my-app help help commands' commands "$@"
 }
 
-if [ "$funcstack[1]" = "_my-app" ]; then
-    _my-app "$@"
-else
-    compdef _my-app my-app
-fi
+_my-app "$@"
diff --git a/clap_complete/tests/snapshots/special_commands.zsh b/clap_complete/tests/snapshots/special_commands.zsh
index 67d04bda..42023be7 100644
--- a/clap_complete/tests/snapshots/special_commands.zsh
+++ b/clap_complete/tests/snapshots/special_commands.zsh
@@ -178,8 +178,4 @@ _my-app__test_commands() {
     _describe -t commands 'my-app test commands' commands "$@"
 }
 
-if [ "$funcstack[1]" = "_my-app" ]; then
-    _my-app "$@"
-else
-    compdef _my-app my-app
-fi
+_my-app "$@"
diff --git a/clap_complete/tests/snapshots/sub_subcommands.zsh b/clap_complete/tests/snapshots/sub_subcommands.zsh
index 720e72f1..7a14feb5 100644
--- a/clap_complete/tests/snapshots/sub_subcommands.zsh
+++ b/clap_complete/tests/snapshots/sub_subcommands.zsh
@@ -224,8 +224,4 @@ _my-app__test_commands() {
     _describe -t commands 'my-app test commands' commands "$@"
 }
 
-if [ "$funcstack[1]" = "_my-app" ]; then
-    _my-app "$@"
-else
-    compdef _my-app my-app
-fi
+_my-app "$@"
diff --git a/clap_complete/tests/snapshots/two_multi_valued_arguments.zsh b/clap_complete/tests/snapshots/two_multi_valued_arguments.zsh
index a20088ea..e0d49622 100644
--- a/clap_complete/tests/snapshots/two_multi_valued_arguments.zsh
+++ b/clap_complete/tests/snapshots/two_multi_valued_arguments.zsh
@@ -27,8 +27,4 @@ _my-app_commands() {
     _describe -t commands 'my-app commands' commands "$@"
 }
 
-if [ "$funcstack[1]" = "_my-app" ]; then
-    _my-app "$@"
-else
-    compdef _my-app my-app
-fi
+_my-app "$@"
diff --git a/clap_complete/tests/snapshots/value_hint.zsh b/clap_complete/tests/snapshots/value_hint.zsh
index c3a97f75..15892dd7 100644
--- a/clap_complete/tests/snapshots/value_hint.zsh
+++ b/clap_complete/tests/snapshots/value_hint.zsh
@@ -47,8 +47,4 @@ _my-app_commands() {
     _describe -t commands 'my-app commands' commands "$@"
 }
 
-if [ "$funcstack[1]" = "_my-app" ]; then
-    _my-app "$@"
-else
-    compdef _my-app my-app
-fi
+_my-app "$@"
diff --git a/clap_complete/tests/snapshots/value_terminator.zsh b/clap_complete/tests/snapshots/value_terminator.zsh
index fe819420..656d8ea1 100644
--- a/clap_complete/tests/snapshots/value_terminator.zsh
+++ b/clap_complete/tests/snapshots/value_terminator.zsh
@@ -27,8 +27,4 @@ _my-app_commands() {
     _describe -t commands 'my-app commands' commands "$@"
 }
 
-if [ "$funcstack[1]" = "_my-app" ]; then
-    _my-app "$@"
-else
-    compdef _my-app my-app
-fi
+_my-app "$@"