Skip to content

Commit 090ab8c

Browse files
authored
Rollup merge of #81038 - flip1995:clippyup, r=Manishearth
Update Clippy Biweekly Clippy update r? ``@Manishearth``
2 parents 86e0ff4 + 3e236b3 commit 090ab8c

File tree

103 files changed

+2328
-248
lines changed

Some content is hidden

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

103 files changed

+2328
-248
lines changed

src/tools/clippy/CHANGELOG.md

+134-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,138 @@ document.
66

77
## Unreleased / In Rust Nightly
88

9-
[b20d4c1...master](https://github.com/rust-lang/rust-clippy/compare/b20d4c1...master)
9+
[4911ab1...master](https://github.com/rust-lang/rust-clippy/compare/4911ab1...master)
10+
11+
## Rust 1.50
12+
13+
Current beta, release 2021-02-11
14+
15+
[b20d4c1...4911ab1](https://github.com/rust-lang/rust-clippy/compare/b20d4c1...4911ab1)
16+
17+
### New Lints
18+
19+
* [`suspicious_operation_groupings`] [#6086](https://github.com/rust-lang/rust-clippy/pull/6086)
20+
* [`size_of_in_element_count`] [#6394](https://github.com/rust-lang/rust-clippy/pull/6394)
21+
* [`unnecessary_wraps`] [#6070](https://github.com/rust-lang/rust-clippy/pull/6070)
22+
* [`let_underscore_drop`] [#6305](https://github.com/rust-lang/rust-clippy/pull/6305)
23+
* [`collapsible_match`] [#6402](https://github.com/rust-lang/rust-clippy/pull/6402)
24+
* [`redundant_else`] [#6330](https://github.com/rust-lang/rust-clippy/pull/6330)
25+
* [`zero_sized_map_values`] [#6218](https://github.com/rust-lang/rust-clippy/pull/6218)
26+
* [`print_stderr`] [#6367](https://github.com/rust-lang/rust-clippy/pull/6367)
27+
* [`string_from_utf8_as_bytes`] [#6134](https://github.com/rust-lang/rust-clippy/pull/6134)
28+
29+
### Moves and Deprecations
30+
31+
* Previously deprecated [`str_to_string`] and [`string_to_string`] have been un-deprecated
32+
as `restriction` lints [#6333](https://github.com/rust-lang/rust-clippy/pull/6333)
33+
* Deprecate [`panic_params`] lint. This is now available in rustc as `panic_fmt`
34+
[#6351](https://github.com/rust-lang/rust-clippy/pull/6351)
35+
* Move [`map_err_ignore`] to `restriction`
36+
[#6416](https://github.com/rust-lang/rust-clippy/pull/6416)
37+
* Move [`await_holding_refcell_ref`] to `pedantic`
38+
[#6354](https://github.com/rust-lang/rust-clippy/pull/6354)
39+
* Move [`await_holding_lock`] to `pedantic`
40+
[#6354](https://github.com/rust-lang/rust-clippy/pull/6354)
41+
42+
### Enhancements
43+
44+
* Add the `unreadable-literal-lint-fractions` configuration to disable
45+
the `unreadable_literal` lint for fractions
46+
[#6421](https://github.com/rust-lang/rust-clippy/pull/6421)
47+
* [`clone_on_copy`]: Now shows the type in the lint message
48+
[#6443](https://github.com/rust-lang/rust-clippy/pull/6443)
49+
* [`redundant_pattern_matching`]: Now also lints on `std::task::Poll`
50+
[#6339](https://github.com/rust-lang/rust-clippy/pull/6339)
51+
* [`redundant_pattern_matching`]: Additionally also lints on `std::net::IpAddr`
52+
[#6377](https://github.com/rust-lang/rust-clippy/pull/6377)
53+
* [`search_is_some`]: Now suggests `contains` instead of `find(foo).is_some()`
54+
[#6119](https://github.com/rust-lang/rust-clippy/pull/6119)
55+
* [`clone_double_ref`]: Now prints the reference type in the lint message
56+
[#6442](https://github.com/rust-lang/rust-clippy/pull/6442)
57+
* [`modulo_one`]: Now also lints on -1.
58+
[#6360](https://github.com/rust-lang/rust-clippy/pull/6360)
59+
* [`empty_loop`]: Now lints no_std crates, too
60+
[#6205](https://github.com/rust-lang/rust-clippy/pull/6205)
61+
* [`or_fun_call`]: Now also lints when indexing `HashMap` or `BTreeMap`
62+
[#6267](https://github.com/rust-lang/rust-clippy/pull/6267)
63+
* [`wrong_self_convention`]: Now also lints in trait definitions
64+
[#6316](https://github.com/rust-lang/rust-clippy/pull/6316)
65+
* [`needless_borrow`]: Print the type in the lint message
66+
[#6449](https://github.com/rust-lang/rust-clippy/pull/6449)
67+
68+
[msrv_readme]: https://github.com/rust-lang/rust-clippy#specifying-the-minimum-supported-rust-version
69+
70+
### False Positive Fixes
71+
72+
* [`manual_range_contains`]: No longer lints in `const fn`
73+
[#6382](https://github.com/rust-lang/rust-clippy/pull/6382)
74+
* [`unnecessary_lazy_evaluations`]: No longer lints if closure argument is used
75+
[#6370](https://github.com/rust-lang/rust-clippy/pull/6370)
76+
* [`match_single_binding`]: Now ignores cases with `#[cfg()]` macros
77+
[#6435](https://github.com/rust-lang/rust-clippy/pull/6435)
78+
* [`match_like_matches_macro`]: No longer lints on arms with attributes
79+
[#6290](https://github.com/rust-lang/rust-clippy/pull/6290)
80+
* [`map_clone`]: No longer lints with deref and clone
81+
[#6269](https://github.com/rust-lang/rust-clippy/pull/6269)
82+
* [`map_clone`]: No longer lints in the case of &mut
83+
[#6301](https://github.com/rust-lang/rust-clippy/pull/6301)
84+
* [`needless_update`]: Now ignores `non_exhaustive` structs
85+
[#6464](https://github.com/rust-lang/rust-clippy/pull/6464)
86+
* [`needless_collect`]: No longer lints when a collect is needed multiple times
87+
[#6313](https://github.com/rust-lang/rust-clippy/pull/6313)
88+
* [`unnecessary_cast`] No longer lints cfg-dependent types
89+
[#6369](https://github.com/rust-lang/rust-clippy/pull/6369)
90+
* [`declare_interior_mutable_const`] and [`borrow_interior_mutable_const`]:
91+
Both now ignore enums with frozen variants
92+
[#6110](https://github.com/rust-lang/rust-clippy/pull/6110)
93+
94+
95+
### Suggestion Fixes/Improvements
96+
97+
* [`vec_box`]: Provide correct type scope suggestion
98+
[#6271](https://github.com/rust-lang/rust-clippy/pull/6271)
99+
* [`manual_range_contains`]: Give correct suggestion when using floats
100+
[#6320](https://github.com/rust-lang/rust-clippy/pull/6320)
101+
* [`unnecessary_lazy_evaluations`]: Don't always mark suggestion as MachineApplicable
102+
[#6272](https://github.com/rust-lang/rust-clippy/pull/6272)
103+
* [`manual_async_fn`]: Improve suggestion formatting
104+
[#6294](https://github.com/rust-lang/rust-clippy/pull/6294)
105+
* [`unnecessary_cast`]: Fix incorrectly formatted float literal suggestion
106+
[#6362](https://github.com/rust-lang/rust-clippy/pull/6362)
107+
108+
### ICE Fixes
109+
110+
* Fix a crash in [`from_iter_instead_of_collect`]
111+
[#6304](https://github.com/rust-lang/rust-clippy/pull/6304)
112+
* Fix a silent crash when parsing doc comments in [`needless_doctest_main`]
113+
[#6458](https://github.com/rust-lang/rust-clippy/pull/6458)
114+
115+
### Documentation Improvements
116+
117+
* The lint website search has been improved ([#6477](https://github.com/rust-lang/rust-clippy/pull/6477)):
118+
* Searching for lints with dashes and spaces is possible now. For example
119+
`missing-errors-doc` and `missing errors doc` are now valid aliases for lint names
120+
* Improved fuzzy search in lint descriptions
121+
* Various README improvements
122+
[#6287](https://github.com/rust-lang/rust-clippy/pull/6287)
123+
* Add known problems to [`comparison_chain`] documentation
124+
[#6390](https://github.com/rust-lang/rust-clippy/pull/6390)
125+
* Fix example used in [`cargo_common_metadata`]
126+
[#6293](https://github.com/rust-lang/rust-clippy/pull/6293)
127+
* Improve [`map_clone`] documentation
128+
[#6340](https://github.com/rust-lang/rust-clippy/pull/6340)
129+
130+
### Others
131+
132+
* You can now tell Clippy about the MSRV your project supports. Please refer to
133+
the specific README section to learn more about MSRV support [here][msrv_readme]
134+
[#6201](https://github.com/rust-lang/rust-clippy/pull/6201)
135+
* Add `--no-deps` option to avoid running on path dependencies in workspaces
136+
[#6188](https://github.com/rust-lang/rust-clippy/pull/6188)
10137

11138
## Rust 1.49
12139

13-
Current beta, release 2020-12-31
140+
Current stable, released 2020-12-31
14141

15142
[e636b88...b20d4c1](https://github.com/rust-lang/rust-clippy/compare/e636b88...b20d4c1)
16143

@@ -116,7 +243,7 @@ Current beta, release 2020-12-31
116243

117244
## Rust 1.48
118245

119-
Current stable, released 2020-11-19
246+
Released 2020-11-19
120247

121248
[09bd400...e636b88](https://github.com/rust-lang/rust-clippy/compare/09bd400...e636b88)
122249

@@ -1769,6 +1896,7 @@ Released 2018-09-13
17691896
[`cmp_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_null
17701897
[`cmp_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned
17711898
[`cognitive_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity
1899+
[`collapsible_else_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if
17721900
[`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
17731901
[`collapsible_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match
17741902
[`comparison_chain`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain
@@ -1973,6 +2101,7 @@ Released 2018-09-13
19732101
[`needless_doctest_main`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_doctest_main
19742102
[`needless_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
19752103
[`needless_pass_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value
2104+
[`needless_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
19762105
[`needless_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop
19772106
[`needless_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
19782107
[`needless_update`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_update
@@ -2012,6 +2141,7 @@ Released 2018-09-13
20122141
[`print_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_with_newline
20132142
[`println_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#println_empty_string
20142143
[`ptr_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
2144+
[`ptr_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr
20152145
[`ptr_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_eq
20162146
[`ptr_offset_with_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast
20172147
[`pub_enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_enum_variant_names
@@ -2152,6 +2282,7 @@ Released 2018-09-13
21522282
[`useless_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_transmute
21532283
[`useless_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec
21542284
[`vec_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_box
2285+
[`vec_init_then_push`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_init_then_push
21552286
[`vec_resize_to_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_resize_to_zero
21562287
[`verbose_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_bit_mask
21572288
[`verbose_file_reads`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_file_reads

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

+35-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::env;
55
use std::ffi::OsStr;
66
use std::fs;
77
use std::lazy::SyncLazy;
8-
use std::path::PathBuf;
8+
use std::path::{Path, PathBuf};
99
use walkdir::WalkDir;
1010

1111
use crate::clippy_project_root;
@@ -16,27 +16,41 @@ pub static CARGO_TARGET_DIR: SyncLazy<PathBuf> = SyncLazy::new(|| match env::var
1616
None => env::current_dir().unwrap().join("target"),
1717
});
1818

19-
pub fn bless() {
20-
let test_dirs = [
19+
static CLIPPY_BUILD_TIME: SyncLazy<Option<std::time::SystemTime>> = SyncLazy::new(|| {
20+
let profile = env::var("PROFILE").unwrap_or_else(|_| "debug".to_string());
21+
let mut path = PathBuf::from(&**CARGO_TARGET_DIR);
22+
path.push(profile);
23+
path.push("cargo-clippy");
24+
fs::metadata(path).ok()?.modified().ok()
25+
});
26+
27+
pub fn bless(ignore_timestamp: bool) {
28+
let test_suite_dirs = [
2129
clippy_project_root().join("tests").join("ui"),
30+
clippy_project_root().join("tests").join("ui-internal"),
2231
clippy_project_root().join("tests").join("ui-toml"),
2332
clippy_project_root().join("tests").join("ui-cargo"),
2433
];
25-
for test_dir in &test_dirs {
26-
WalkDir::new(test_dir)
34+
for test_suite_dir in &test_suite_dirs {
35+
WalkDir::new(test_suite_dir)
2736
.into_iter()
2837
.filter_map(Result::ok)
2938
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
3039
.for_each(|f| {
31-
update_reference_file(f.path().with_extension("stdout"));
32-
update_reference_file(f.path().with_extension("stderr"));
33-
update_reference_file(f.path().with_extension("fixed"));
40+
let test_name = f.path().strip_prefix(test_suite_dir).unwrap();
41+
for &ext in &["stdout", "stderr", "fixed"] {
42+
update_reference_file(
43+
f.path().with_extension(ext),
44+
test_name.with_extension(ext),
45+
ignore_timestamp,
46+
);
47+
}
3448
});
3549
}
3650
}
3751

38-
fn update_reference_file(reference_file_path: PathBuf) {
39-
let test_output_path = build_dir().join(PathBuf::from(reference_file_path.file_name().unwrap()));
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);
4054
let relative_reference_file_path = reference_file_path.strip_prefix(clippy_project_root()).unwrap();
4155

4256
// If compiletest did not write any changes during the test run,
@@ -45,6 +59,11 @@ fn update_reference_file(reference_file_path: PathBuf) {
4559
return;
4660
}
4761

62+
// 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) {
64+
return;
65+
}
66+
4867
let test_output_file = fs::read(&test_output_path).expect("Unable to read test output file");
4968
let reference_file = fs::read(&reference_file_path).unwrap_or_default();
5069

@@ -64,6 +83,12 @@ fn update_reference_file(reference_file_path: PathBuf) {
6483
}
6584
}
6685

86+
fn updated_since_clippy_build(path: &Path) -> Option<bool> {
87+
let clippy_build_time = (*CLIPPY_BUILD_TIME)?;
88+
let modified = fs::metadata(path).ok()?.modified().ok()?;
89+
Some(modified >= clippy_build_time)
90+
}
91+
6792
fn build_dir() -> PathBuf {
6893
let profile = env::var("PROFILE").unwrap_or_else(|_| "debug".to_string());
6994
let mut path = PathBuf::new();

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ fn main() {
77
let matches = get_clap_config();
88

99
match matches.subcommand() {
10-
("bless", Some(_)) => {
11-
bless::bless();
10+
("bless", Some(matches)) => {
11+
bless::bless(matches.is_present("ignore-timestamp"));
1212
},
1313
("fmt", Some(matches)) => {
1414
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
@@ -47,7 +47,15 @@ fn main() {
4747

4848
fn get_clap_config<'a>() -> ArgMatches<'a> {
4949
App::new("Clippy developer tooling")
50-
.subcommand(SubCommand::with_name("bless").about("bless the test output changes"))
50+
.subcommand(
51+
SubCommand::with_name("bless")
52+
.about("bless the test output changes")
53+
.arg(
54+
Arg::with_name("ignore-timestamp")
55+
.long("ignore-timestamp")
56+
.help("Include files updated before clippy was built"),
57+
),
58+
)
5159
.subcommand(
5260
SubCommand::with_name("fmt")
5361
.about("Run rustfmt on all projects and tests")

src/tools/clippy/clippy_lints/src/attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
370370
if let Some(meta_item) = lint.meta_item();
371371
if meta_item.path.segments.len() > 1;
372372
if let tool_name = meta_item.path.segments[0].ident;
373-
if tool_name.as_str() == "clippy";
373+
if tool_name.name == sym::clippy;
374374
let lint_name = meta_item.path.segments.last().unwrap().ident.name;
375375
then {
376376
return Some(lint_name.as_str());

src/tools/clippy/clippy_lints/src/collapsible_if.rs

+30-14
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ use rustc_errors::Applicability;
2323

2424
declare_clippy_lint! {
2525
/// **What it does:** Checks for nested `if` statements which can be collapsed
26-
/// by `&&`-combining their conditions and for `else { if ... }` expressions
27-
/// that
28-
/// can be collapsed to `else if ...`.
26+
/// by `&&`-combining their conditions.
2927
///
3028
/// **Why is this bad?** Each `if`-statement adds one level of nesting, which
3129
/// makes code look more complex than it really is.
@@ -40,7 +38,31 @@ declare_clippy_lint! {
4038
/// }
4139
/// }
4240
///
43-
/// // or
41+
/// ```
42+
///
43+
/// Should be written:
44+
///
45+
/// ```rust.ignore
46+
/// if x && y {
47+
/// …
48+
/// }
49+
/// ```
50+
pub COLLAPSIBLE_IF,
51+
style,
52+
"nested `if`s that can be collapsed (e.g., `if x { if y { ... } }`"
53+
}
54+
55+
declare_clippy_lint! {
56+
/// **What it does:** Checks for collapsible `else { if ... }` expressions
57+
/// that can be collapsed to `else if ...`.
58+
///
59+
/// **Why is this bad?** Each `if`-statement adds one level of nesting, which
60+
/// makes code look more complex than it really is.
61+
///
62+
/// **Known problems:** None.
63+
///
64+
/// **Example:**
65+
/// ```rust,ignore
4466
///
4567
/// if x {
4668
/// …
@@ -54,24 +76,18 @@ declare_clippy_lint! {
5476
/// Should be written:
5577
///
5678
/// ```rust.ignore
57-
/// if x && y {
58-
/// …
59-
/// }
60-
///
61-
/// // or
62-
///
6379
/// if x {
6480
/// …
6581
/// } else if y {
6682
/// …
6783
/// }
6884
/// ```
69-
pub COLLAPSIBLE_IF,
85+
pub COLLAPSIBLE_ELSE_IF,
7086
style,
71-
"`if`s that can be collapsed (e.g., `if x { if y { ... } }` and `else { if x { ... } }`)"
87+
"nested `else`-`if` expressions that can be collapsed (e.g., `else { if x { ... } }`)"
7288
}
7389

74-
declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF]);
90+
declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF, COLLAPSIBLE_ELSE_IF]);
7591

7692
impl EarlyLintPass for CollapsibleIf {
7793
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
@@ -112,7 +128,7 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
112128
let mut applicability = Applicability::MachineApplicable;
113129
span_lint_and_sugg(
114130
cx,
115-
COLLAPSIBLE_IF,
131+
COLLAPSIBLE_ELSE_IF,
116132
block.span,
117133
"this `else { if .. }` block can be collapsed",
118134
"collapse nested if block",

src/tools/clippy/clippy_lints/src/comparison_chain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ declare_clippy_lint! {
1313
/// repetitive
1414
///
1515
/// **Known problems:** The match statement may be slower due to the compiler
16-
/// not inlining the call to cmp. See issue #5354
16+
/// not inlining the call to cmp. See issue [#5354](https://github.com/rust-lang/rust-clippy/issues/5354)
1717
///
1818
/// **Example:**
1919
/// ```rust,ignore

0 commit comments

Comments
 (0)