Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy::almost_swapped check failing on latest nightly #4733

Closed
2 tasks done
rkrasiuk opened this issue Feb 27, 2023 · 6 comments · Fixed by #4735 or #4739
Closed
2 tasks done

clippy::almost_swapped check failing on latest nightly #4733

rkrasiuk opened this issue Feb 27, 2023 · 6 comments · Fixed by #4735 or #4739
Labels
C-bug Category: Updating dependencies

Comments

@rkrasiuk
Copy link
Contributor

rkrasiuk commented Feb 27, 2023

Please complete the following tasks

Rust Version

rustc 1.69.0-nightly (d962ea578 2023-02-26)

Clap Version

4.1.4

Minimal reproducible code

use clap::Parser;

#[derive(Parser, Debug)]
struct SomeArgs {
    name: Vec<String>,
}

Steps to reproduce the bug with the above code

cargo clippy

Actual Behaviour

$ 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

$ cargo expand
#![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

@rkrasiuk rkrasiuk added the C-bug Category: Updating dependencies label Feb 27, 2023
@rkrasiuk rkrasiuk changed the title clippy::correctness check failing on latest nightly clippy::almost_swapped check failing on latest nightly Feb 27, 2023
@Ltrlg
Copy link

Ltrlg commented Feb 27, 2023

There is a similar error with subcommands:

#[derive(clap::Subcommand)]
enum Command {
    X
}

results in:

error: this looks like you are trying to swap `__clap_subcommand` and `clap::Subcommand`
 --> src/lib.rs:3:10
  |
3 | #[derive(clap::Subcommand)]
  |          ^^^^^^^^^^^^^^^^
  |
  = 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/lib.rs:3:10
  |
3 | #[derive(clap::Subcommand)]
  |          ^^^^^^^^^^^^^^^^
  = note: `#[deny(clippy::almost_swapped)]` implied by `#[deny(clippy::correctness)]`
  = note: this error originates in the derive macro `clap::Subcommand` (in Nightly builds, run with -Z macro-backtrace for more info)

The relevant part of the expansion seems to be:

impl clap::Subcommand for Command {
    fn augment_subcommands<'b>(__clap_app: clap::Command) -> clap::Command {
        ;
        let __clap_app = __clap_app;
        let __clap_app =
            __clap_app.subcommand({
                    let __clap_subcommand = clap::Command::new("x");
                    let __clap_subcommand = __clap_subcommand;
                    let __clap_subcommand = __clap_subcommand;
                    __clap_subcommand
                });
        ;
        __clap_app
    }
    fn augment_subcommands_for_update<'b>(__clap_app: clap::Command)
        -> clap::Command {
        ;
        let __clap_app = __clap_app;
        let __clap_app =
            __clap_app.subcommand({
                    let __clap_subcommand = clap::Command::new("x");
                    let __clap_subcommand = __clap_subcommand;
                    let __clap_subcommand = __clap_subcommand;
                    __clap_subcommand
                });
        ;
        __clap_app
    }
    fn has_subcommand(__clap_name: &str) -> bool {
        if "x" == __clap_name { return true }
        false
    }
}

@rkrasiuk
Copy link
Contributor Author

@Ltrlg ty, this should be fixed in c1caf46 as well

didier-wenzek added a commit to didier-wenzek/thin-edge.io that referenced this issue Feb 27, 2023
Due to clap-rs/clap#4733
one has to revert back to clippy 1.64

Signed-off-by: Didier Wenzek <[email protected]>
@rkrasiuk
Copy link
Contributor Author

@epage seems like we need to reopen this, because #[deny(clippy::correctness)] takes precedence over #[allow(clippy::almost_swapped)]

ralexstokes added a commit to ralexstokes/mev-rs that referenced this issue Feb 28, 2023
ralexstokes added a commit to ralexstokes/mev-rs that referenced this issue Feb 28, 2023
azriel91 added a commit to azriel91/peace that referenced this issue Feb 28, 2023
ralexstokes added a commit to ralexstokes/mev-rs that referenced this issue Feb 28, 2023
ralexstokes added a commit to ralexstokes/mev-rs that referenced this issue Feb 28, 2023
ralexstokes added a commit to ralexstokes/mev-rs that referenced this issue Feb 28, 2023
ralexstokes added a commit to ralexstokes/mev-rs that referenced this issue Feb 28, 2023
@MingweiSamuel
Copy link
Contributor

MingweiSamuel commented Feb 28, 2023

