diff --git a/src/main.rs b/src/main.rs index 30beaae34d2f..d4ff00a83c48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ #![cfg_attr(feature = "deny-warnings", deny(warnings))] +#![feature(let_chains)] // warn on lints, that are included in `rust-lang/rust`s bootstrap #![warn(rust_2018_idioms, unused_lifetimes)] @@ -43,7 +44,23 @@ pub fn main() { return; } - if let Err(code) = process(env::args().skip(2)) { + // if we run "cargo clippy" (as cargo subcommand), we have to strip "cargo clippy" (first 2 args) + // but if we are run via "..../target/debug/cargo-clippy", only ommit the first arg, the second one + // might be a normal cmdline arg already (which we don't want to ommit) + let args = if let Some(first_arg) = env::args().next() + && (first_arg.ends_with("cargo-clippy") || first_arg.ends_with("cargo-clippy.exe")) + { + // turn this of during the migration + // env::args().skip(1) + eprintln!( + "WARNING: potentially breaking change: 'cargo-clippy arg1 arg2...' will no longer ignore 'arg1' after edition=2024" + ); + env::args().skip(2) + } else { + env::args().skip(2) + }; + + if let Err(code) = process(args) { process::exit(code); } } @@ -216,4 +233,14 @@ mod tests { let cmd = ClippyCmd::new(args); assert_eq!("check", cmd.cargo_subcommand); } + + #[test] + fn dont_skip_arg() { + let args = "target/debug/cargo-clippy --fix" + .split_whitespace() + .map(ToString::to_string); + let cmd = ClippyCmd::new(args); + assert_eq!("fix", cmd.cargo_subcommand); + assert!(!cmd.args.iter().any(|arg| arg.ends_with("unstable-options"))); + } } diff --git a/tests/dogfood.rs b/tests/dogfood.rs index 3f16c180ea78..c1c79db6f093 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -98,7 +98,6 @@ fn run_clippy_for_package(project: &str, args: &[&str]) -> bool { command .current_dir(root_dir.join(project)) .env("CARGO_INCREMENTAL", "0") - .arg("clippy") .arg("--all-targets") .arg("--all-features"); diff --git a/tests/workspace.rs b/tests/workspace.rs index 699ab2be199a..b20c2e06ba9b 100644 --- a/tests/workspace.rs +++ b/tests/workspace.rs @@ -71,7 +71,6 @@ fn test_no_deps_ignores_path_deps_in_workspaces() { .current_dir(&cwd) .env("CARGO_INCREMENTAL", "0") .env("CARGO_TARGET_DIR", &target_dir) - .arg("clippy") .args(["-p", "subcrate"]) .arg("--no-deps") .arg("--") @@ -91,7 +90,6 @@ fn test_no_deps_ignores_path_deps_in_workspaces() { .current_dir(&cwd) .env("CARGO_INCREMENTAL", "0") .env("CARGO_TARGET_DIR", &target_dir) - .arg("clippy") .args(["-p", "subcrate"]) .arg("--") .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir @@ -118,7 +116,6 @@ fn test_no_deps_ignores_path_deps_in_workspaces() { .current_dir(&cwd) .env("CARGO_INCREMENTAL", "0") .env("CARGO_TARGET_DIR", &target_dir) - .arg("clippy") .args(["-p", "subcrate"]) .arg("--") .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir