Skip to content

Commit af02b43

Browse files
committed
Auto merge of rust-lang#115183 - flip1995:clippyup, r=Manishearth,oli-obk
Update Clippy r? `@oli-obk` Assigning you, because something broke with ui_test: ``` tests/ui/crashes/ice-7272.rs FAILED: command: "<unknown>" A bug in `ui_test` occurred: called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" } full stderr: ``` (and that 103 times) Thought I would ping you, before starting to investigate. Maybe you know what's going on.
2 parents 70f6321 + 6a876f2 commit af02b43

File tree

1,885 files changed

+16423
-9600
lines changed

Some content is hidden

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

1,885 files changed

+16423
-9600
lines changed

CHANGELOG.md

+99-8
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,105 @@ document.
66

77
## Unreleased / Beta / In Rust Nightly
88

9-
[435a8ad8...master](https://github.com/rust-lang/rust-clippy/compare/435a8ad8...master)
9+
[37f4c172...master](https://github.com/rust-lang/rust-clippy/compare/37f4c172...master)
1010

11-
## Rust 1.71
11+
## Rust 1.72
12+
13+
Current stable, released 2023-08-24
14+
15+
[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)
16+
17+
### New Lints
18+
19+
* [`manual_try_fold`]
20+
[#11012](https://github.com/rust-lang/rust-clippy/pull/11012)
21+
* [`tuple_array_conversions`]
22+
[#11020](https://github.com/rust-lang/rust-clippy/pull/11020)
23+
* [`redundant_at_rest_pattern`]
24+
[#11013](https://github.com/rust-lang/rust-clippy/pull/11013)
25+
* [`needless_pub_self`]
26+
[#10967](https://github.com/rust-lang/rust-clippy/pull/10967)
27+
* [`pub_with_shorthand`]
28+
[#10967](https://github.com/rust-lang/rust-clippy/pull/10967)
29+
* [`pub_without_shorthand`]
30+
[#10967](https://github.com/rust-lang/rust-clippy/pull/10967)
31+
* [`manual_range_patterns`]
32+
[#10968](https://github.com/rust-lang/rust-clippy/pull/10968)
33+
* [`needless_raw_string_hashes`]
34+
[#10884](https://github.com/rust-lang/rust-clippy/pull/10884)
35+
* [`needless_raw_strings`]
36+
[#10884](https://github.com/rust-lang/rust-clippy/pull/10884)
37+
* [`incorrect_clone_impl_on_copy_type`]
38+
[#10925](https://github.com/rust-lang/rust-clippy/pull/10925)
39+
* [`drain_collect`]
40+
[#10835](https://github.com/rust-lang/rust-clippy/pull/10835)
41+
* [`single_range_in_vec_init`]
42+
[#10934](https://github.com/rust-lang/rust-clippy/pull/10934)
43+
* [`unnecessary_literal_unwrap`]
44+
[#10358](https://github.com/rust-lang/rust-clippy/pull/10358)
45+
* [`large_stack_frames`]
46+
[#10827](https://github.com/rust-lang/rust-clippy/pull/10827)
47+
* [`min_ident_chars`]
48+
[#10916](https://github.com/rust-lang/rust-clippy/pull/10916)
49+
* [`needless_if`]
50+
[#10921](https://github.com/rust-lang/rust-clippy/pull/10921)
51+
* [`excessive_nesting`]
52+
[#10672](https://github.com/rust-lang/rust-clippy/pull/10672)
53+
* [`arc_with_non_send_sync`]
54+
[#10898](https://github.com/rust-lang/rust-clippy/pull/10898)
55+
* [`redundant_type_annotations`]
56+
[#10570](https://github.com/rust-lang/rust-clippy/pull/10570)
57+
* [`host_endian_bytes`]
58+
[#10826](https://github.com/rust-lang/rust-clippy/pull/10826)
59+
* [`little_endian_bytes`]
60+
[#10826](https://github.com/rust-lang/rust-clippy/pull/10826)
61+
* [`big_endian_bytes`]
62+
[#10826](https://github.com/rust-lang/rust-clippy/pull/10826)
63+
* [`ptr_cast_constness`]
64+
[#10779](https://github.com/rust-lang/rust-clippy/pull/10779)
65+
* [`needless_else`]
66+
[#10810](https://github.com/rust-lang/rust-clippy/pull/10810)
67+
68+
### Moves and Deprecations
69+
70+
* Moved [`redundant_clone`] to `nursery` (Now allow-by-default)
71+
[#10873](https://github.com/rust-lang/rust-clippy/pull/10873)
72+
73+
### Enhancements
74+
75+
* [`undocumented_unsafe_blocks`]: Added [`accept-comment-above-attributes`] configuration
76+
[#10986](https://github.com/rust-lang/rust-clippy/pull/10986)
77+
* [`undocumented_unsafe_blocks`]: Added [`accept-comment-above-statement`] configuration.
78+
[#10886](https://github.com/rust-lang/rust-clippy/pull/10886)
79+
* [`missing_panics_doc`]: No longer lints on `todo!()`
80+
[#10976](https://github.com/rust-lang/rust-clippy/pull/10976)
81+
* [`module_inception`]: Added `allow-private-module-inception` configuration.
82+
[#10917](https://github.com/rust-lang/rust-clippy/pull/10917)
83+
* Errors and warnings generated while parsing `clippy.toml` now point to the location in the TOML
84+
file the error/warning occurred in.
85+
[#10607](https://github.com/rust-lang/rust-clippy/pull/10607)
86+
87+
### False Positive Fixes
88+
89+
* [`excessive_precision`]: No longer lints overflowing literals
90+
[#10952](https://github.com/rust-lang/rust-clippy/pull/10952)
91+
92+
### Suggestion Fixes/Improvements
93+
94+
* [`option_map_unwrap_or`]: The suggestion now considers the set [`msrv`] config value
95+
[#11030](https://github.com/rust-lang/rust-clippy/pull/11030)
96+
97+
### Documentation Improvements
98+
99+
* [Clippy's lint list] now stores filter parameters in the URL, to allow easy sharing
100+
[#10834](https://github.com/rust-lang/rust-clippy/pull/10834)
12101

13-
Current stable, released 2023-07-13
102+
## Rust 1.71
14103

15-
<!-- FIXME: Remove the request for feedback, with the next changelog -->
104+
Released 2023-07-13
16105

17-
We're trying out a new shorter changelog format, that only contains significant changes.
18-
You can check out the list of merged pull requests for a list of all changes.
19-
If you have any feedback related to the new format, please share it in
20-
[#10847](https://github.com/rust-lang/rust-clippy/issues/10847)
106+
Note: Clippy will use a shorter changelog format from now on, if you want a detailed list of
107+
all changes, please check out the list of merged pull requests.
21108

22109
[View all 78 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-04-11T20%3A05%3A26Z..2023-05-20T13%3A48%3A17Z+base%3Amaster)
23110

@@ -4677,6 +4764,7 @@ Released 2018-09-13
46774764
[pull3665]: https://github.com/rust-lang/rust-clippy/pull/3665
46784765
[adding_lints]: https://github.com/rust-lang/rust-clippy/blob/master/book/src/development/adding_lints.md
46794766
[`README.md`]: https://github.com/rust-lang/rust-clippy/blob/master/README.md
4767+
[Clippy's lint list]: https://rust-lang.github.io/rust-clippy/master/index.html
46804768

46814769
<!-- lint disable no-unused-definitions -->
46824770
<!-- begin autogenerated links to lint list -->
@@ -4897,6 +4985,7 @@ Released 2018-09-13
48974985
[`implicit_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return
48984986
[`implicit_saturating_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_add
48994987
[`implicit_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub
4988+
[`implied_bounds_in_impls`]: https://rust-lang.github.io/rust-clippy/master/index.html#implied_bounds_in_impls
49004989
[`impossible_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#impossible_comparisons
49014990
[`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops
49024991
[`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping
@@ -5211,6 +5300,7 @@ Released 2018-09-13
52115300
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
52125301
[`repeat_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_once
52135302
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
5303+
[`reserve_after_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#reserve_after_initialization
52145304
[`rest_pat_in_fully_bound_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pat_in_fully_bound_structs
52155305
[`result_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_expect_used
52165306
[`result_large_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
@@ -5241,6 +5331,7 @@ Released 2018-09-13
52415331
[`short_circuit_statement`]: https://rust-lang.github.io/rust-clippy/master/index.html#short_circuit_statement
52425332
[`should_assert_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_assert_eq
52435333
[`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait
5334+
[`should_panic_without_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_panic_without_expect
52445335
[`significant_drop_in_scrutinee`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee
52455336
[`significant_drop_tightening`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_tightening
52465337
[`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub mod else_if_without_else;
148148

149149
pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
150150
// ...
151-
store.register_early_pass(|| box else_if_without_else::ElseIfWithoutElse);
151+
store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
152152
// ...
153153

154154
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.73"
3+
version = "0.1.74"
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"
@@ -27,7 +27,7 @@ tempfile = { version = "3.2", optional = true }
2727
termize = "0.1"
2828

2929
[dev-dependencies]
30-
ui_test = "0.11.5"
30+
ui_test = "0.18.1"
3131
tester = "0.9"
3232
regex = "1.5"
3333
toml = "0.7.3"

book/src/SUMMARY.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
- [Development](development/README.md)
1414
- [Basics](development/basics.md)
1515
- [Adding Lints](development/adding_lints.md)
16+
- [Defining Lints](development/defining_lints.md)
1617
- [Lint Passes](development/lint_passes.md)
1718
- [Type Checking](development/type_checking.md)
19+
- [Method Checking](development/method_checking.md)
1820
- [Macro Expansions](development/macro_expansions.md)
1921
- [Common Tools](development/common_tools_writing_lints.md)
2022
- [Infrastructure](development/infrastructure/README.md)

book/src/development/adding_lints.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ The process of generating the `.stderr` file is the same, and prepending the
161161
## Rustfix tests
162162

163163
If the lint you are working on is making use of structured suggestions, the test
164-
file should include a `//@run-rustfix` comment at the top. This will
165-
additionally run [rustfix] for that test. Rustfix will apply the suggestions
164+
will create a `.fixed` file by running [rustfix] for that test.
165+
Rustfix will apply the suggestions
166166
from the lint to the code of the test file and compare that to the contents of a
167167
`.fixed` file.
168168

+205
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# Define New Lints
2+
3+
The first step in the journey of a new lint is the definition
4+
and registration of the lint in Clippy's codebase.
5+
We can use the Clippy dev tools to handle this step since setting up the
6+
lint involves some boilerplate code.
7+
8+
#### Lint types
9+
10+
A lint type is the category of items and expressions in which your lint focuses on.
11+
12+
As of the writing of this documentation update, there are 12 _types_ of lints
13+
besides the numerous standalone lints living under `clippy_lints/src/`:
14+
15+
- `cargo`
16+
- `casts`
17+
- `functions`
18+
- `loops`
19+
- `matches`
20+
- `methods`
21+
- `misc_early`
22+
- `operators`
23+
- `transmute`
24+
- `types`
25+
- `unit_types`
26+
- `utils / internal` (Clippy internal lints)
27+
28+
These types group together lints that share some common behaviors. For instance,
29+
`functions` groups together lints that deal with some aspects of functions in
30+
Rust, like definitions, signatures and attributes.
31+
32+
For more information, feel free to compare the lint files under any category
33+
with [All Clippy lints][all_lints] or ask one of the maintainers.
34+
35+
## Lint name
36+
37+
A good lint name is important, make sure to check the [lint naming
38+
guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy
39+
team member will alert you in the PR process.
40+
41+
---
42+
43+
We'll name our example lint that detects functions named "foo" `foo_functions`.
44+
Check the [lint naming guidelines][lint_naming] to see why this name makes
45+
sense.
46+
47+
## Add and Register the Lint
48+
49+
Now that a name is chosen, we shall register `foo_functions` as a lint to the
50+
codebase. There are two ways to register a lint.
51+
52+
### Standalone
53+
54+
If you believe that this new lint is a standalone lint (that doesn't belong to
55+
any specific [type](#lint-types) like `functions` or `loops`), you can run the
56+
following command in your Clippy project:
57+
58+
```sh
59+
$ cargo dev new_lint --name=lint_name --pass=late --category=pedantic
60+
```
61+
62+
There are two things to note here:
63+
64+
1. `--pass`: We set `--pass=late` in this command to do a late lint pass. The
65+
alternative is an `early` lint pass. We will discuss this difference in a
66+
later chapter.
67+
<!-- FIXME: Link that "later chapter" when lint_passes.md is merged -->
68+
2. `--category`: If not provided, the `category` of this new lint will default
69+
to `nursery`.
70+
71+
The `cargo dev new_lint` command will create a new file:
72+
`clippy_lints/src/foo_functions.rs` as well as [register the
73+
lint](#lint-registration).
74+
75+
Overall, you should notice that the following files are modified or created:
76+
77+
```sh
78+
$ git status
79+
On branch foo_functions
80+
Changes not staged for commit:
81+
(use "git add <file>..." to update what will be committed)
82+
(use "git restore <file>..." to discard changes in working directory)
83+
modified: CHANGELOG.md
84+
modified: clippy_lints/src/lib.register_lints.rs
85+
modified: clippy_lints/src/lib.register_pedantic.rs
86+
modified: clippy_lints/src/lib.rs
87+
88+
Untracked files:
89+
(use "git add <file>..." to include in what will be committed)
90+
clippy_lints/src/foo_functions.rs
91+
tests/ui/foo_functions.rs
92+
```
93+
94+
95+
### Specific Type
96+
97+
> **Note**: Lint types are listed in the ["Lint types"](#lint-types) section
98+
99+
If you believe that this new lint belongs to a specific type of lints,
100+
you can run `cargo dev new_lint` with a `--type` option.
101+
102+
Since our `foo_functions` lint is related to function calls, one could
103+
argue that we should put it into a group of lints that detect some behaviors
104+
of functions, we can put it in the `functions` group.
105+
106+
Let's run the following command in your Clippy project:
107+
108+
```sh
109+
$ cargo dev new_lint --name=foo_functions --type=functions --category=pedantic
110+
```
111+
112+
This command will create, among other things, a new file:
113+
`clippy_lints/src/{type}/foo_functions.rs`.
114+
In our case, the path will be `clippy_lints/src/functions/foo_functions.rs`.
115+
116+
Notice how this command has a `--type` flag instead of `--pass`. Unlike a standalone
117+
definition, this lint won't be registered in the traditional sense. Instead, you will
118+
call your lint from within the type's lint pass, found in `clippy_lints/src/{type}/mod.rs`.
119+
120+
A _type_ is just the name of a directory in `clippy_lints/src`, like `functions` in
121+
the example command. Clippy groups together some lints that share common behaviors,
122+
so if your lint falls into one, it would be best to add it to that type.
123+
124+
Overall, you should notice that the following files are modified or created:
125+
126+
```sh
127+
$ git status
128+
On branch foo_functions
129+
Changes not staged for commit:
130+
(use "git add <file>..." to update what will be committed)
131+
(use "git restore <file>..." to discard changes in working directory)
132+
modified: CHANGELOG.md
133+
modified: clippy_lints/src/declared_lints.rs
134+
modified: clippy_lints/src/functions/mod.rs
135+
136+
Untracked files:
137+
(use "git add <file>..." to include in what will be committed)
138+
clippy_lints/src/functions/foo_functions.rs
139+
tests/ui/foo_functions.rs
140+
```
141+
142+
143+
## The `define_clippy_lints` macro
144+
145+
After `cargo dev new_lint`, you should see a macro with the name
146+
`define_clippy_lints`. It will be in the same file if you defined a standalone
147+
lint, and it will be in `mod.rs` if you defined a type-specific lint.
148+
149+
The macro looks something like this:
150+
151+
```rust
152+
declare_clippy_lint! {
153+
/// ### What it does
154+
///
155+
/// // Describe here what does the lint do.
156+
///
157+
/// Triggers when detects...
158+
///
159+
/// ### Why is this bad?
160+
///
161+
/// // Describe why this pattern would be bad
162+
///
163+
/// It can lead to...
164+
///
165+
/// ### Example
166+
/// ```rust
167+
/// // example code where clippy issues a warning
168+
/// ```
169+
/// Use instead:
170+
/// ```rust
171+
/// // example code which does not raise clippy warning
172+
/// ```
173+
#[clippy::version = "1.70.0"] // <- In which version was this implemented, keep it up to date!
174+
pub LINT_NAME, // <- The lint name IN_ALL_CAPS
175+
pedantic, // <- The lint group
176+
"default lint description" // <- A lint description, e.g. "A function has an unit return type."
177+
}
178+
```
179+
180+
## Lint registration
181+
182+
If we run the `cargo dev new_lint` command for a new lint, the lint will be
183+
automatically registered and there is nothing more to do.
184+
185+
However, sometimes we might want to declare a new lint by hand. In this case,
186+
we'd use `cargo dev update_lints` command afterwards.
187+
188+
When a lint is manually declared, we might need to register the lint pass
189+
manually in the `register_plugins` function in `clippy_lints/src/lib.rs`:
190+
191+
```rust
192+
store.register_late_pass(|_| Box::new(foo_functions::FooFunctions));
193+
```
194+
195+
As you might have guessed, where there's something late, there is something
196+
early: in Clippy there is a `register_early_pass` method as well. More on early
197+
vs. late passes in a later chapter.
198+
<!-- FIXME: Link that "later chapter" when lint_passes.md is merged -->
199+
200+
Without a call to one of `register_early_pass` or `register_late_pass`, the lint
201+
pass in question will not be run.
202+
203+
204+
[all_lints]: https://rust-lang.github.io/rust-clippy/master/
205+
[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

0 commit comments

Comments
 (0)