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 swap triggering on clap subcommand and Parser #4849

Closed
2 tasks done
kristian1108 opened this issue Apr 20, 2023 · 1 comment
Closed
2 tasks done

Clippy almost swap triggering on clap subcommand and Parser #4849

kristian1108 opened this issue Apr 20, 2023 · 1 comment
Labels
C-bug Category: Updating dependencies

Comments

@kristian1108
Copy link

Please complete the following tasks

Rust Version

rustc 1.69.0 (84c898d65 2023-04-16)

Clap Version

Multiple versions in my Cargo.lock: 2.34.0, 3.2.23, 4.2.1

Minimal reproducible code

use clap::Parser;

#[derive(Debug, Parser)]
#[clap(name = "test")]
#[clap(bin_name = "test")]
pub enum Test {
    TestSubcommandOne(TestOne),
    TestSubcommandTwo(TestTwo),
    TestThree
}

#[derive(clap::Args, Debug)]
#[clap(author, version, about, long_about = None)]
pub struct TestOne {
    #[clap(short, long, value_parser)]
    pub test_one: String,
    #[clap(short, long, value_parser)]
    pub test_two: String
}

#[derive(clap::Args, Debug)]
#[clap(author, version, about, long_about = None)]
pub struct TestTwo {
    #[clap(short, long, value_parser)]
    pub test_one: String,
    #[clap(short, long, value_parser)]
    pub test_two: String
}

fn main() {
    let args = Test::parse();
}

Steps to reproduce the bug with the above code

cargo clippy

Actual Behaviour

error: this looks like you are trying to swap __clap_subcommand and Parser
--> src/test/test.rs:57:17
|
57 | #[derive(Debug, Parser)]
| ^^^^^^
|
= 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

Expected Behaviour

Should not fail.

Additional Context

Looks like it's related to this closed issue: #4733

Debug Output

No response

@kristian1108 kristian1108 added the C-bug Category: Updating dependencies label Apr 20, 2023
@kristian1108
Copy link
Author

Sorry, this is fixed in the +nightly toolchain.

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
Development

No branches or pull requests

1 participant