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

almost_swapped false positive on #[derive(clap::Subcommand)] #10676

Closed
9999years opened this issue Apr 20, 2023 · 3 comments
Closed

almost_swapped false positive on #[derive(clap::Subcommand)] #10676

9999years opened this issue Apr 20, 2023 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@9999years
Copy link
Contributor

Summary

clap 4.0 raises what looks like a spurious almost_swapped lint.

Frustratingly, I don't appear to be able to silence the lint with #![allow(clippy::almost_swapped)].

Lint Name

almost_swapped

Reproducer

I tried this code:

#[derive(Debug, Clone, clap::Subcommand)]
pub enum Command {
    /// Uninstall Nix and exit when finished.
    UninstallNix,
}

I saw this happen:

$ cargo clippy
error: this looks like you are trying to swap `__clap_subcommand` and `clap::Subcommand`
   --> src/cli.rs:117:24
    |
117 | #[derive(Debug, Clone, 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/cli.rs:117:24
    |
117 | #[derive(Debug, Clone, 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)

I expected to see this happen:

$ cargo clippy
All good :)

Version

rustc 1.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: aarch64-apple-darwin
release: 1.69.0
LLVM version: 15.0.7

Additional Labels

No response

@9999years 9999years added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 20, 2023
@9999years
Copy link
Contributor Author

This is a duplicate of #10421, but even though that issue is closed this occurs with today's stable release.

@9999years
Copy link
Contributor Author

Updating from clap v4.0.18 -> v4.2.4 fixed the issue for me. Still seems weird but closing.

@shinypb
Copy link

shinypb commented Apr 21, 2023

@9999years I'm seeing this too! We're intentionally all the way back on clap 3.2.23 for various reasons; would you be open to re-opening this issue even though there's a workaround? 🙏 Ah, I see that it's been fixed in nightly builds, so I guess I'll just wait. (Thanks anyhow!)

dillonrg pushed a commit to dillonrg/akd that referenced this issue Apr 21, 2023
- As of now, the Clippy step appears broken due to issues with Clap
and Clippy. For more information, please see: rust-lang/rust-clippy#10676.
- To mitigate, we're enabling CI to continue even if the Clippy step
fails. Please note that the Clap issue appears fixed on nightly, so
we can remove continue-on-error once things are resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants