Skip to content

Commit 31be8cc

Browse files
committed
Auto merge of #116489 - flip1995:clippyup, r=Manishearth
Clippy subtree sync r? `@Manishearth`
2 parents 64fa0c3 + 6233d44 commit 31be8cc

File tree

109 files changed

+2665
-772
lines changed

Some content is hidden

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

109 files changed

+2665
-772
lines changed

Cargo.lock

+28-4
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,12 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
508508

509509
[[package]]
510510
name = "clippy"
511-
version = "0.1.74"
511+
version = "0.1.75"
512512
dependencies = [
513+
"anstream",
513514
"clippy_lints",
514515
"clippy_utils",
516+
"color-print",
515517
"filetime",
516518
"futures",
517519
"if_chain",
@@ -546,7 +548,7 @@ dependencies = [
546548

547549
[[package]]
548550
name = "clippy_lints"
549-
version = "0.1.74"
551+
version = "0.1.75"
550552
dependencies = [
551553
"arrayvec",
552554
"cargo_metadata",
@@ -566,11 +568,12 @@ dependencies = [
566568
"unicode-normalization",
567569
"unicode-script",
568570
"url",
571+
"walkdir",
569572
]
570573

571574
[[package]]
572575
name = "clippy_utils"
573-
version = "0.1.74"
576+
version = "0.1.75"
574577
dependencies = [
575578
"arrayvec",
576579
"if_chain",
@@ -603,6 +606,27 @@ dependencies = [
603606
"tracing-error",
604607
]
605608

609+
[[package]]
610+
name = "color-print"
611+
version = "0.3.5"
612+
source = "registry+https://github.com/rust-lang/crates.io-index"
613+
checksum = "7a858372ff14bab9b1b30ea504f2a4bc534582aee3e42ba2d41d2a7baba63d5d"
614+
dependencies = [
615+
"color-print-proc-macro",
616+
]
617+
618+
[[package]]
619+
name = "color-print-proc-macro"
620+
version = "0.3.5"
621+
source = "registry+https://github.com/rust-lang/crates.io-index"
622+
checksum = "57e37866456a721d0a404439a1adae37a31be4e0055590d053dfe6981e05003f"
623+
dependencies = [
624+
"nom",
625+
"proc-macro2",
626+
"quote",
627+
"syn 1.0.109",
628+
]
629+
606630
[[package]]
607631
name = "color-spantrace"
608632
version = "0.2.0"
@@ -933,7 +957,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
933957

934958
[[package]]
935959
name = "declare_clippy_lint"
936-
version = "0.1.74"
960+
version = "0.1.75"
937961
dependencies = [
938962
"itertools",
939963
"quote",

src/tools/clippy/CHANGELOG.md

+95-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,101 @@ document.
66

77
## Unreleased / Beta / In Rust Nightly
88

9-
[37f4c172...master](https://github.com/rust-lang/rust-clippy/compare/37f4c172...master)
9+
[1e8fdf49...master](https://github.com/rust-lang/rust-clippy/compare/1e8fdf49...master)
10+
11+
## Rust 1.73
12+
13+
Current stable, released 2023-10-05
14+
15+
[View all 103 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-07-02T12%3A24%3A40Z..2023-08-11T11%3A09%3A56Z+base%3Amaster)
16+
17+
### New Lints
18+
19+
* [`impossible_comparisons`]
20+
[#10843](https://github.com/rust-lang/rust-clippy/pull/10843)
21+
* [`redundant_comparisons`]
22+
[#10843](https://github.com/rust-lang/rust-clippy/pull/10843)
23+
* [`ignored_unit_patterns`]
24+
[#11242](https://github.com/rust-lang/rust-clippy/pull/11242)
25+
* [`readonly_write_lock`]
26+
[#11210](https://github.com/rust-lang/rust-clippy/pull/11210)
27+
* [`filter_map_bool_then`]
28+
[#11115](https://github.com/rust-lang/rust-clippy/pull/11115)
29+
* [`needless_return_with_question_mark`]
30+
[#11031](https://github.com/rust-lang/rust-clippy/pull/11031)
31+
* [`redundant_guards`]
32+
[#10955](https://github.com/rust-lang/rust-clippy/pull/10955)
33+
* [`redundant_locals`]
34+
[#10885](https://github.com/rust-lang/rust-clippy/pull/10885)
35+
* [`absolute_paths`]
36+
[#11003](https://github.com/rust-lang/rust-clippy/pull/11003)
37+
* [`error_impl_error`]
38+
[#11107](https://github.com/rust-lang/rust-clippy/pull/11107)
39+
* [`iter_skip_zero`]
40+
[#11046](https://github.com/rust-lang/rust-clippy/pull/11046)
41+
* [`string_lit_chars_any`]
42+
[#11052](https://github.com/rust-lang/rust-clippy/pull/11052)
43+
* [`four_forward_slashes`]
44+
[#11140](https://github.com/rust-lang/rust-clippy/pull/11140)
45+
* [`format_collect`]
46+
[#11116](https://github.com/rust-lang/rust-clippy/pull/11116)
47+
* [`needless_pass_by_ref_mut`]
48+
[#10900](https://github.com/rust-lang/rust-clippy/pull/10900)
49+
* [`manual_is_infinite`]
50+
[#11049](https://github.com/rust-lang/rust-clippy/pull/11049)
51+
* [`manual_is_finite`]
52+
[#11049](https://github.com/rust-lang/rust-clippy/pull/11049)
53+
* [`incorrect_partial_ord_impl_on_ord_type`]
54+
[#10788](https://github.com/rust-lang/rust-clippy/pull/10788)
55+
* [`read_line_without_trim`]
56+
[#10970](https://github.com/rust-lang/rust-clippy/pull/10970)
57+
* [`type_id_on_box`]
58+
[#10987](https://github.com/rust-lang/rust-clippy/pull/10987)
59+
60+
### Moves and Deprecations
61+
62+
* Renamed `unwrap_or_else_default` to [`unwrap_or_default`]
63+
[#10120](https://github.com/rust-lang/rust-clippy/pull/10120)
64+
* Moved [`tuple_array_conversions`] to `pedantic` (Now allow-by-default)
65+
[#11146](https://github.com/rust-lang/rust-clippy/pull/11146)
66+
* Moved [`arc_with_non_send_sync`] to `suspicious` (Now warn-by-default)
67+
[#11104](https://github.com/rust-lang/rust-clippy/pull/11104)
68+
* Moved [`needless_raw_string_hashes`] to `pedantic` (Now allow-by-default)
69+
[#11415](https://github.com/rust-lang/rust-clippy/pull/11415)
70+
71+
### Enhancements
72+
73+
* [`unwrap_used`]: No longer lints on the never-type or never-like enums
74+
[#11252](https://github.com/rust-lang/rust-clippy/pull/11252)
75+
* [`expect_used`]: No longer lints on the never-type or never-like enums
76+
[#11252](https://github.com/rust-lang/rust-clippy/pull/11252)
77+
78+
### False Positive Fixes
79+
80+
* [`panic_in_result_fn`]: No longer triggers on `todo!`, `unimplemented!`, `unreachable!`
81+
[#11123](https://github.com/rust-lang/rust-clippy/pull/11123)
82+
83+
### Suggestion Fixes/Improvements
84+
85+
* [`semicolon_if_nothing_returned`]: The suggestion is now machine-applicable with rustfix
86+
[#11083](https://github.com/rust-lang/rust-clippy/pull/11083)
87+
88+
### ICE Fixes
89+
90+
* [`filter_map_bool_then`]: No longer crashes on late-bound regions
91+
[#11318](https://github.com/rust-lang/rust-clippy/pull/11318)
92+
* [`unwrap_or_default`]: No longer crashes on alias types for local items
93+
[#11258](https://github.com/rust-lang/rust-clippy/pull/11258)
94+
* [`unnecessary_literal_unwrap`]: No longer crashes on `None.unwrap_or_default()`
95+
[#11106](https://github.com/rust-lang/rust-clippy/pull/11106)
96+
* Fixed MIR-related ICE
97+
[#11130](https://github.com/rust-lang/rust-clippy/pull/11130)
98+
* [`missing_fields_in_debug`]: No longer crashes on non-ADT self types
99+
[#11069](https://github.com/rust-lang/rust-clippy/pull/11069)
10100

11101
## Rust 1.72
12102

13-
Current stable, released 2023-08-24
103+
Released 2023-08-24
14104

15105
[View all 131 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-05-22T14%3A53%3A59Z..2023-07-01T22%3A57%3A20Z+base%3Amaster)
16106

@@ -5011,6 +5101,7 @@ Released 2018-09-13
50115101
[`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division
50125102
[`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array
50135103
[`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref
5104+
[`into_iter_without_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_without_iter
50145105
[`invalid_atomic_ordering`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering
50155106
[`invalid_null_ptr_usage`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_null_ptr_usage
50165107
[`invalid_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_ref
@@ -5036,6 +5127,7 @@ Released 2018-09-13
50365127
[`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next
50375128
[`iter_skip_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_zero
50385129
[`iter_with_drain`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_with_drain
5130+
[`iter_without_into_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_without_into_iter
50395131
[`iterator_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iterator_step_by_zero
50405132
[`just_underscores_and_digits`]: https://rust-lang.github.io/rust-clippy/master/index.html#just_underscores_and_digits
50415133
[`large_const_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_const_arrays
@@ -5072,6 +5164,7 @@ Released 2018-09-13
50725164
[`manual_find`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find
50735165
[`manual_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find_map
50745166
[`manual_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_flatten
5167+
[`manual_hash_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_hash_one
50755168
[`manual_instant_elapsed`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_instant_elapsed
50765169
[`manual_is_ascii_check`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check
50775170
[`manual_is_finite`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_finite

src/tools/clippy/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.74"
3+
version = "0.1.75"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"
@@ -25,6 +25,8 @@ clippy_lints = { path = "clippy_lints" }
2525
rustc_tools_util = "0.3.0"
2626
tempfile = { version = "3.2", optional = true }
2727
termize = "0.1"
28+
color-print = "0.3.4" # Sync version with Cargo
29+
anstream = "0.5.0"
2830

2931
[dev-dependencies]
3032
ui_test = "0.20"

src/tools/clippy/book/src/development/adding_lints.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl EarlyLintPass for FooFunctions {}
261261
[declare_clippy_lint]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/lib.rs#L60
262262
[example_lint_page]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
263263
[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
264-
[category_level_mapping]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/lib.rs#L110
264+
[category_level_mapping]: ../index.html
265265

266266
## Lint registration
267267

src/tools/clippy/book/src/lint_configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ The minimum rust version that the project supports
151151
* [`type_repetition_in_bounds`](https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds)
152152
* [`tuple_array_conversions`](https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions)
153153
* [`manual_try_fold`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold)
154+
* [`manual_hash_one`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_hash_one)
154155

155156

156157
## `cognitive-complexity-threshold`

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

+51-12
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn create(
5858
};
5959

6060
create_lint(&lint, msrv).context("Unable to create lint implementation")?;
61-
create_test(&lint).context("Unable to create a test for the new lint")?;
61+
create_test(&lint, msrv).context("Unable to create a test for the new lint")?;
6262

6363
if lint.ty.is_none() {
6464
add_lint(&lint, msrv).context("Unable to add lint to clippy_lints/src/lib.rs")?;
@@ -88,15 +88,21 @@ fn create_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
8888
}
8989
}
9090

91-
fn create_test(lint: &LintData<'_>) -> io::Result<()> {
92-
fn create_project_layout<P: Into<PathBuf>>(lint_name: &str, location: P, case: &str, hint: &str) -> io::Result<()> {
91+
fn create_test(lint: &LintData<'_>, msrv: bool) -> io::Result<()> {
92+
fn create_project_layout<P: Into<PathBuf>>(
93+
lint_name: &str,
94+
location: P,
95+
case: &str,
96+
hint: &str,
97+
msrv: bool,
98+
) -> io::Result<()> {
9399
let mut path = location.into().join(case);
94100
fs::create_dir(&path)?;
95101
write_file(path.join("Cargo.toml"), get_manifest_contents(lint_name, hint))?;
96102

97103
path.push("src");
98104
fs::create_dir(&path)?;
99-
write_file(path.join("main.rs"), get_test_file_contents(lint_name))?;
105+
write_file(path.join("main.rs"), get_test_file_contents(lint_name, msrv))?;
100106

101107
Ok(())
102108
}
@@ -106,13 +112,25 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
106112
let test_dir = lint.project_root.join(&relative_test_dir);
107113
fs::create_dir(&test_dir)?;
108114

109-
create_project_layout(lint.name, &test_dir, "fail", "Content that triggers the lint goes here")?;
110-
create_project_layout(lint.name, &test_dir, "pass", "This file should not trigger the lint")?;
115+
create_project_layout(
116+
lint.name,
117+
&test_dir,
118+
"fail",
119+
"Content that triggers the lint goes here",
120+
msrv,
121+
)?;
122+
create_project_layout(
123+
lint.name,
124+
&test_dir,
125+
"pass",
126+
"This file should not trigger the lint",
127+
false,
128+
)?;
111129

112130
println!("Generated test directories: `{relative_test_dir}/pass`, `{relative_test_dir}/fail`");
113131
} else {
114132
let test_path = format!("tests/ui/{}.rs", lint.name);
115-
let test_contents = get_test_file_contents(lint.name);
133+
let test_contents = get_test_file_contents(lint.name, msrv);
116134
write_file(lint.project_root.join(&test_path), test_contents)?;
117135

118136
println!("Generated test file: `{test_path}`");
@@ -194,16 +212,38 @@ pub(crate) fn get_stabilization_version() -> String {
194212
parse_manifest(&contents).expect("Unable to find package version in `Cargo.toml`")
195213
}
196214

197-
fn get_test_file_contents(lint_name: &str) -> String {
198-
formatdoc!(
215+
fn get_test_file_contents(lint_name: &str, msrv: bool) -> String {
216+
let mut test = formatdoc!(
199217
r#"
200218
#![warn(clippy::{lint_name})]
201219
202220
fn main() {{
203221
// test code goes here
204222
}}
205223
"#
206-
)
224+
);
225+
226+
if msrv {
227+
let _ = writedoc!(
228+
test,
229+
r#"
230+
231+
// TODO: set xx to the version one below the MSRV used by the lint, and yy to
232+
// the version used by the lint
233+
#[clippy::msrv = "1.xx"]
234+
fn msrv_1_xx() {{
235+
// a simple example that would trigger the lint if the MSRV were met
236+
}}
237+
238+
#[clippy::msrv = "1.yy"]
239+
fn msrv_1_yy() {{
240+
// the same example as above
241+
}}
242+
"#
243+
);
244+
}
245+
246+
test
207247
}
208248

209249
fn get_manifest_contents(lint_name: &str, hint: &str) -> String {
@@ -258,7 +298,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
258298
)
259299
});
260300

261-
let _: fmt::Result = write!(result, "{}", get_lint_declaration(&name_upper, category));
301+
let _: fmt::Result = writeln!(result, "{}", get_lint_declaration(&name_upper, category));
262302

263303
result.push_str(&if enable_msrv {
264304
formatdoc!(
@@ -281,7 +321,6 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
281321
}}
282322
283323
// TODO: Add MSRV level to `clippy_utils/src/msrvs.rs` if needed.
284-
// TODO: Add MSRV test to `tests/ui/min_rust_version_attr.rs`.
285324
// TODO: Update msrv config comment in `clippy_lints/src/utils/conf.rs`
286325
"#
287326
)

src/tools/clippy/clippy_lints/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.74"
3+
version = "0.1.75"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"
@@ -28,6 +28,9 @@ semver = "1.0"
2828
rustc-semver = "1.1"
2929
url = "2.2"
3030

31+
[dev-dependencies]
32+
walkdir = "2.3"
33+
3134
[features]
3235
deny-warnings = ["clippy_utils/deny-warnings"]
3336
# build clippy with internal lints enabled, off by default

src/tools/clippy/clippy_lints/src/allow_attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_middle::lint::in_external_macro;
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99

1010
declare_clippy_lint! {
11+
/// ### What it does
1112
/// Checks for usage of the `#[allow]` attribute and suggests replacing it with
1213
/// the `#[expect]` (See [RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html))
1314
///
@@ -19,7 +20,6 @@ declare_clippy_lint! {
1920
/// (`#![allow]`) are usually used to enable or disable lints on a global scale.
2021
///
2122
/// ### Why is this bad?
22-
///
2323
/// `#[expect]` attributes suppress the lint emission, but emit a warning, if
2424
/// the expectation is unfulfilled. This can be useful to be notified when the
2525
/// lint is no longer triggered.

0 commit comments

Comments
 (0)