Skip to content

Commit 1ee5aa4

Browse files
committed
Merge commit '81f37a8150fc86f8de00e6947e86d2b69291906a' into clippyup
2 parents 7c4be43 + 81f37a8 commit 1ee5aa4

File tree

426 files changed

+6421
-2482
lines changed

Some content is hidden

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

426 files changed

+6421
-2482
lines changed

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

-12
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

+11-8
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

+1
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

+1
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

+26-18
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

+1
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;
+20
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

+14-1
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

+18-3
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
));

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

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static DEC_CLIPPY_LINT_RE: SyncLazy<Regex> = SyncLazy::new(|| {
1818
r#"(?x)
1919
declare_clippy_lint!\s*[\{(]
2020
(?:\s+///.*)*
21+
(?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])?
2122
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
2223
(?P<cat>[a-z_]+)\s*,\s*
2324
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
@@ -31,6 +32,7 @@ static DEC_DEPRECATED_LINT_RE: SyncLazy<Regex> = SyncLazy::new(|| {
3132
r#"(?x)
3233
declare_deprecated_lint!\s*[{(]\s*
3334
(?:\s+///.*)*
35+
(?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])?
3436
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
3537
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
3638
"#,
@@ -495,20 +497,23 @@ fn test_parse_contents() {
495497
let result: Vec<Lint> = parse_contents(
496498
r#"
497499
declare_clippy_lint! {
500+
#[clippy::version = "Hello Clippy!"]
498501
pub PTR_ARG,
499502
style,
500503
"really long \
501504
text"
502505
}
503506
504507
declare_clippy_lint!{
508+
#[clippy::version = "Test version"]
505509
pub DOC_MARKDOWN,
506510
pedantic,
507511
"single line"
508512
}
509513
510514
/// some doc comment
511515
declare_deprecated_lint! {
516+
#[clippy::version = "I'm a version"]
512517
pub SHOULD_ASSERT_EQ,
513518
"`assert!()` will be more flexible with RFC 2011"
514519
}

src/tools/clippy/clippy_lints/src/absurd_extreme_comparisons.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ declare_clippy_lint! {
3636
/// if vec.len() <= 0 {}
3737
/// if 100 > i32::MAX {}
3838
/// ```
39+
#[clippy::version = "pre 1.29.0"]
3940
pub ABSURD_EXTREME_COMPARISONS,
4041
correctness,
4142
"a comparison with a maximum or minimum value that is always true or false"

src/tools/clippy/clippy_lints/src/approx_const.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ declare_clippy_lint! {
3333
/// let x = std::f32::consts::PI;
3434
/// let y = std::f64::consts::FRAC_1_PI;
3535
/// ```
36+
#[clippy::version = "pre 1.29.0"]
3637
pub APPROX_CONSTANT,
3738
correctness,
3839
"the approximate of a known float constant (in `std::fXX::consts`)"

src/tools/clippy/clippy_lints/src/arithmetic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ declare_clippy_lint! {
2525
/// # let a = 0;
2626
/// a + 1;
2727
/// ```
28+
#[clippy::version = "pre 1.29.0"]
2829
pub INTEGER_ARITHMETIC,
2930
restriction,
3031
"any integer arithmetic expression which could overflow or panic"
@@ -43,6 +44,7 @@ declare_clippy_lint! {
4344
/// # let a = 0.0;
4445
/// a + 1.0;
4546
/// ```
47+
#[clippy::version = "pre 1.29.0"]
4648
pub FLOAT_ARITHMETIC,
4749
restriction,
4850
"any floating-point arithmetic statement"

0 commit comments

Comments
 (0)