Skip to content

Commit f5559e3

Browse files
committed
Auto merge of #110718 - flip1995:clippyup, r=Manishearth
Update Clippy r? `@Manishearth` A few days late, I was on a business trip, sorry.
2 parents 521de43 + bb63b59 commit f5559e3

File tree

784 files changed

+2308
-1405
lines changed

Some content is hidden

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

784 files changed

+2308
-1405
lines changed

Cargo.lock

+4-5
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,8 @@ dependencies = [
593593
"rustc-semver",
594594
"rustc-workspace-hack",
595595
"rustc_tools_util",
596-
"semver",
597596
"serde",
598-
"syn 1.0.102",
597+
"syn 2.0.8",
599598
"tempfile",
600599
"termize",
601600
"tester",
@@ -746,9 +745,9 @@ dependencies = [
746745

747746
[[package]]
748747
name = "compiletest_rs"
749-
version = "0.9.0"
748+
version = "0.10.0"
750749
source = "registry+https://github.com/rust-lang/crates.io-index"
751-
checksum = "70489bbb718aea4f92e5f48f2e3b5be670c2051de30e57cb6e5377b4aa08b372"
750+
checksum = "e2731272cf25196735df1b52ab5bcba22cf9f99455626c4c8dc092bd5f7f66d0"
752751
dependencies = [
753752
"diff",
754753
"filetime",
@@ -973,7 +972,7 @@ version = "0.1.70"
973972
dependencies = [
974973
"itertools",
975974
"quote",
976-
"syn 1.0.102",
975+
"syn 2.0.8",
977976
]
978977

979978
[[package]]

src/tools/clippy/CHANGELOG.md

+118-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,126 @@ document.
66

77
## Unreleased / Beta / In Rust Nightly
88

9-
[7f27e2e7...master](https://github.com/rust-lang/rust-clippy/compare/7f27e2e7...master)
9+
[149392b0...master](https://github.com/rust-lang/rust-clippy/compare/149392b0...master)
10+
11+
## Rust 1.69
12+
13+
Current stable, released 2023-04-20
14+
15+
[7f27e2e7...149392b0](https://github.com/rust-lang/rust-clippy/compare/7f27e2e7...149392b0)
16+
17+
### New Lints
18+
19+
* [`no_mangle_with_rust_abi`]
20+
[#10369](https://github.com/rust-lang/rust-clippy/pull/10369)
21+
* [`significant_drop_tightening`]
22+
[#10163](https://github.com/rust-lang/rust-clippy/pull/10163)
23+
* [`suspicious_command_arg_space`]
24+
[#10317](https://github.com/rust-lang/rust-clippy/pull/10317)
25+
* [`let_underscore_untyped`]
26+
[#10356](https://github.com/rust-lang/rust-clippy/pull/10356)
27+
* [`question_mark_used`]
28+
[#10342](https://github.com/rust-lang/rust-clippy/pull/10342)
29+
* [`extra_unused_type_parameters`]
30+
[#10028](https://github.com/rust-lang/rust-clippy/pull/10028)
31+
* [`impl_trait_in_params`]
32+
[10197](https://github.com/rust-lang/rust-clippy/pull/10197)
33+
* [`transmute_int_to_non_zero`]
34+
[#10360](https://github.com/rust-lang/rust-clippy/pull/10360)
35+
* [`multiple_unsafe_ops_per_block`]
36+
[#10206](https://github.com/rust-lang/rust-clippy/pull/10206)
37+
38+
### Moves and Deprecations
39+
40+
* Moved [`uninlined_format_args`] to `pedantic` (Now allow-by-default)
41+
[#10265](https://github.com/rust-lang/rust-clippy/pull/10265)
42+
* Moved [`unchecked_duration_subtraction`] to `pedantic` (Now allow-by-default)
43+
[#10194](https://github.com/rust-lang/rust-clippy/pull/10194)
44+
45+
### Enhancements
46+
47+
* [`arithmetic_side_effects`]: No longer lints, if safe constant values are used.
48+
[#10310](https://github.com/rust-lang/rust-clippy/pull/10310)
49+
* [`needless_lifetimes`]: Now works in local macros
50+
[#10257](https://github.com/rust-lang/rust-clippy/pull/10257)
51+
* [`unused_io_amount`]: Now detects usages of `is_ok` and `is_err`
52+
[#10225](https://github.com/rust-lang/rust-clippy/pull/10225)
53+
* [`missing_docs_in_private_items`]: Added new configuration `missing-docs-in-crate-items` to lint
54+
on items visible within the current crate. For example, `pub(crate)` items.
55+
[#10303](https://github.com/rust-lang/rust-clippy/pull/10303)
56+
* [`almost_swapped`]: Now detects almost swaps using `let` statements
57+
[#10177](https://github.com/rust-lang/rust-clippy/pull/10177)
58+
* [`wildcard_enum_match_arm`]: Now lints missing private variants, for local enums
59+
[#10250](https://github.com/rust-lang/rust-clippy/pull/10250)
60+
61+
### False Positive Fixes
62+
63+
* [`explicit_auto_deref`]: Now considers projections, when determining if auto deref is applicable
64+
[#10386](https://github.com/rust-lang/rust-clippy/pull/10386)
65+
* [`manual_let_else`]: Now considers side effects of branches, before linting
66+
[#10336](https://github.com/rust-lang/rust-clippy/pull/10336)
67+
* [`uninlined_format_args`]: No longer lints for arguments with generic parameters
68+
[#10343](https://github.com/rust-lang/rust-clippy/pull/10343)
69+
* [`needless_lifetimes`]: No longer lints signatures in macros, if the lifetime is a metavariable
70+
[#10380](https://github.com/rust-lang/rust-clippy/pull/10380)
71+
* [`len_without_is_empty`]: No longer lints, if `len` as a non-default signature
72+
[#10255](https://github.com/rust-lang/rust-clippy/pull/10255)
73+
* [`unusual_byte_groupings`]: Relaxed the required restrictions for specific sizes, to reduce false
74+
positives
75+
[#10353](https://github.com/rust-lang/rust-clippy/pull/10353)
76+
* [`manual_let_else`]: No longer lints `if-else` blocks if they can divergent
77+
[#10332](https://github.com/rust-lang/rust-clippy/pull/10332)
78+
* [`expect_used`], [`unwrap_used`], [`dbg_macro`], [`print_stdout`], [`print_stderr`]: No longer lint
79+
in test functions, if `allow-expect-in-tests` is set
80+
[#10391](https://github.com/rust-lang/rust-clippy/pull/10391)
81+
* [`unnecessary_safety_comment`]: No longer lints code inside macros
82+
[#10106](https://github.com/rust-lang/rust-clippy/pull/10106)
83+
* [`never_loop`]: No longer lints, for statements following break statements for outer blocks.
84+
[#10311](https://github.com/rust-lang/rust-clippy/pull/10311)
85+
86+
### Suggestion Fixes/Improvements
87+
88+
* [`box_default`]: The suggestion now includes the type for trait objects, when needed
89+
[#10382](https://github.com/rust-lang/rust-clippy/pull/10382)
90+
* [`cast_possible_truncation`]: Now suggests using `try_from` or allowing the lint
91+
[#10038](https://github.com/rust-lang/rust-clippy/pull/10038)
92+
* [`invalid_regex`]: Regex errors for non-literals or regular strings containing escape sequences will
93+
now show the complete error
94+
[#10231](https://github.com/rust-lang/rust-clippy/pull/10231)
95+
* [`transmutes_expressible_as_ptr_casts`]: The suggestion now works, if the base type is borrowed
96+
[#10193](https://github.com/rust-lang/rust-clippy/pull/10193)
97+
* [`needless_return`]: Now removes all semicolons on the same line
98+
[#10187](https://github.com/rust-lang/rust-clippy/pull/10187)
99+
* [`suspicious_to_owned`]: The suggestion now shows all options clearly
100+
[#10295](https://github.com/rust-lang/rust-clippy/pull/10295)
101+
* [`bytes_nth`]: Now suggests the correct replacement based on the context
102+
[#10361](https://github.com/rust-lang/rust-clippy/pull/10361)
103+
* [`bool_assert_comparison`]: The suggestion is now machine applicable
104+
[#10218](https://github.com/rust-lang/rust-clippy/pull/10218)
105+
* [`cast_possible_truncation`]: Corrected the lint name in the help message
106+
[#10330](https://github.com/rust-lang/rust-clippy/pull/10330)
107+
* [`needless_return`]: The suggestion now works on if sequences
108+
[#10345](https://github.com/rust-lang/rust-clippy/pull/10345)
109+
* [`needless_lifetimes`]: The suggestion is now machine applicable
110+
[#10222](https://github.com/rust-lang/rust-clippy/pull/10222)
111+
* [`map_entry`]: The suggestion no longer expands macros
112+
[#10346](https://github.com/rust-lang/rust-clippy/pull/10346)
113+
114+
### ICE Fixes
115+
116+
* [`needless_pass_by_value`]: Fixed an ICE, caused by how late bounds were handled
117+
[#10328](https://github.com/rust-lang/rust-clippy/pull/10328)
118+
* [`needless_borrow`]: No longer panics on ambiguous projections
119+
[#10403](https://github.com/rust-lang/rust-clippy/pull/10403)
120+
121+
### Documentation Improvements
122+
123+
* All configurations are now documented in the Clippy Book
124+
[#10199](https://github.com/rust-lang/rust-clippy/pull/10199)
10125

11126
## Rust 1.68
12127

13-
Current stable, released 2023-03-09
128+
Released 2023-03-09
14129

15130
[d822110d...7f27e2e7](https://github.com/rust-lang/rust-clippy/compare/d822110d...7f27e2e7)
16131

@@ -4615,6 +4730,7 @@ Released 2018-09-13
46154730
[`invisible_characters`]: https://rust-lang.github.io/rust-clippy/master/index.html#invisible_characters
46164731
[`is_digit_ascii_radix`]: https://rust-lang.github.io/rust-clippy/master/index.html#is_digit_ascii_radix
46174732
[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
4733+
[`items_after_test_module`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module
46184734
[`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect
46194735
[`iter_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_count
46204736
[`iter_kv_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_kv_map

src/tools/clippy/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ path = "src/driver.rs"
2222

2323
[dependencies]
2424
clippy_lints = { path = "clippy_lints" }
25-
semver = "1.0"
2625
rustc_tools_util = "0.3.0"
2726
tempfile = { version = "3.2", optional = true }
2827
termize = "0.1"
2928

3029
[dev-dependencies]
31-
compiletest_rs = { version = "0.9", features = ["tmp"] }
30+
compiletest_rs = { version = "0.10", features = ["tmp"] }
3231
tester = "0.9"
3332
regex = "1.5"
3433
toml = "0.5"
@@ -49,7 +48,7 @@ if_chain = "1.0"
4948
itertools = "0.10.1"
5049
quote = "1.0"
5150
serde = { version = "1.0.125", features = ["derive"] }
52-
syn = { version = "1.0", features = ["full"] }
51+
syn = { version = "2.0", features = ["full"] }
5352
futures = "0.3"
5453
parking_lot = "0.12"
5554
tokio = { version = "1", features = ["io-util"] }

src/tools/clippy/book/src/SUMMARY.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
- [Development](development/README.md)
1414
- [Basics](development/basics.md)
1515
- [Adding Lints](development/adding_lints.md)
16+
- [Lint Passes](development/lint_passes.md)
1617
- [Type Checking](development/type_checking.md)
18+
- [Macro Expansions](development/macro_expansions.md)
1719
- [Common Tools](development/common_tools_writing_lints.md)
1820
- [Infrastructure](development/infrastructure/README.md)
1921
- [Syncing changes between Clippy and rust-lang/rust](development/infrastructure/sync.md)

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

+22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ If this is your first time contributing to Clippy, you should first read the
1313
[Basics docs](basics.md). This will explain the basics on how to get the source
1414
code and how to compile and test the code.
1515

16+
## Additional Readings for Beginners
17+
18+
If a dear reader of this documentation has never taken a class on compilers
19+
and interpreters, it might be confusing as to why AST level deals with only
20+
the language's syntax. And some readers might not even understand what lexing,
21+
parsing, and AST mean.
22+
23+
This documentation serves by no means as a crash course on compilers or language design.
24+
And for details specifically related to Rust, the [Rustc Development Guide][rustc_dev_guide]
25+
is a far better choice to peruse.
26+
27+
The [Syntax and AST][ast] chapter and the [High-Level IR][hir] chapter are
28+
great introduction to the concepts mentioned in this chapter.
29+
30+
Some readers might also find the [introductory chapter][map_of_territory] of
31+
Robert Nystrom's _Crafting Interpreters_ a helpful overview of compiled and
32+
interpreted languages before jumping back to the Rustc guide.
33+
1634
## Writing code
1735

1836
If you have done the basic setup, it's time to start hacking.
@@ -37,6 +55,10 @@ book](../lints.md).
3755
> - Triage procedure
3856
> - Bors and Homu
3957
58+
[ast]: https://rustc-dev-guide.rust-lang.org/syntax-intro.html
59+
[hir]: https://rustc-dev-guide.rust-lang.org/hir.html
60+
[rustc_dev_guide]: https://rustc-dev-guide.rust-lang.org/
61+
[map_of_territory]: https://craftinginterpreters.com/a-map-of-the-territory.html
4062
[clippy_rfc]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md
4163
[rfc_stability]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees
4264
[rfc_lint_cats]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ The process of generating the `.stderr` file is the same, and prepending the
164164
## Rustfix tests
165165

166166
If the lint you are working on is making use of structured suggestions, the test
167-
file should include a `// run-rustfix` comment at the top. This will
167+
file should include a `//@run-rustfix` comment at the top. This will
168168
additionally run [rustfix] for that test. Rustfix will apply the suggestions
169169
from the lint to the code of the test file and compare that to the contents of a
170170
`.fixed` file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Lint passes
2+
3+
Before working on the logic of a new lint, there is an important decision
4+
that every Clippy developer must make: to use
5+
[`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass].
6+
7+
In short, the `LateLintPass` has access to type and symbol information while the
8+
`EarlyLintPass` doesn't. If you don't need access to type information, use the
9+
`EarlyLintPass`.
10+
11+
Let us expand on these two traits more below.
12+
13+
## `EarlyLintPass`
14+
15+
If you examine the documentation on [`EarlyLintPass`][early_lint_pass] closely,
16+
you'll see that every method defined for this trait utilizes a
17+
[`EarlyContext`][early_context]. In `EarlyContext`'s documentation, it states:
18+
19+
> Context for lint checking of the AST, after expansion, before lowering to HIR.
20+
21+
Voilà. `EarlyLintPass` works only on the Abstract Syntax Tree (AST) level.
22+
And AST is generated during the [lexing and parsing][lexing_and_parsing] phase
23+
of code compilation. Therefore, it doesn't know what a symbol means or information about types, and it should
24+
be our trait choice for a new lint if the lint only deals with syntax-related issues.
25+
26+
While linting speed has not been a concern for Clippy,
27+
the `EarlyLintPass` is faster, and it should be your choice
28+
if you know for sure a lint does not need type information.
29+
30+
As a reminder, run the following command to generate boilerplate for lints
31+
that use `EarlyLintPass`:
32+
33+
```sh
34+
$ cargo dev new_lint --name=<your_new_lint> --pass=early --category=<your_category_choice>
35+
```
36+
37+
### Example for `EarlyLintPass`
38+
39+
Take a look at the following code:
40+
41+
```rust
42+
let x = OurUndefinedType;
43+
x.non_existing_method();
44+
```
45+
46+
From the AST perspective, both lines are "grammatically" correct.
47+
The assignment uses a `let` and ends with a semicolon. The invocation
48+
of a method looks fine, too. As programmers, we might raise a few
49+
questions already, but the parser is okay with it. This is what we
50+
mean when we say `EarlyLintPass` deals with only syntax on the AST level.
51+
52+
Alternatively, think of the `foo_functions` lint we mentioned in
53+
define new lints chapter.
54+
55+
We want the `foo_functions` lint to detect functions with `foo` as their name.
56+
Writing a lint that only checks for the name of a function means that we only
57+
work with the AST and don't have to access the type system at all (the type system is where
58+
`LateLintPass` comes into the picture).
59+
60+
## `LateLintPass`
61+
62+
In contrast to `EarlyLintPass`, `LateLintPass` contains type information.
63+
64+
If you examine the documentation on [`LateLintPass`][late_lint_pass] closely,
65+
you see that every method defined in this trait utilizes a
66+
[`LateContext`][late_context].
67+
68+
In `LateContext`'s documentation we will find methods that
69+
deal with type-checking, which do not exist in `EarlyContext`, such as:
70+
71+
- [`maybe_typeck_results`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html#method.maybe_typeck_results)
72+
- [`typeck_results`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html#method.typeck_results)
73+
74+
### Example for `LateLintPass`
75+
76+
Let us take a look with the following example:
77+
78+
```rust
79+
let x = OurUndefinedType;
80+
x.non_existing_method();
81+
```
82+
83+
These two lines of code are syntactically correct code from the perspective
84+
of the AST. We have an assignment and invoke a method on the variable that
85+
is of a type. Grammatically, everything is in order for the parser.
86+
87+
However, going down a level and looking at the type information,
88+
the compiler will notice that both `OurUndefinedType` and `non_existing_method()`
89+
**are undefined**.
90+
91+
As Clippy developers, to access such type information, we must implement
92+
`LateLintPass` on our lint.
93+
When you browse through Clippy's lints, you will notice that almost every lint
94+
is implemented in a `LateLintPass`, specifically because we often need to check
95+
not only for syntactic issues but also type information.
96+
97+
Another limitation of the `EarlyLintPass` is that the nodes are only identified
98+
by their position in the AST. This means that you can't just get an `id` and
99+
request a certain node. For most lints that is fine, but we have some lints
100+
that require the inspection of other nodes, which is easier at the HIR level.
101+
In these cases, `LateLintPass` is the better choice.
102+
103+
As a reminder, run the following command to generate boilerplate for lints
104+
that use `LateLintPass`:
105+
106+
```sh
107+
$ cargo dev new_lint --name=<your_new_lint> --pass=late --category=<your_category_choice>
108+
```
109+
110+
[early_context]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.EarlyContext.html
111+
[early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html
112+
[late_context]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html
113+
[late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html
114+
[lexing_and_parsing]: https://rustc-dev-guide.rust-lang.org/overview.html#lexing-and-parsing

0 commit comments

Comments
 (0)