Made a clippy issue: rust-lang/rust-clippy#10421

Not clear to me that this should trigger clippy at all. At the very least the error message is wrong

@MingweiSamuel
Copy link
Contributor

Seems unnecessary to have #[deny(clippy::correctness)] in the first place (added in bfc850e )

Macros aren't really where you want clippy to be at its strictest. And really shouldn't be having clippy to catch bugs in macro code from user usage..

MingweiSamuel added a commit to MingweiSamuel/clap that referenced this issue Feb 28, 2023
MingweiSamuel added a commit to MingweiSamuel/clap that referenced this issue Feb 28, 2023
JonasWanke added a commit to candy-lang/candy that referenced this issue Feb 28, 2023
anfredette pushed a commit to anfredette/bpfman that referenced this issue Feb 28, 2023
Needed until clap-rs/clap#4733 is fixed.

Signed-off-by: Andre Fredette <[email protected]>
svix-gabriel added a commit to svix/svix-webhooks that referenced this issue Mar 8, 2023
## Motivation

This bumps `clap` to the latest stable version. This probably good for
it's own reasons, but the real motivation is fix the new clippy lints
that dropped. clap-rs/clap#4733


## Solution

1. Bump `clap` version.
2. Profit!!!
@blyxyas
Copy link

blyxyas commented Mar 13, 2023

I've made a PR to Clippy, in a few days it should be fixed in Clippy itself (even without changing Clap's version).

Porges added a commit to microsoft/onefuzz that referenced this issue Apr 20, 2023
Porges added a commit to microsoft/onefuzz that referenced this issue Apr 21, 2023
Porges added a commit to microsoft/onefuzz that referenced this issue Apr 21, 2023
* Bump Rust version to 1.69

* Bump clap to fix clippy lints

See: clap-rs/clap#4733
kpreid added a commit to kpreid/all-is-cubes that referenced this issue Apr 21, 2023
This avoids a lint failure <clap-rs/clap#4733>.
xsv24 added a commit to xsv24/git-kit that referenced this issue Apr 23, 2023
xsv24 added a commit to xsv24/git-kit that referenced this issue Apr 23, 2023
* 🐛 Fix up commit template path bug

* 🧹 remove unused import

* 🏭 Update shared action ref

* 📋 Attempt to fix ci clippy

* 🏭 skip clippy warning for now.

clap-rs/clap#4733 (comment)

* 📋 Try skip correctness as well

* 🏭 Just skip clippy for now.

* 🏭 Skip clippy for now

* 📖 Add deprecated note.
flihp added a commit to flihp/dice-util that referenced this issue Apr 26, 2023
This fixes a known issue introduced in rust 1.69 clippy that required
additional changes to clap. See:
rust-lang/rust-clippy#10421
clap-rs/clap#4733
flihp added a commit to oxidecomputer/dice-util that referenced this issue Apr 26, 2023
This fixes a known issue introduced in rust 1.69 clippy that required
additional changes to clap. See:
rust-lang/rust-clippy#10421
clap-rs/clap#4733
sebasnabas added a commit to sebasnabas/cocogitto that referenced this issue May 2, 2023
Details can be seen in clap-rs/clap#4733.
Using Subcommand with old clap versions causes clippy 1.69 to complain.
In this case it was:
```
error: this looks like you are trying to swap `arg` and `cmd`
   --> src/bin/cog/main.rs:292:23
```
oknozor pushed a commit to cocogitto/cocogitto that referenced this issue May 4, 2023
Details can be seen in clap-rs/clap#4733.
Using Subcommand with old clap versions causes clippy 1.69 to complain.
In this case it was:
```
error: this looks like you are trying to swap `arg` and `cmd`
   --> src/bin/cog/main.rs:292:23
```
FantasyTeddy added a commit to FantasyTeddy/macchina that referenced this issue May 30, 2023
This fixes clippy errors (see clap-rs/clap#4733)
grtcdr pushed a commit to Macchina-CLI/macchina that referenced this issue May 31, 2023
* Migrate from tui-rs to ratatui

* Update clap to version 4.1.14

This fixes clippy errors (see clap-rs/clap#4733)
ralexstokes added a commit to ralexstokes/mev-rs that referenced this issue Jul 9, 2023
SummerRolf added a commit to SummerRolf/mev-rs that referenced this issue May 7, 2024
SummerRolf added a commit to SummerRolf/mev-rs that referenced this issue May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies
Projects
None yet
4 participants