Skip to content

Commit c9ce710

Browse files
authored
Rollup merge of #91154 - flip1995:clippyup, r=Manishearth
Update Clippy r? `@Manishearth` Delayed Clippy sync. I didn't get to it over the weekend..
2 parents 5c8ed8f + b95545b commit c9ce710

File tree

427 files changed

+6434
-2490
lines changed

Some content is hidden

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

427 files changed

+6434
-2490
lines changed

Cargo.lock

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ dependencies = [
584584
"filetime",
585585
"if_chain",
586586
"itertools 0.10.1",
587+
"parking_lot",
587588
"quote",
588589
"regex",
589590
"rustc-workspace-hack",
@@ -600,6 +601,7 @@ name = "clippy_dev"
600601
version = "0.0.1"
601602
dependencies = [
602603
"bytecount",
604+
"cargo_metadata 0.14.0",
603605
"clap",
604606
"indoc",
605607
"itertools 0.10.1",
@@ -1713,9 +1715,12 @@ dependencies = [
17131715

17141716
[[package]]
17151717
name = "instant"
1716-
version = "0.1.6"
1718+
version = "0.1.12"
17171719
source = "registry+https://github.com/rust-lang/crates.io-index"
1718-
checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485"
1720+
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
1721+
dependencies = [
1722+
"cfg-if 1.0.0",
1723+
]
17191724

17201725
[[package]]
17211726
name = "itertools"
@@ -1992,9 +1997,9 @@ version = "0.1.0"
19921997

19931998
[[package]]
19941999
name = "lock_api"
1995-
version = "0.4.1"
2000+
version = "0.4.5"
19962001
source = "registry+https://github.com/rust-lang/crates.io-index"
1997-
checksum = "28247cc5a5be2f05fbcd76dd0cf2c7d3b5400cb978a28042abcd4fa0b3f8261c"
2002+
checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109"
19982003
dependencies = [
19992004
"scopeguard",
20002005
]
@@ -2511,9 +2516,9 @@ dependencies = [
25112516

25122517
[[package]]
25132518
name = "parking_lot"
2514-
version = "0.11.1"
2519+
version = "0.11.2"
25152520
source = "registry+https://github.com/rust-lang/crates.io-index"
2516-
checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
2521+
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
25172522
dependencies = [
25182523
"instant",
25192524
"lock_api",
@@ -2522,9 +2527,9 @@ dependencies = [
25222527

25232528
[[package]]
25242529
name = "parking_lot_core"
2525-
version = "0.8.3"
2530+
version = "0.8.5"
25262531
source = "registry+https://github.com/rust-lang/crates.io-index"
2527-
checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018"
2532+
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
25282533
dependencies = [
25292534
"cfg-if 1.0.0",
25302535
"instant",

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@ jobs:
2525
- name: Checkout
2626
uses: actions/[email protected]
2727

28-
- name: remove toolchain file
29-
run: rm rust-toolchain
30-
31-
- name: rust-toolchain
32-
uses: actions-rs/[email protected]
33-
with:
34-
toolchain: nightly
35-
target: x86_64-unknown-linux-gnu
36-
profile: minimal
37-
components: rustfmt
38-
default: true
39-
4028
# Run
4129
- name: Build
4230
run: cargo build --features deny-warnings

src/tools/clippy/CHANGELOG.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Current beta, release 2021-12-02
7070
[#7560](https://github.com/rust-lang/rust-clippy/pull/7560)
7171
* [`unnecessary_unwrap`]: Now also checks for `expect`s
7272
[#7584](https://github.com/rust-lang/rust-clippy/pull/7584)
73-
* [`disallowed_method`]: Allow adding a reason that will be displayed with the
73+
* [`disallowed_methods`]: Allow adding a reason that will be displayed with the
7474
lint message
7575
[#7621](https://github.com/rust-lang/rust-clippy/pull/7621)
7676
* [`approx_constant`]: Now checks the MSRV for `LOG10_2` and `LOG2_10`
@@ -174,7 +174,7 @@ Current stable, released 2021-10-21
174174

175175
* [`needless_continue`]: Now also lints in `loop { continue; }` case
176176
[#7477](https://github.com/rust-lang/rust-clippy/pull/7477)
177-
* [`disallowed_type`]: Now also primitive types can be disallowed
177+
* [`disallowed_types`]: Now also primitive types can be disallowed
178178
[#7488](https://github.com/rust-lang/rust-clippy/pull/7488)
179179
* [`manual_swap`]: Now also lints on xor swaps
180180
[#7506](https://github.com/rust-lang/rust-clippy/pull/7506)
@@ -248,7 +248,7 @@ Released 2021-09-09
248248
[#7403](https://github.com/rust-lang/rust-clippy/pull/7403)
249249
* [`disallowed_script_idents`]
250250
[#7400](https://github.com/rust-lang/rust-clippy/pull/7400)
251-
* [`disallowed_type`]
251+
* [`disallowed_types`]
252252
[#7315](https://github.com/rust-lang/rust-clippy/pull/7315)
253253
* [`missing_enforced_import_renames`]
254254
[#7300](https://github.com/rust-lang/rust-clippy/pull/7300)
@@ -294,7 +294,7 @@ Released 2021-09-09
294294
[#7379](https://github.com/rust-lang/rust-clippy/pull/7379)
295295
* [`redundant_closure`]: Suggests `&mut` for `FnMut`
296296
[#7437](https://github.com/rust-lang/rust-clippy/pull/7437)
297-
* [`disallowed_method`], [`disallowed_type`]: The configuration values `disallowed-method` and `disallowed-type`
297+
* [`disallowed_methods`], [`disallowed_types`]: The configuration values `disallowed-method` and `disallowed-type`
298298
no longer require fully qualified paths
299299
[#7345](https://github.com/rust-lang/rust-clippy/pull/7345)
300300
* [`zst_offset`]: Fixed lint invocation after it was accidentally suppressed
@@ -703,7 +703,7 @@ Released 2021-05-06
703703

704704
### Enhancements
705705

706-
* [`disallowed_method`]: Now supports functions in addition to methods
706+
* [`disallowed_methods`]: Now supports functions in addition to methods
707707
[#6674](https://github.com/rust-lang/rust-clippy/pull/6674)
708708
* [`upper_case_acronyms`]: Added a new configuration `upper-case-acronyms-aggressive` to
709709
trigger the lint if there is more than one uppercase character next to each other
@@ -1044,7 +1044,7 @@ Released 2020-12-31
10441044

10451045
* [`field_reassign_with_default`] [#5911](https://github.com/rust-lang/rust-clippy/pull/5911)
10461046
* [`await_holding_refcell_ref`] [#6029](https://github.com/rust-lang/rust-clippy/pull/6029)
1047-
* [`disallowed_method`] [#6081](https://github.com/rust-lang/rust-clippy/pull/6081)
1047+
* [`disallowed_methods`] [#6081](https://github.com/rust-lang/rust-clippy/pull/6081)
10481048
* [`inline_asm_x86_att_syntax`] [#6092](https://github.com/rust-lang/rust-clippy/pull/6092)
10491049
* [`inline_asm_x86_intel_syntax`] [#6092](https://github.com/rust-lang/rust-clippy/pull/6092)
10501050
* [`from_iter_instead_of_collect`] [#6101](https://github.com/rust-lang/rust-clippy/pull/6101)
@@ -2821,9 +2821,9 @@ Released 2018-09-13
28212821
[`derivable_impls`]: https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls
28222822
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
28232823
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
2824-
[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
2824+
[`disallowed_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods
28252825
[`disallowed_script_idents`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_script_idents
2826-
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
2826+
[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
28272827
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
28282828
[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
28292829
[`double_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_comparisons
@@ -2904,6 +2904,7 @@ Released 2018-09-13
29042904
[`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops
29052905
[`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping
29062906
[`inconsistent_struct_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_struct_constructor
2907+
[`index_refutable_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#index_refutable_slice
29072908
[`indexing_slicing`]: https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicing
29082909
[`ineffective_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#ineffective_bit_mask
29092910
[`inefficient_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#inefficient_to_string
@@ -3038,6 +3039,7 @@ Released 2018-09-13
30383039
[`needless_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
30393040
[`needless_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop
30403041
[`needless_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
3042+
[`needless_splitn`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_splitn
30413043
[`needless_update`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_update
30423044
[`neg_cmp_op_on_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#neg_cmp_op_on_partial_ord
30433045
[`neg_multiply`]: https://rust-lang.github.io/rust-clippy/master/index.html#neg_multiply
@@ -3054,6 +3056,7 @@ Released 2018-09-13
30543056
[`nonsensical_open_options`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonsensical_open_options
30553057
[`nonstandard_macro_braces`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces
30563058
[`not_unsafe_ptr_arg_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
3059+
[`octal_escapes`]: https://rust-lang.github.io/rust-clippy/master/index.html#octal_escapes
30573060
[`ok_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect
30583061
[`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
30593062
[`option_as_ref_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref

src/tools/clippy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ itertools = "0.10"
4747
quote = "1.0"
4848
serde = { version = "1.0", features = ["derive"] }
4949
syn = { version = "1.0", features = ["full"] }
50+
parking_lot = "0.11.2"
5051

5152
[build-dependencies]
5253
rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }

src/tools/clippy/clippy_dev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ opener = "0.5"
1212
regex = "1.5"
1313
shell-escape = "0.1"
1414
walkdir = "2.3"
15+
cargo_metadata = "0.14"
1516

1617
[features]
1718
deny-warnings = []

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

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::clippy_project_root;
2+
use itertools::Itertools;
23
use shell_escape::escape;
3-
use std::ffi::OsStr;
4+
use std::ffi::{OsStr, OsString};
45
use std::path::Path;
56
use std::process::{self, Command};
67
use std::{fs, io};
@@ -56,15 +57,22 @@ pub fn run(check: bool, verbose: bool) {
5657
success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?;
5758
success &= cargo_fmt(context, &project_root.join("lintcheck"))?;
5859

59-
for entry in WalkDir::new(project_root.join("tests")) {
60-
let entry = entry?;
61-
let path = entry.path();
62-
63-
if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" {
64-
continue;
65-
}
66-
67-
success &= rustfmt(context, path)?;
60+
let chunks = WalkDir::new(project_root.join("tests"))
61+
.into_iter()
62+
.filter_map(|entry| {
63+
let entry = entry.expect("failed to find tests");
64+
let path = entry.path();
65+
66+
if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" {
67+
None
68+
} else {
69+
Some(entry.into_path().into_os_string())
70+
}
71+
})
72+
.chunks(250);
73+
74+
for chunk in &chunks {
75+
success &= rustfmt(context, chunk)?;
6876
}
6977

7078
Ok(success)
@@ -149,7 +157,7 @@ fn exec(
149157
}
150158

151159
fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
152-
let mut args = vec!["+nightly", "fmt", "--all"];
160+
let mut args = vec!["fmt", "--all"];
153161
if context.check {
154162
args.push("--");
155163
args.push("--check");
@@ -162,7 +170,7 @@ fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
162170
fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
163171
let program = "rustfmt";
164172
let dir = std::env::current_dir()?;
165-
let args = &["+nightly", "--version"];
173+
let args = &["--version"];
166174

167175
if context.verbose {
168176
println!("{}", format_command(&program, &dir, args));
@@ -185,14 +193,14 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
185193
}
186194
}
187195

188-
fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
189-
let mut args = vec!["+nightly".as_ref(), path.as_os_str()];
196+
fn rustfmt(context: &FmtContext, paths: impl Iterator<Item = OsString>) -> Result<bool, CliError> {
197+
let mut args = Vec::new();
190198
if context.check {
191-
args.push("--check".as_ref());
199+
args.push(OsString::from("--check"));
192200
}
201+
args.extend(paths);
202+
193203
let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?;
194-
if !success {
195-
eprintln!("rustfmt failed on {}", path.display());
196-
}
204+
197205
Ok(success)
198206
}

src/tools/clippy/clippy_dev/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::path::PathBuf;
77

88
pub mod bless;
99
pub mod fmt;
10+
pub mod lint;
1011
pub mod new_lint;
1112
pub mod serve;
1213
pub mod setup;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::process::{self, Command};
2+
3+
pub fn run(filename: &str) {
4+
let code = Command::new("cargo")
5+
.args(["run", "--bin", "clippy-driver", "--"])
6+
.args(["-L", "./target/debug"])
7+
.args(["-Z", "no-codegen"])
8+
.args(["--edition", "2021"])
9+
.arg(filename)
10+
.env("__CLIPPY_INTERNAL_TESTS", "true")
11+
.status()
12+
.expect("failed to run cargo")
13+
.code();
14+
15+
if code.is_none() {
16+
eprintln!("Killed by signal");
17+
}
18+
19+
process::exit(code.unwrap_or(1));
20+
}

src/tools/clippy/clippy_dev/src/main.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![warn(rust_2018_idioms, unused_lifetimes)]
44

55
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
6-
use clippy_dev::{bless, fmt, new_lint, serve, setup, update_lints};
6+
use clippy_dev::{bless, fmt, lint, new_lint, serve, setup, update_lints};
77
fn main() {
88
let matches = get_clap_config();
99

@@ -55,6 +55,10 @@ fn main() {
5555
let lint = matches.value_of("lint");
5656
serve::run(port, lint);
5757
},
58+
("lint", Some(matches)) => {
59+
let filename = matches.value_of("filename").unwrap();
60+
lint::run(filename);
61+
},
5862
_ => {},
5963
}
6064
}
@@ -219,5 +223,14 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
219223
)
220224
.arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
221225
)
226+
.subcommand(
227+
SubCommand::with_name("lint")
228+
.about("Manually run clippy on a file")
229+
.arg(
230+
Arg::with_name("filename")
231+
.required(true)
232+
.help("The path to a file to lint"),
233+
),
234+
)
222235
.get_matches()
223236
}

src/tools/clippy/clippy_dev/src/new_lint.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ fn to_camel_case(name: &str) -> String {
132132
.collect()
133133
}
134134

135+
fn get_stabilisation_version() -> String {
136+
let mut command = cargo_metadata::MetadataCommand::new();
137+
command.no_deps();
138+
if let Ok(metadata) = command.exec() {
139+
if let Some(pkg) = metadata.packages.iter().find(|pkg| pkg.name == "clippy") {
140+
return format!("{}.{}.0", pkg.version.minor, pkg.version.patch);
141+
}
142+
}
143+
144+
String::from("<TODO set version(see doc/adding_lints.md)>")
145+
}
146+
135147
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
136148
let mut contents = format!(
137149
indoc! {"
@@ -178,6 +190,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
178190
},
179191
};
180192

193+
let version = get_stabilisation_version();
181194
let lint_name = lint.name;
182195
let category = lint.category;
183196
let name_camel = to_camel_case(lint.name);
@@ -212,7 +225,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
212225
});
213226

214227
result.push_str(&format!(
215-
indoc! {"
228+
indoc! {r#"
216229
declare_clippy_lint! {{
217230
/// ### What it does
218231
///
@@ -226,11 +239,13 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
226239
/// ```rust
227240
/// // example code which does not raise clippy warning
228241
/// ```
242+
#[clippy::version = "{version}"]
229243
pub {name_upper},
230244
{category},
231-
\"default lint description\"
245+
"default lint description"
232246
}}
233-
"},
247+
"#},
248+
version = version,
234249
name_upper = name_upper,
235250
category = category,
236251
));

0 commit comments

Comments
 (0)