From 17fbb56e9ad00bd6ce8ccfe507829c3811983335 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 25 Jun 2021 21:41:56 -0400 Subject: [PATCH] Stabilize `cargo clippy --fix` This has been unstable since it was first introduced in https://github.com/rust-lang/rust-clippy/pull/5363. In that time, I have been using it successfully in nightly without issues. I don't think there are any blocking issues now that RUSTC_WORKSPACE_WRAPPER is stabilized, so this can be stabilized. --- .github/workflows/clippy.yml | 2 +- .github/workflows/clippy_bors.yml | 2 +- README.md | 5 ++--- lintcheck/README.md | 2 +- lintcheck/src/main.rs | 9 +-------- src/main.rs | 26 ++++---------------------- 6 files changed, 10 insertions(+), 36 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 32103f59d8b0..d856c55a41a4 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -71,7 +71,7 @@ jobs: working-directory: clippy_workspace_tests - name: Test cargo-clippy --fix - run: ../target/debug/cargo-clippy clippy --fix -Zunstable-options + run: ../target/debug/cargo-clippy clippy --fix working-directory: clippy_workspace_tests - name: Test clippy-driver diff --git a/.github/workflows/clippy_bors.yml b/.github/workflows/clippy_bors.yml index ae6f1aa1b30b..146b6fccd0c7 100644 --- a/.github/workflows/clippy_bors.yml +++ b/.github/workflows/clippy_bors.yml @@ -134,7 +134,7 @@ jobs: working-directory: clippy_workspace_tests - name: Test cargo-clippy --fix - run: ../target/debug/cargo-clippy clippy --fix -Zunstable-options + run: ../target/debug/cargo-clippy clippy --fix working-directory: clippy_workspace_tests - name: Test clippy-driver diff --git a/README.md b/README.md index 6c556f579ca4..53056081325e 100644 --- a/README.md +++ b/README.md @@ -75,11 +75,10 @@ cargo clippy #### Automatically applying Clippy suggestions -Clippy can automatically apply some lint suggestions. -Note that this is still experimental and only supported on the nightly channel: +Clippy can automatically apply some lint suggestions, just like the compiler. ```terminal -cargo clippy --fix -Z unstable-options +cargo clippy --fix ``` #### Workspaces diff --git a/lintcheck/README.md b/lintcheck/README.md index 52bbcc0a8317..07c3ec045067 100644 --- a/lintcheck/README.md +++ b/lintcheck/README.md @@ -69,7 +69,7 @@ is checked. is explicitly specified in the options. ### Fix mode -You can run `./lintcheck/target/debug/lintcheck --fix` which will run Clippy with `-Zunstable-options --fix` and +You can run `./lintcheck/target/debug/lintcheck --fix` which will run Clippy with `--fix` and print a warning if Clippys suggestions fail to apply (if the resulting code does not build). This lets us spot bad suggestions or false positives automatically in some cases. diff --git a/lintcheck/src/main.rs b/lintcheck/src/main.rs index f6a75595c986..7d2f3173fb0e 100644 --- a/lintcheck/src/main.rs +++ b/lintcheck/src/main.rs @@ -260,14 +260,7 @@ impl Crate { let shared_target_dir = clippy_project_root().join("target/lintcheck/shared_target_dir"); let mut args = if fix { - vec![ - "-Zunstable-options", - "--fix", - "-Zunstable-options", - "--allow-no-vcs", - "--", - "--cap-lints=warn", - ] + vec!["--fix", "--allow-no-vcs", "--", "--cap-lints=warn"] } else { vec!["--", "--message-format=json", "--", "--cap-lints=warn"] }; diff --git a/src/main.rs b/src/main.rs index 7bb80b1196e5..73d288a198c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,7 +70,6 @@ impl ClippyCmd { I: Iterator, { let mut cargo_subcommand = "check"; - let mut unstable_options = false; let mut args = vec![]; for arg in old_args.by_ref() { @@ -80,18 +79,12 @@ impl ClippyCmd { continue; }, "--" => break, - // Cover -Zunstable-options and -Z unstable-options - s if s.ends_with("unstable-options") => unstable_options = true, _ => {}, } args.push(arg); } - if cargo_subcommand == "fix" && !unstable_options { - panic!("Usage of `--fix` requires `-Z unstable-options`"); - } - let mut clippy_args: Vec = old_args.collect(); if cargo_subcommand == "fix" && !clippy_args.iter().any(|arg| arg == "--no-deps") { clippy_args.push("--no-deps".into()); @@ -175,35 +168,24 @@ where mod tests { use super::ClippyCmd; - #[test] - #[should_panic] - fn fix_without_unstable() { - let args = "cargo clippy --fix".split_whitespace().map(ToString::to_string); - ClippyCmd::new(args); - } - #[test] fn fix_unstable() { - let args = "cargo clippy --fix -Zunstable-options" - .split_whitespace() - .map(ToString::to_string); + let args = "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"))); + assert!(!cmd.args.iter().any(|arg| arg.ends_with("unstable-options"))); } #[test] fn fix_implies_no_deps() { - let args = "cargo clippy --fix -Zunstable-options" - .split_whitespace() - .map(ToString::to_string); + let args = "cargo clippy --fix".split_whitespace().map(ToString::to_string); let cmd = ClippyCmd::new(args); assert!(cmd.clippy_args.iter().any(|arg| arg == "--no-deps")); } #[test] fn no_deps_not_duplicated_with_fix() { - let args = "cargo clippy --fix -Zunstable-options -- --no-deps" + let args = "cargo clippy --fix -- --no-deps" .split_whitespace() .map(ToString::to_string); let cmd = ClippyCmd::new(args);