Skip to content

Commit 4d6c2cc

Browse files
committed
Merge commit 'e18101137866b79045fee0ef996e696e68c920b4' into clippyup
2 parents 4061c04 + e181011 commit 4d6c2cc

File tree

220 files changed

+3201
-1532
lines changed

Some content is hidden

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

220 files changed

+3201
-1532
lines changed
File renamed without changes.

src/tools/clippy/.github/deploy.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ cp util/gh-pages/lints.json out/master
1313
if [[ -n $TAG_NAME ]]; then
1414
echo "Save the doc for the current tag ($TAG_NAME) and point stable/ to it"
1515
cp -Tr out/master "out/$TAG_NAME"
16-
ln -sf "$TAG_NAME" out/stable
16+
rm -f out/stable
17+
ln -s "$TAG_NAME" out/stable
1718
fi
1819

1920
if [[ $BETA = "true" ]]; then

src/tools/clippy/CHANGELOG.md

+158-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,162 @@ document.
66

77
## Unreleased / In Rust Nightly
88

9-
[7bfc26e...master](https://github.com/rust-lang/rust-clippy/compare/7bfc26e...master)
9+
[b7f3f7f...master](https://github.com/rust-lang/rust-clippy/compare/b7f3f7f...master)
10+
11+
## Rust 1.57
12+
13+
Current beta, release 2021-12-02
14+
15+
[7bfc26e...b7f3f7f](https://github.com/rust-lang/rust-clippy/compare/7bfc26e...b7f3f7f)
16+
17+
### New Lints
18+
19+
* [`negative_feature_names`]
20+
[#7539](https://github.com/rust-lang/rust-clippy/pull/7539)
21+
* [`redundant_feature_names`]
22+
[#7539](https://github.com/rust-lang/rust-clippy/pull/7539)
23+
* [`mod_module_files`]
24+
[#7543](https://github.com/rust-lang/rust-clippy/pull/7543)
25+
* [`self_named_module_files`]
26+
[#7543](https://github.com/rust-lang/rust-clippy/pull/7543)
27+
* [`manual_split_once`]
28+
[#7565](https://github.com/rust-lang/rust-clippy/pull/7565)
29+
* [`derivable_impls`]
30+
[#7570](https://github.com/rust-lang/rust-clippy/pull/7570)
31+
* [`needless_option_as_deref`]
32+
[#7596](https://github.com/rust-lang/rust-clippy/pull/7596)
33+
* [`iter_not_returning_iterator`]
34+
[#7610](https://github.com/rust-lang/rust-clippy/pull/7610)
35+
* [`same_name_method`]
36+
[#7653](https://github.com/rust-lang/rust-clippy/pull/7653)
37+
* [`manual_assert`] [#7669](https://github.com/rust-lang/rust-clippy/pull/7669)
38+
* [`non_send_fields_in_send_ty`]
39+
[#7709](https://github.com/rust-lang/rust-clippy/pull/7709)
40+
* [`equatable_if_let`]
41+
[#7762](https://github.com/rust-lang/rust-clippy/pull/7762)
42+
43+
### Moves and Deprecations
44+
45+
* Move [`shadow_unrelated`] to `restriction`
46+
[#7338](https://github.com/rust-lang/rust-clippy/pull/7338)
47+
* Move [`option_if_let_else`] to `nursery`
48+
[#7568](https://github.com/rust-lang/rust-clippy/pull/7568)
49+
* Move [`branches_sharing_code`] to `nursery`
50+
[#7595](https://github.com/rust-lang/rust-clippy/pull/7595)
51+
* Rename `if_let_some_result` to [`match_result_ok`] which now also handles
52+
`while let` cases [#7608](https://github.com/rust-lang/rust-clippy/pull/7608)
53+
* Move [`many_single_char_names`] to `pedantic`
54+
[#7671](https://github.com/rust-lang/rust-clippy/pull/7671)
55+
* Move [`float_cmp`] to `pedantic`
56+
[#7692](https://github.com/rust-lang/rust-clippy/pull/7692)
57+
* Rename `box_vec` to [`box_collection`] and lint on more general cases
58+
[#7693](https://github.com/rust-lang/rust-clippy/pull/7693)
59+
* Uplift `invalid_atomic_ordering` to rustc
60+
[rust-lang/rust#84039](https://github.com/rust-lang/rust/pull/84039)
61+
62+
### Enhancements
63+
64+
* Rewrite the `shadow*` lints, so that they find a lot more shadows and are not
65+
limited to certain patterns
66+
[#7338](https://github.com/rust-lang/rust-clippy/pull/7338)
67+
* The `avoid-breaking-exported-api` configuration now also works for
68+
[`box_collection`], [`redundant_allocation`], [`rc_buffer`], [`vec_box`],
69+
[`option_option`], [`linkedlist`], [`rc_mutex`]
70+
[#7560](https://github.com/rust-lang/rust-clippy/pull/7560)
71+
* [`unnecessary_unwrap`]: Now also checks for `expect`s
72+
[#7584](https://github.com/rust-lang/rust-clippy/pull/7584)
73+
* [`disallowed_method`]: Allow adding a reason that will be displayed with the
74+
lint message
75+
[#7621](https://github.com/rust-lang/rust-clippy/pull/7621)
76+
* [`approx_constant`]: Now checks the MSRV for `LOG10_2` and `LOG2_10`
77+
[#7629](https://github.com/rust-lang/rust-clippy/pull/7629)
78+
* [`approx_constant`]: Add `TAU`
79+
[#7642](https://github.com/rust-lang/rust-clippy/pull/7642)
80+
* [`needless_borrow`]: Now also lints on needless mutable borrows
81+
[#7657](https://github.com/rust-lang/rust-clippy/pull/7657)
82+
* [`missing_safety_doc`]: Now also lints on unsafe traits
83+
[#7734](https://github.com/rust-lang/rust-clippy/pull/7734)
84+
85+
### False Positive Fixes
86+
87+
* [`manual_map`]: No longer lints when the option is borrowed in the match and
88+
also consumed in the arm
89+
[#7531](https://github.com/rust-lang/rust-clippy/pull/7531)
90+
* [`filter_next`]: No longer lints if `filter` method is not the
91+
`Iterator::filter` method
92+
[#7562](https://github.com/rust-lang/rust-clippy/pull/7562)
93+
* [`manual_flatten`]: No longer lints if expression is used after `if let`
94+
[#7566](https://github.com/rust-lang/rust-clippy/pull/7566)
95+
* [`option_if_let_else`]: Multiple fixes
96+
[#7573](https://github.com/rust-lang/rust-clippy/pull/7573)
97+
* `break` and `continue` statements local to the would-be closure are
98+
allowed
99+
* Don't lint in const contexts
100+
* Don't lint when yield expressions are used
101+
* Don't lint when the captures made by the would-be closure conflict with
102+
the other branch
103+
* Don't lint when a field of a local is used when the type could be
104+
potentially moved from
105+
* In some cases, don't lint when scrutinee expression conflicts with the
106+
captures of the would-be closure
107+
* [`redundant_allocation`]: No longer lints on `Box<Box<dyn T>>` which replaces
108+
wide pointers with thin pointers
109+
[#7592](https://github.com/rust-lang/rust-clippy/pull/7592)
110+
* [`bool_assert_comparison`]: No longer lints on types that do not implement the
111+
`Not` trait with `Output = bool`
112+
[#7605](https://github.com/rust-lang/rust-clippy/pull/7605)
113+
* [`mut_range_bound`]: No longer lints on range bound mutations, that are
114+
immediately followed by a `break;`
115+
[#7607](https://github.com/rust-lang/rust-clippy/pull/7607)
116+
* [`mutable_key_type`]: Improve accuracy and document remaining false positives
117+
and false negatives
118+
[#7640](https://github.com/rust-lang/rust-clippy/pull/7640)
119+
* [`redundant_closure`]: Rewrite the lint to fix various false positives and
120+
false negatives [#7661](https://github.com/rust-lang/rust-clippy/pull/7661)
121+
* [`large_enum_variant`]: No longer wrongly identifies the second largest
122+
variant [#7677](https://github.com/rust-lang/rust-clippy/pull/7677)
123+
* [`needless_return`]: No longer lints on let-else expressions
124+
[#7685](https://github.com/rust-lang/rust-clippy/pull/7685)
125+
* [`suspicious_else_formatting`]: No longer lints in proc-macros
126+
[#7707](https://github.com/rust-lang/rust-clippy/pull/7707)
127+
* [`excessive_precision`]: No longer lints when in some cases the float was
128+
already written in the shortest form
129+
[#7722](https://github.com/rust-lang/rust-clippy/pull/7722)
130+
* [`doc_markdown`]: No longer lints on intra-doc links
131+
[#7772](https://github.com/rust-lang/rust-clippy/pull/7772)
132+
133+
### Suggestion Fixes/Improvements
134+
135+
* [`unnecessary_operation`]: Recommend using an `assert!` instead of using a
136+
function call in an indexing operation
137+
[#7453](https://github.com/rust-lang/rust-clippy/pull/7453)
138+
* [`manual_split_once`]: Produce semantically equivalent suggestion when
139+
`rsplitn` is used [#7663](https://github.com/rust-lang/rust-clippy/pull/7663)
140+
* [`while_let_on_iterator`]: Produce correct suggestion when using `&mut`
141+
[#7690](https://github.com/rust-lang/rust-clippy/pull/7690)
142+
* [`manual_assert`]: No better handles complex conditions
143+
[#7741](https://github.com/rust-lang/rust-clippy/pull/7741)
144+
* Correctly handle signs in exponents in numeric literals lints
145+
[#7747](https://github.com/rust-lang/rust-clippy/pull/7747)
146+
* [`suspicious_map`]: Now also suggests to use `inspect` as an alternative
147+
[#7770](https://github.com/rust-lang/rust-clippy/pull/7770)
148+
* Drop exponent from suggestion if it is 0 in numeric literals lints
149+
[#7774](https://github.com/rust-lang/rust-clippy/pull/7774)
150+
151+
### ICE Fixes
152+
153+
* [`implicit_hasher`]
154+
[#7761](https://github.com/rust-lang/rust-clippy/pull/7761)
155+
156+
### Others
157+
158+
* Clippy now uses the 2021
159+
[Edition!](https://www.youtube.com/watch?v=q0aNduqb2Ro)
160+
[#7664](https://github.com/rust-lang/rust-clippy/pull/7664)
10161

11162
## Rust 1.56
12163

13-
Current beta, release 2021-10-21
164+
Current stable, released 2021-10-21
14165

15166
[74d1561...7bfc26e](https://github.com/rust-lang/rust-clippy/compare/74d1561...7bfc26e)
16167

@@ -74,13 +225,9 @@ Current beta, release 2021-10-21
74225
* [`unnested_or_patterns`]: Removed `or_patterns` feature gate in the code
75226
example [#7507](https://github.com/rust-lang/rust-clippy/pull/7507)
76227

77-
### New Lints
78-
79-
* Renamed Lint: `if_let_some_result` is now called [`match_result_ok`]. Now also handles `while let` case.
80-
81228
## Rust 1.55
82229

83-
Current stable, released 2021-09-09
230+
Released 2021-09-09
84231

85232
[3ae8faf...74d1561](https://github.com/rust-lang/rust-clippy/compare/3ae8faf...74d1561)
86233

@@ -2748,7 +2895,6 @@ Released 2018-09-13
27482895
[`if_let_redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_redundant_pattern_matching
27492896
[`if_not_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else
27502897
[`if_same_then_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
2751-
[`if_then_panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_panic
27522898
[`if_then_some_else_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none
27532899
[`ifs_same_cond`]: https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond
27542900
[`implicit_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone
@@ -2806,6 +2952,7 @@ Released 2018-09-13
28062952
[`lossy_float_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#lossy_float_literal
28072953
[`macro_use_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#macro_use_imports
28082954
[`main_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#main_recursion
2955+
[`manual_assert`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert
28092956
[`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn
28102957
[`manual_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter_map
28112958
[`manual_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find_map
@@ -2976,6 +3123,7 @@ Released 2018-09-13
29763123
[`self_named_constructors`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_named_constructors
29773124
[`self_named_module_files`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_named_module_files
29783125
[`semicolon_if_nothing_returned`]: https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
3126+
[`separated_literal_suffix`]: https://rust-lang.github.io/rust-clippy/master/index.html#separated_literal_suffix
29793127
[`serde_api_misuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#serde_api_misuse
29803128
[`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse
29813129
[`shadow_same`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_same
@@ -3000,6 +3148,7 @@ Released 2018-09-13
30003148
[`string_extend_chars`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_extend_chars
30013149
[`string_from_utf8_as_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_from_utf8_as_bytes
30023150
[`string_lit_as_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_lit_as_bytes
3151+
[`string_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_slice
30033152
[`string_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_to_string
30043153
[`strlen_on_c_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#strlen_on_c_strings
30053154
[`struct_excessive_bools`]: https://rust-lang.github.io/rust-clippy/master/index.html#struct_excessive_bools
@@ -3046,6 +3195,7 @@ Released 2018-09-13
30463195
[`uninit_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_vec
30473196
[`unit_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
30483197
[`unit_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp
3198+
[`unit_hash`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_hash
30493199
[`unit_return_expecting_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_return_expecting_ord
30503200
[`unnecessary_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
30513201
[`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map

src/tools/clippy/CONTRIBUTING.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ to be run inside the `rust` directory):
262262
2. Checkout the commit from the latest available nightly. You can get it using `rustup check`.
263263
3. Sync the changes to the rust-copy of Clippy to your Clippy fork:
264264
```bash
265-
# Make sure to change `your-github-name` to your github name in the following command
265+
# Make sure to change `your-github-name` to your github name in the following command. Also be
266+
# sure to either use a net-new branch, e.g. `sync-from-rust`, or delete the branch beforehand
267+
# because changes cannot be fast forwarded
266268
git subtree push -P src/tools/clippy [email protected]:your-github-name/rust-clippy sync-from-rust
267269
```
268270

src/tools/clippy/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tempfile = { version = "3.2", optional = true }
2828

2929
[dev-dependencies]
3030
cargo_metadata = "0.14"
31-
compiletest_rs = { version = "0.7", features = ["tmp"] }
31+
compiletest_rs = { version = "0.7.1", features = ["tmp"] }
3232
tester = "0.9"
3333
regex = "1.5"
3434
# This is used by the `collect-metadata` alias.

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

+29-11
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str
4242
};
4343

4444
create_lint(&lint, msrv).context("Unable to create lint implementation")?;
45-
create_test(&lint).context("Unable to create a test for the new lint")
45+
create_test(&lint).context("Unable to create a test for the new lint")?;
46+
add_lint(&lint, msrv).context("Unable to add lint to clippy_lints/src/lib.rs")
4647
}
4748

4849
fn create_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
@@ -80,6 +81,33 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
8081
}
8182
}
8283

84+
fn add_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
85+
let path = "clippy_lints/src/lib.rs";
86+
let mut lib_rs = fs::read_to_string(path).context("reading")?;
87+
88+
let comment_start = lib_rs.find("// add lints here,").expect("Couldn't find comment");
89+
90+
let new_lint = if enable_msrv {
91+
format!(
92+
"store.register_{lint_pass}_pass(move || Box::new({module_name}::{camel_name}::new(msrv)));\n ",
93+
lint_pass = lint.pass,
94+
module_name = lint.name,
95+
camel_name = to_camel_case(lint.name),
96+
)
97+
} else {
98+
format!(
99+
"store.register_{lint_pass}_pass(|| Box::new({module_name}::{camel_name}));\n ",
100+
lint_pass = lint.pass,
101+
module_name = lint.name,
102+
camel_name = to_camel_case(lint.name),
103+
)
104+
};
105+
106+
lib_rs.insert_str(comment_start, &new_lint);
107+
108+
fs::write(path, lib_rs).context("writing")
109+
}
110+
83111
fn write_file<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> {
84112
fn inner(path: &Path, contents: &[u8]) -> io::Result<()> {
85113
OpenOptions::new()
@@ -151,7 +179,6 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
151179
};
152180

153181
let lint_name = lint.name;
154-
let pass_name = lint.pass;
155182
let category = lint.category;
156183
let name_camel = to_camel_case(lint.name);
157184
let name_upper = lint_name.to_uppercase();
@@ -228,18 +255,14 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
228255
extract_msrv_attr!({context_import});
229256
}}
230257
231-
// TODO: Register the lint pass in `clippy_lints/src/lib.rs`,
232-
// e.g. store.register_{pass_name}_pass(move || Box::new({module_name}::{name_camel}::new(msrv)));
233258
// TODO: Add MSRV level to `clippy_utils/src/msrvs.rs` if needed.
234259
// TODO: Add MSRV test to `tests/ui/min_rust_version_attr.rs`.
235260
// TODO: Update msrv config comment in `clippy_lints/src/utils/conf.rs`
236261
"},
237262
pass_type = pass_type,
238263
pass_lifetimes = pass_lifetimes,
239-
pass_name = pass_name,
240264
name_upper = name_upper,
241265
name_camel = name_camel,
242-
module_name = lint_name,
243266
context_import = context_import,
244267
)
245268
} else {
@@ -248,16 +271,11 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
248271
declare_lint_pass!({name_camel} => [{name_upper}]);
249272
250273
impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
251-
//
252-
// TODO: Register the lint pass in `clippy_lints/src/lib.rs`,
253-
// e.g. store.register_{pass_name}_pass(|| Box::new({module_name}::{name_camel}));
254274
"},
255275
pass_type = pass_type,
256276
pass_lifetimes = pass_lifetimes,
257-
pass_name = pass_name,
258277
name_upper = name_upper,
259278
name_camel = name_camel,
260-
module_name = lint_name,
261279
)
262280
});
263281

0 commit comments

Comments
 (0)