Skip to content

Commit e273fca

Browse files
committed
Auto merge of #93865 - flip1995:clippyup, r=Manishearth,flip1995
Update Clippy r? `@Manishearth`
2 parents e646f3d + 04c9842 commit e273fca

File tree

123 files changed

+4465
-3159
lines changed

Some content is hidden

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

123 files changed

+4465
-3159
lines changed

src/tools/clippy/CHANGELOG.md

+177-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,185 @@ document.
66

77
## Unreleased / In Rust Nightly
88

9-
[e181011...master](https://github.com/rust-lang/rust-clippy/compare/e181011...master)
9+
[0eff589...master](https://github.com/rust-lang/rust-clippy/compare/0eff589...master)
1010

11-
## Rust 1.58 (beta)
11+
## Rust 1.59 (beta)
1212

13-
Current beta, release 2022-01-13
13+
Current beta, release 2022-02-24
14+
15+
[e181011...0eff589](https://github.com/rust-lang/rust-clippy/compare/e181011...0eff589)
16+
17+
### New Lints
18+
19+
* [`index_refutable_slice`]
20+
[#7643](https://github.com/rust-lang/rust-clippy/pull/7643)
21+
* [`needless_splitn`]
22+
[#7896](https://github.com/rust-lang/rust-clippy/pull/7896)
23+
* [`unnecessary_to_owned`]
24+
[#7978](https://github.com/rust-lang/rust-clippy/pull/7978)
25+
* [`needless_late_init`]
26+
[#7995](https://github.com/rust-lang/rust-clippy/pull/7995)
27+
* [`octal_escapes`] [#8007](https://github.com/rust-lang/rust-clippy/pull/8007)
28+
* [`return_self_not_must_use`]
29+
[#8071](https://github.com/rust-lang/rust-clippy/pull/8071)
30+
* [`init_numbered_fields`]
31+
[#8170](https://github.com/rust-lang/rust-clippy/pull/8170)
32+
33+
### Moves and Deprecations
34+
35+
* Move `if_then_panic` to `pedantic` and rename to [`manual_assert`] (now
36+
allow-by-default) [#7810](https://github.com/rust-lang/rust-clippy/pull/7810)
37+
* Rename `disallow_type` to [`disallowed_types`] and `disallowed_method` to
38+
[`disallowed_methods`]
39+
[#7984](https://github.com/rust-lang/rust-clippy/pull/7984)
40+
* Move [`map_flatten`] to `complexity` (now warn-by-default)
41+
[#8054](https://github.com/rust-lang/rust-clippy/pull/8054)
42+
43+
### Enhancements
44+
45+
* [`match_overlapping_arm`]: Fix false negative where after included ranges,
46+
overlapping ranges weren't linted anymore
47+
[#7909](https://github.com/rust-lang/rust-clippy/pull/7909)
48+
* [`deprecated_cfg_attr`]: Now takes the specified MSRV into account
49+
[#7944](https://github.com/rust-lang/rust-clippy/pull/7944)
50+
* [`cast_lossless`]: Now also lints for `bool` to integer casts
51+
[#7948](https://github.com/rust-lang/rust-clippy/pull/7948)
52+
* [`let_underscore_lock`]: Also emit lints for the `parking_lot` crate
53+
[#7957](https://github.com/rust-lang/rust-clippy/pull/7957)
54+
* [`needless_borrow`]
55+
[#7977](https://github.com/rust-lang/rust-clippy/pull/7977)
56+
* Lint when a borrow is auto-dereffed more than once
57+
* Lint in the trailing expression of a block for a match arm
58+
* [`strlen_on_c_strings`]
59+
[8001](https://github.com/rust-lang/rust-clippy/pull/8001)
60+
* Lint when used without a fully-qualified path
61+
* Suggest removing the surrounding unsafe block when possible
62+
* [`non_ascii_literal`]: Now also lints on `char`s, not just `string`s
63+
[#8034](https://github.com/rust-lang/rust-clippy/pull/8034)
64+
* [`single_char_pattern`]: Now also lints on `split_inclusive`, `split_once`,
65+
`rsplit_once`, `replace`, and `replacen`
66+
[#8077](https://github.com/rust-lang/rust-clippy/pull/8077)
67+
* [`unwrap_or_else_default`]: Now also lints on `std` constructors like
68+
`Vec::new`, `HashSet::new`, and `HashMap::new`
69+
[#8163](https://github.com/rust-lang/rust-clippy/pull/8163)
70+
* [`shadow_reuse`]: Now also lints on shadowed `if let` bindings, instead of
71+
[`shadow_unrelated`]
72+
[#8165](https://github.com/rust-lang/rust-clippy/pull/8165)
73+
74+
### False Positive Fixes
75+
76+
* [`or_fun_call`], [`unnecessary_lazy_evaluations`]: Improve heuristics, so that
77+
cheap functions (e.g. calling `.len()` on a `Vec`) won't get linted anymore
78+
[#7639](https://github.com/rust-lang/rust-clippy/pull/7639)
79+
* [`manual_split_once`]: No longer suggests code changing the original behavior
80+
[#7896](https://github.com/rust-lang/rust-clippy/pull/7896)
81+
* Don't show [`no_effect`] or [`unnecessary_operation`] warning for unit struct
82+
implementing `FnOnce`
83+
[#7898](https://github.com/rust-lang/rust-clippy/pull/7898)
84+
* [`semicolon_if_nothing_returned`]: Fixed a bug, where the lint wrongly
85+
triggered on `let-else` statements
86+
[#7955](https://github.com/rust-lang/rust-clippy/pull/7955)
87+
* [`if_then_some_else_none`]: No longer lints if there is an early return
88+
[#7980](https://github.com/rust-lang/rust-clippy/pull/7980)
89+
* [`needless_collect`]: No longer suggests removal of `collect` when removal
90+
would create code requiring mutably borrowing a value multiple times
91+
[#7982](https://github.com/rust-lang/rust-clippy/pull/7982)
92+
* [`shadow_same`]: Fix false positive for `async` function's params
93+
[#7997](https://github.com/rust-lang/rust-clippy/pull/7997)
94+
* [`suboptimal_flops`]: No longer triggers in constant functions
95+
[#8009](https://github.com/rust-lang/rust-clippy/pull/8009)
96+
* [`type_complexity`]: No longer lints on associated types in traits
97+
[#8030](https://github.com/rust-lang/rust-clippy/pull/8030)
98+
* [`question_mark`]: No longer lints if returned object is not local
99+
[#8080](https://github.com/rust-lang/rust-clippy/pull/8080)
100+
* [`option_if_let_else`]: No longer lint on complex sub-patterns
101+
[#8086](https://github.com/rust-lang/rust-clippy/pull/8086)
102+
* [`blocks_in_if_conditions`]: No longer lints on empty closures
103+
[#8100](https://github.com/rust-lang/rust-clippy/pull/8100)
104+
* [`enum_variant_names`]: No longer lint when first prefix is only a substring
105+
of a camel-case word
106+
[#8127](https://github.com/rust-lang/rust-clippy/pull/8127)
107+
* [`identity_op`]: Only lint on integral operands
108+
[#8183](https://github.com/rust-lang/rust-clippy/pull/8183)
109+
110+
### Suggestion Fixes/Improvements
111+
112+
* [`search_is_some`]: Fix suggestion for `any()` not taking item by reference
113+
[#7463](https://github.com/rust-lang/rust-clippy/pull/7463)
114+
* [`almost_swapped`]: Now detects if there is a `no_std` or `no_core` attribute
115+
and adapts the suggestion accordingly
116+
[#7877](https://github.com/rust-lang/rust-clippy/pull/7877)
117+
* [`redundant_pattern_matching`]: Fix suggestion for deref expressions
118+
[#7949](https://github.com/rust-lang/rust-clippy/pull/7949)
119+
* [`explicit_counter_loop`]: Now also produces a suggestion for non-`usize`
120+
types [#7950](https://github.com/rust-lang/rust-clippy/pull/7950)
121+
* [`manual_map`]: Fix suggestion when used with unsafe functions and blocks
122+
[#7968](https://github.com/rust-lang/rust-clippy/pull/7968)
123+
* [`option_map_or_none`]: Suggest `map` over `and_then` when possible
124+
[#7971](https://github.com/rust-lang/rust-clippy/pull/7971)
125+
* [`option_if_let_else`]: No longer expands macros in the suggestion
126+
[#7974](https://github.com/rust-lang/rust-clippy/pull/7974)
127+
* [`iter_cloned_collect`]: Suggest `copied` over `cloned` when possible
128+
[#8006](https://github.com/rust-lang/rust-clippy/pull/8006)
129+
* [`doc_markdown`]: No longer uses inline hints to improve readability of
130+
suggestion [#8011](https://github.com/rust-lang/rust-clippy/pull/8011)
131+
* [`needless_question_mark`]: Now better explains the suggestion
132+
[#8028](https://github.com/rust-lang/rust-clippy/pull/8028)
133+
* [`single_char_pattern`]: Escape backslash `\` in suggestion
134+
[#8067](https://github.com/rust-lang/rust-clippy/pull/8067)
135+
* [`needless_bool`]: Suggest `a != b` over `!(a == b)`
136+
[#8117](https://github.com/rust-lang/rust-clippy/pull/8117)
137+
* [`iter_skip_next`]: Suggest to add a `mut` if it is necessary in order to
138+
apply this lints suggestion
139+
[#8133](https://github.com/rust-lang/rust-clippy/pull/8133)
140+
* [`neg_multiply`]: Now produces a suggestion
141+
[#8144](https://github.com/rust-lang/rust-clippy/pull/8144)
142+
* [`needless_return`]: Now suggests the unit type `()` over an empty block `{}`
143+
in match arms [#8185](https://github.com/rust-lang/rust-clippy/pull/8185)
144+
* [`suboptimal_flops`]: Now gives a syntactically correct suggestion for
145+
`to_radians` and `to_degrees`
146+
[#8187](https://github.com/rust-lang/rust-clippy/pull/8187)
147+
148+
### ICE Fixes
149+
150+
* [`undocumented_unsafe_blocks`]
151+
[#7945](https://github.com/rust-lang/rust-clippy/pull/7945)
152+
[#7988](https://github.com/rust-lang/rust-clippy/pull/7988)
153+
* [`unnecessary_cast`]
154+
[#8167](https://github.com/rust-lang/rust-clippy/pull/8167)
155+
156+
### Documentation Improvements
157+
158+
* [`print_stdout`], [`print_stderr`], [`dbg_macro`]: Document how the lint level
159+
can be changed crate-wide
160+
[#8040](https://github.com/rust-lang/rust-clippy/pull/8040)
161+
* Added a note to the `README` that config changes don't apply to already
162+
compiled code [#8175](https://github.com/rust-lang/rust-clippy/pull/8175)
163+
164+
### Others
165+
166+
* [Clippy's lint
167+
list](https://rust-lang.github.io/rust-clippy/master/index.html) now displays
168+
the version a lint was added. :tada:
169+
[#7813](https://github.com/rust-lang/rust-clippy/pull/7813)
170+
* New and improved issue templates
171+
[#8032](https://github.com/rust-lang/rust-clippy/pull/8032)
172+
* _Dev:_ Add `cargo dev lint` command, to run your modified Clippy version on a
173+
file [#7917](https://github.com/rust-lang/rust-clippy/pull/7917)
174+
175+
## Rust 1.58
176+
177+
Current stable, released 2022-01-13
14178

15179
[00e31fa...e181011](https://github.com/rust-lang/rust-clippy/compare/00e31fa...e181011)
16180

181+
### Rust 1.58.1
182+
183+
* Move [`non_send_fields_in_send_ty`] to `nursery` (now allow-by-default)
184+
[#8075](https://github.com/rust-lang/rust-clippy/pull/8075)
185+
* [`useless_format`]: Handle implicit named arguments
186+
[#8295](https://github.com/rust-lang/rust-clippy/pull/8295)
187+
17188
### New lints
18189

19190
* [`transmute_num_to_bytes`]
@@ -124,7 +295,7 @@ Current beta, release 2022-01-13
124295

125296
## Rust 1.57
126297

127-
Current stable, released 2021-12-02
298+
Released 2021-12-02
128299

129300
[7bfc26e...00e31fa](https://github.com/rust-lang/rust-clippy/compare/7bfc26e...00e31fa)
130301

@@ -2930,6 +3101,7 @@ Released 2018-09-13
29303101
[`declare_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
29313102
[`default_numeric_fallback`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback
29323103
[`default_trait_access`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_trait_access
3104+
[`default_union_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_union_representation
29333105
[`deprecated_cfg_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_cfg_attr
29343106
[`deprecated_semver`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_semver
29353107
[`deref_addrof`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
@@ -3303,6 +3475,7 @@ Released 2018-09-13
33033475
[`transmute_num_to_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_num_to_bytes
33043476
[`transmute_ptr_to_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ptr
33053477
[`transmute_ptr_to_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref
3478+
[`transmute_undefined_repr`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_undefined_repr
33063479
[`transmutes_expressible_as_ptr_casts`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmutes_expressible_as_ptr_casts
33073480
[`transmuting_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmuting_null
33083481
[`trivial_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivial_regex

src/tools/clippy/clippy_dev/src/bless.rs

+18-47
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use std::ffi::OsStr;
55
use std::fs;
66
use std::lazy::SyncLazy;
77
use std::path::{Path, PathBuf};
8-
use walkdir::WalkDir;
9-
10-
use crate::clippy_project_root;
8+
use walkdir::{DirEntry, WalkDir};
119

1210
#[cfg(not(windows))]
1311
static CARGO_CLIPPY_EXE: &str = "cargo-clippy";
@@ -24,43 +22,25 @@ static CLIPPY_BUILD_TIME: SyncLazy<Option<std::time::SystemTime>> = SyncLazy::ne
2422
///
2523
/// Panics if the path to a test file is broken
2624
pub fn bless(ignore_timestamp: bool) {
27-
let test_suite_dirs = [
28-
clippy_project_root().join("tests").join("ui"),
29-
clippy_project_root().join("tests").join("ui-internal"),
30-
clippy_project_root().join("tests").join("ui-toml"),
31-
clippy_project_root().join("tests").join("ui-cargo"),
32-
];
33-
for test_suite_dir in &test_suite_dirs {
34-
WalkDir::new(test_suite_dir)
35-
.into_iter()
36-
.filter_map(Result::ok)
37-
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
38-
.for_each(|f| {
39-
let test_name = f.path().strip_prefix(test_suite_dir).unwrap();
40-
for &ext in &["stdout", "stderr", "fixed"] {
41-
let test_name_ext = format!("stage-id.{}", ext);
42-
update_reference_file(
43-
f.path().with_extension(ext),
44-
test_name.with_extension(test_name_ext),
45-
ignore_timestamp,
46-
);
47-
}
48-
});
49-
}
25+
let extensions = ["stdout", "stderr", "fixed"].map(OsStr::new);
26+
27+
WalkDir::new(build_dir())
28+
.into_iter()
29+
.map(Result::unwrap)
30+
.filter(|entry| entry.path().extension().map_or(false, |ext| extensions.contains(&ext)))
31+
.for_each(|entry| update_reference_file(&entry, ignore_timestamp));
5032
}
5133

52-
fn update_reference_file(reference_file_path: PathBuf, test_name: PathBuf, ignore_timestamp: bool) {
53-
let test_output_path = build_dir().join(test_name);
54-
let relative_reference_file_path = reference_file_path.strip_prefix(clippy_project_root()).unwrap();
34+
fn update_reference_file(test_output_entry: &DirEntry, ignore_timestamp: bool) {
35+
let test_output_path = test_output_entry.path();
5536

56-
// If compiletest did not write any changes during the test run,
57-
// we don't have to update anything
58-
if !test_output_path.exists() {
59-
return;
60-
}
37+
let reference_file_name = test_output_entry.file_name().to_str().unwrap().replace(".stage-id", "");
38+
let reference_file_path = Path::new("tests")
39+
.join(test_output_path.strip_prefix(build_dir()).unwrap())
40+
.with_file_name(reference_file_name);
6141

6242
// If the test output was not updated since the last clippy build, it may be outdated
63-
if !ignore_timestamp && !updated_since_clippy_build(&test_output_path).unwrap_or(true) {
43+
if !ignore_timestamp && !updated_since_clippy_build(test_output_entry).unwrap_or(true) {
6444
return;
6545
}
6646

@@ -69,23 +49,14 @@ fn update_reference_file(reference_file_path: PathBuf, test_name: PathBuf, ignor
6949

7050
if test_output_file != reference_file {
7151
// If a test run caused an output file to change, update the reference file
72-
println!("updating {}", &relative_reference_file_path.display());
52+
println!("updating {}", reference_file_path.display());
7353
fs::copy(test_output_path, &reference_file_path).expect("Could not update reference file");
74-
75-
// We need to re-read the file now because it was potentially updated from copying
76-
let reference_file = fs::read(&reference_file_path).unwrap_or_default();
77-
78-
if reference_file.is_empty() {
79-
// If we copied over an empty output file, we remove the now empty reference file
80-
println!("removing {}", &relative_reference_file_path.display());
81-
fs::remove_file(reference_file_path).expect("Could not remove reference file");
82-
}
8354
}
8455
}
8556

86-
fn updated_since_clippy_build(path: &Path) -> Option<bool> {
57+
fn updated_since_clippy_build(entry: &DirEntry) -> Option<bool> {
8758
let clippy_build_time = (*CLIPPY_BUILD_TIME)?;
88-
let modified = fs::metadata(path).ok()?.modified().ok()?;
59+
let modified = entry.metadata().ok()?.modified().ok()?;
8960
Some(modified >= clippy_build_time)
9061
}
9162

src/tools/clippy/clippy_lints/src/blocks_in_if_conditions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
2+
use clippy_utils::get_parent_expr;
23
use clippy_utils::higher;
34
use clippy_utils::source::snippet_block_with_applicability;
45
use clippy_utils::ty::implements_trait;
5-
use clippy_utils::{differing_macro_contexts, get_parent_expr};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
88
use rustc_hir::intravisit::{walk_expr, Visitor};
@@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions {
9797
if let Some(ex) = &block.expr {
9898
// don't dig into the expression here, just suggest that they remove
9999
// the block
100-
if expr.span.from_expansion() || differing_macro_contexts(expr.span, ex.span) {
100+
if expr.span.from_expansion() || ex.span.from_expansion() {
101101
return;
102102
}
103103
let mut applicability = Applicability::MachineApplicable;
@@ -122,7 +122,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions {
122122
}
123123
} else {
124124
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
125-
if span.from_expansion() || differing_macro_contexts(expr.span, span) {
125+
if span.from_expansion() || expr.span.from_expansion() {
126126
return;
127127
}
128128
// move block higher

0 commit comments

Comments
 (0)