Skip to content

Commit d793bd2

Browse files
authored
Rollup merge of #92849 - flip1995:clippyup, r=Manishearth
Clippyup r? ``@Manishearth``
2 parents a9966f5 + b83c77c commit d793bd2

File tree

224 files changed

+3262
-1685
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+3262
-1685
lines changed

Cargo.lock

+6-3
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,15 @@ dependencies = [
613613

614614
[[package]]
615615
name = "clippy"
616-
version = "0.1.59"
616+
version = "0.1.60"
617617
dependencies = [
618618
"cargo_metadata 0.14.0",
619619
"clippy_lints",
620620
"clippy_utils",
621621
"compiletest_rs",
622622
"derive-new",
623623
"filetime",
624+
"futures 0.3.12",
624625
"if_chain",
625626
"itertools 0.10.1",
626627
"parking_lot",
@@ -633,6 +634,7 @@ dependencies = [
633634
"syn",
634635
"tempfile",
635636
"tester",
637+
"tokio",
636638
]
637639

638640
[[package]]
@@ -652,7 +654,7 @@ dependencies = [
652654

653655
[[package]]
654656
name = "clippy_lints"
655-
version = "0.1.59"
657+
version = "0.1.60"
656658
dependencies = [
657659
"cargo_metadata 0.14.0",
658660
"clippy_utils",
@@ -673,8 +675,9 @@ dependencies = [
673675

674676
[[package]]
675677
name = "clippy_utils"
676-
version = "0.1.59"
678+
version = "0.1.60"
677679
dependencies = [
680+
"arrayvec",
678681
"if_chain",
679682
"rustc-semver",
680683
]

src/tools/clippy/.cargo/config.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
uitest = "test --test compile-test"
33
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
44
lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- "
5-
collect-metadata = "test --test dogfood --features metadata-collector-lint -- run_metadata_collection_lint --ignored"
5+
collect-metadata = "test --test dogfood --features internal -- run_metadata_collection_lint --ignored"
66

77
[build]
88
# -Zbinary-dep-depinfo allows us to track which rlib files to use for compiling UI tests
99
rustflags = ["-Zunstable-options", "-Zbinary-dep-depinfo"]
1010
target-dir = "target"
11+
12+
[unstable]
13+
binary-dep-depinfo = true

src/tools/clippy/.github/workflows/clippy.yml

+4-12
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ jobs:
4949
echo "LD_LIBRARY_PATH=${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" >> $GITHUB_ENV
5050
5151
- name: Build
52-
run: cargo build --features deny-warnings,internal-lints,metadata-collector-lint
52+
run: cargo build --features deny-warnings,internal
5353

5454
- name: Test
55-
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
55+
run: cargo test --features deny-warnings,internal
5656

5757
- name: Test clippy_lints
58-
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
58+
run: cargo test --features deny-warnings,internal
5959
working-directory: clippy_lints
6060

6161
- name: Test clippy_utils
62-
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
62+
run: cargo test --features deny-warnings,internal
6363
working-directory: clippy_utils
6464

6565
- name: Test rustc_tools_util
@@ -70,14 +70,6 @@ jobs:
7070
run: cargo test --features deny-warnings
7171
working-directory: clippy_dev
7272

73-
- name: Test cargo-clippy
74-
run: ../target/debug/cargo-clippy
75-
working-directory: clippy_workspace_tests
76-
77-
- name: Test cargo-clippy --fix
78-
run: ../target/debug/cargo-clippy clippy --fix
79-
working-directory: clippy_workspace_tests
80-
8173
- name: Test clippy-driver
8274
run: bash .github/driver.sh
8375
env:

src/tools/clippy/.github/workflows/clippy_bors.yml

+9-12
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,22 @@ jobs:
112112
echo "$SYSROOT/bin" >> $GITHUB_PATH
113113
114114
- name: Build
115-
run: cargo build --features deny-warnings,internal-lints,metadata-collector-lint
115+
run: cargo build --features deny-warnings,internal
116116

117117
- name: Test
118-
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
118+
if: runner.os == 'Linux'
119+
run: cargo test --features deny-warnings,internal
120+
121+
- name: Test
122+
if: runner.os != 'Linux'
123+
run: cargo test --features deny-warnings,internal -- --skip dogfood
119124

120125
- name: Test clippy_lints
121-
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
126+
run: cargo test --features deny-warnings,internal
122127
working-directory: clippy_lints
123128

124129
- name: Test clippy_utils
125-
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
130+
run: cargo test --features deny-warnings,internal
126131
working-directory: clippy_utils
127132

128133
- name: Test rustc_tools_util
@@ -133,14 +138,6 @@ jobs:
133138
run: cargo test --features deny-warnings
134139
working-directory: clippy_dev
135140

136-
- name: Test cargo-clippy
137-
run: ../target/debug/cargo-clippy
138-
working-directory: clippy_workspace_tests
139-
140-
- name: Test cargo-clippy --fix
141-
run: ../target/debug/cargo-clippy clippy --fix
142-
working-directory: clippy_workspace_tests
143-
144141
- name: Test clippy-driver
145142
run: bash .github/driver.sh
146143
env:

src/tools/clippy/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ out
1919
/target
2020
/clippy_lints/target
2121
/clippy_utils/target
22-
/clippy_workspace_tests/target
2322
/clippy_dev/target
2423
/lintcheck/target
2524
/rustc_tools_util/target

src/tools/clippy/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2887,6 +2887,7 @@ Released 2018-09-13
28872887
[`blocks_in_if_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions
28882888
[`bool_assert_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_assert_comparison
28892889
[`bool_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
2890+
[`borrow_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr
28902891
[`borrow_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const
28912892
[`borrowed_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box
28922893
[`box_collection`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_collection
@@ -3070,6 +3071,7 @@ Released 2018-09-13
30703071
[`main_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#main_recursion
30713072
[`manual_assert`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert
30723073
[`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn
3074+
[`manual_bits`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits
30733075
[`manual_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter_map
30743076
[`manual_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find_map
30753077
[`manual_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_flatten
@@ -3253,6 +3255,7 @@ Released 2018-09-13
32533255
[`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait
32543256
[`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names
32553257
[`single_char_add_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_add_str
3258+
[`single_char_lifetime_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_lifetime_names
32563259
[`single_char_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
32573260
[`single_component_path_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
32583261
[`single_element_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_element_loop

src/tools/clippy/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.59"
3+
version = "0.1.60"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"
@@ -47,16 +47,17 @@ itertools = "0.10"
4747
quote = "1.0"
4848
serde = { version = "1.0", features = ["derive"] }
4949
syn = { version = "1.0", features = ["full"] }
50+
futures = "0.3"
5051
parking_lot = "0.11.2"
52+
tokio = { version = "1", features = ["io-util"] }
5153

5254
[build-dependencies]
5355
rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }
5456

5557
[features]
5658
deny-warnings = ["clippy_lints/deny-warnings"]
5759
integration = ["tempfile"]
58-
internal-lints = ["clippy_lints/internal-lints"]
59-
metadata-collector-lint = ["internal-lints", "clippy_lints/metadata-collector-lint"]
60+
internal = ["clippy_lints/internal"]
6061

6162
[package.metadata.rust-analyzer]
6263
# This package uses #[feature(rustc_private)]

src/tools/clippy/README.md

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
77

8-
[There are over 450 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
8+
[There are over 500 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
99

1010
Lints are divided into categories, each with a default [lint level](https://doc.rust-lang.org/rustc/lints/levels.html).
1111
You can choose how much Clippy is supposed to ~~annoy~~ help you by changing the lint level by category.
@@ -37,8 +37,8 @@ Table of contents:
3737

3838
## Usage
3939

40-
Below are instructions on how to use Clippy as a subcommand, compiled from source
41-
or in Travis CI.
40+
Below are instructions on how to use Clippy as a cargo subcommand,
41+
in projects that do not use cargo, or in Travis CI.
4242

4343
### As a cargo subcommand (`cargo clippy`)
4444

@@ -98,22 +98,18 @@ If you want to run Clippy **only** on the given crate, use the `--no-deps` optio
9898
cargo clippy -p example -- --no-deps
9999
```
100100

101-
### As a rustc replacement (`clippy-driver`)
101+
### Using `clippy-driver`
102102

103-
Clippy can also be used in projects that do not use cargo. To do so, you will need to replace
104-
your `rustc` compilation commands with `clippy-driver`. For example, if your project runs:
105-
106-
```terminal
107-
rustc --edition 2018 -Cpanic=abort foo.rs
108-
```
109-
110-
Then, to enable Clippy, you will need to call:
103+
Clippy can also be used in projects that do not use cargo. To do so, run `clippy-driver`
104+
with the same arguments you use for `rustc`. For example:
111105

112106
```terminal
113107
clippy-driver --edition 2018 -Cpanic=abort foo.rs
114108
```
115109

116-
Note that `rustc` will still run, i.e. it will still emit the output files it normally does.
110+
Note that `clippy-driver` is designed for running Clippy only and should not be used as a general
111+
replacement for `rustc`. `clippy-driver` may produce artifacts that are not optimized as expected,
112+
for example.
117113

118114
### Travis CI
119115

src/tools/clippy/clippy_dev/src/fmt.rs

+26-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use itertools::Itertools;
33
use shell_escape::escape;
44
use std::ffi::{OsStr, OsString};
55
use std::path::Path;
6-
use std::process::{self, Command};
6+
use std::process::{self, Command, Stdio};
77
use std::{fs, io};
88
use walkdir::WalkDir;
99

@@ -31,6 +31,7 @@ impl From<walkdir::Error> for CliError {
3131
struct FmtContext {
3232
check: bool,
3333
verbose: bool,
34+
rustfmt_path: String,
3435
}
3536

3637
// the "main" function of cargo dev fmt
@@ -102,7 +103,23 @@ Please revert the changes to Cargo.tomls first."
102103
}
103104
}
104105

105-
let context = FmtContext { check, verbose };
106+
let output = Command::new("rustup")
107+
.args(["which", "rustfmt"])
108+
.stderr(Stdio::inherit())
109+
.output()
110+
.expect("error running `rustup which rustfmt`");
111+
if !output.status.success() {
112+
eprintln!("`rustup which rustfmt` did not execute successfully");
113+
process::exit(1);
114+
}
115+
let mut rustfmt_path = String::from_utf8(output.stdout).expect("invalid rustfmt path");
116+
rustfmt_path.truncate(rustfmt_path.trim_end().len());
117+
118+
let context = FmtContext {
119+
check,
120+
verbose,
121+
rustfmt_path,
122+
};
106123
let result = try_run(&context);
107124
let code = match result {
108125
Ok(true) => 0,
@@ -141,8 +158,12 @@ fn exec(
141158
println!("{}", format_command(&program, &dir, args));
142159
}
143160

144-
let child = Command::new(&program).current_dir(&dir).args(args.iter()).spawn()?;
145-
let output = child.wait_with_output()?;
161+
let output = Command::new(&program)
162+
.env("RUSTFMT", &context.rustfmt_path)
163+
.current_dir(&dir)
164+
.args(args.iter())
165+
.output()
166+
.unwrap();
146167
let success = output.status.success();
147168

148169
if !context.check && !success {
@@ -159,7 +180,6 @@ fn exec(
159180
fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
160181
let mut args = vec!["fmt", "--all"];
161182
if context.check {
162-
args.push("--");
163183
args.push("--check");
164184
}
165185
let success = exec(context, "cargo", path, &args)?;
@@ -200,7 +220,7 @@ fn rustfmt(context: &FmtContext, paths: impl Iterator<Item = OsString>) -> Resul
200220
}
201221
args.extend(paths);
202222

203-
let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?;
223+
let success = exec(context, &context.rustfmt_path, std::env::current_dir()?, &args)?;
204224

205225
Ok(success)
206226
}

src/tools/clippy/clippy_dev/src/update_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn gen_register_lint_list<'a>(
321321

322322
for (is_public, module_name, lint_name) in details {
323323
if !is_public {
324-
output.push_str(" #[cfg(feature = \"internal-lints\")]\n");
324+
output.push_str(" #[cfg(feature = \"internal\")]\n");
325325
}
326326
output.push_str(&format!(" {}::{},\n", module_name, lint_name));
327327
}

src/tools/clippy/clippy_lints/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.59"
3+
version = "0.1.60"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"
@@ -30,8 +30,7 @@ url = { version = "2.2", features = ["serde"] }
3030
[features]
3131
deny-warnings = ["clippy_utils/deny-warnings"]
3232
# build clippy with internal lints enabled, off by default
33-
internal-lints = ["clippy_utils/internal-lints"]
34-
metadata-collector-lint = ["serde_json", "clippy_utils/metadata-collector-lint"]
33+
internal = ["clippy_utils/internal", "serde_json"]
3534

3635
[package.metadata.rust-analyzer]
3736
# This crate uses #[feature(rustc_private)]

0 commit comments

Comments
 (0)