Skip to content

Update Clippy #110718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 59 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
67e836d
fix
robertbastian Apr 6, 2023
cd0009e
Suppress the triggering of some lints in derived structures
c410-f3r Apr 9, 2023
4026dde
bump declare_clippy_lint syn to 2.0
fee1-dead Apr 10, 2023
0b1b535
Add "Lint Passes" chapter
blyxyas Apr 10, 2023
c19c08f
Fix CI
blyxyas Apr 10, 2023
b85deea
Test all types supported by [`collection_is_never_read`]
schubart Apr 10, 2023
8f979af
Fix UB in `as_ptr_cast_mut` documentation
Alexendoo Apr 11, 2023
2a774bb
Auto merge of #10627 - schubart:collection_is_never_read_all_types, r…
bors Apr 11, 2023
3813b8e
Update ui tests auxiliary to syn 2.0
fee1-dead Apr 12, 2023
d406f65
bless test error
fee1-dead Apr 12, 2023
0d06001
Auto merge of #10621 - fee1-dead-contrib:bump_syn, r=flip1995
bors Apr 12, 2023
6409556
Standardize lint formulation
bluthej Apr 12, 2023
d2f1b2c
Auto merge of #10638 - bluthej:standardize-lint-formulation, r=Alexendoo
bors Apr 12, 2023
d9c2957
Auto merge of #10629 - Alexendoo:as-ptr-cast-mut-docs-ub, r=Jarcho
bors Apr 12, 2023
b473267
Talk about symbol information in "Early Lint Pass"
blyxyas Apr 12, 2023
b2edd42
Merge pull request #10603 from robertbastian/octal
Manishearth Apr 13, 2023
0049816
Auto merge of #10622 - blyxyas:book-lint_passes, r=llogiq
bors Apr 14, 2023
d639062
Address comments
c410-f3r Apr 15, 2023
fbb69de
Improve type checking and lint passes chapters
flip1995 Apr 16, 2023
b842e99
Make warning about hir_ty_to_ty more visible
flip1995 Apr 16, 2023
a34e75b
Auto merge of #10653 - flip1995:book-type_passes_corrections, r=llogiq
bors Apr 16, 2023
e3a352d
Add new chapter: "Macro Expansions"
blyxyas Apr 16, 2023
90cb0fa
Auto merge of #10652 - blyxyas:book-macro_expansions, r=flip1995
bors Apr 16, 2023
4fb38cf
Rename std::mem::size_of_value to std::mem::size_of_val
timvisee Apr 17, 2023
e57deaa
Auto merge of #10659 - timvisee:fix-size-of-val, r=Manishearth
bors Apr 17, 2023
503fd56
Suggest applicable expression for manual slice size calculation lint
timvisee Apr 17, 2023
b8fee8b
Add run-rustfix marker and test file
timvisee Apr 17, 2023
a2580db
Use `clippy_utils::std_or_core` in manual slice size calculation lint
timvisee Apr 17, 2023
203c909
Auto merge of #10661 - timvisee:manual-slice-size-calc-suggestion, r=…
bors Apr 17, 2023
2f4f798
Ignore `manual_slice_size_calculation` in code from macro expansions
Alexendoo Apr 18, 2023
8099f19
Auto merge of #10667 - Alexendoo:manual-slice-size-calculation-macros…
bors Apr 18, 2023
4bc68f9
Add size-parameter to unecessary_box_returns
lukaslueg Apr 16, 2023
0c44586
Auto merge of #10651 - lukaslueg:issue10641, r=xFrednet
bors Apr 19, 2023
747ff06
Update version attribute for 1.69 lints
xFrednet Apr 19, 2023
f1a552c
Auto merge of #10203 - c410-f3r:macro-lint, r=giraffate
bors Apr 19, 2023
3db7352
[arithmetic_side_effects] Fix #10590
c410-f3r Apr 19, 2023
6ce346c
Changelog for Rust 1.69 :cherry_blossom:
xFrednet Apr 19, 2023
4d35b5e
Auto merge of #10668 - xFrednet:changelog-1-69, r=flip1995
bors Apr 19, 2023
523c8fa
Auto merge of #10615 - c410-f3r:bbbbbbbbbbb, r=giraffate
bors Apr 20, 2023
def1705
Update to a compiletest-rs version that requires `//@` for commands
oli-obk Apr 20, 2023
06dace2
Auto merge of #10669 - oli-obk:@, r=Alexendoo
bors Apr 20, 2023
0b16f80
[arithmetic_side_effects] Cache symbols
c410-f3r Apr 20, 2023
c976ad0
Auto merge of #10675 - c410-f3r:bbbbbbbbbbb, r=llogiq
bors Apr 20, 2023
7077bde
Fix typo in significant_drop_tightening
Swatinem Apr 20, 2023
b8d6964
make [`len_zero`] lint not spanning over parenthesis
J-ZhengLi Apr 21, 2023
9283497
Auto merge of #10677 - Swatinem:patch-1, r=xFrednet
bors Apr 21, 2023
8f702b0
clippy: drop unused semver crate
klensy Apr 21, 2023
397f36a
Fix `#[allow(clippy::enum_variant_names)]` directly on variants
Alexendoo Apr 22, 2023
0354cee
Add lint `items_after_test_module`
blyxyas Mar 31, 2023
1ac8dc5
Compact emmited lint
blyxyas Apr 12, 2023
9824234
Auto merge of #10696 - Alexendoo:allow-enum-variant-names, r=flip1995
bors Apr 23, 2023
6328371
Auto merge of #10681 - J-ZhengLi:issue10529, r=flip1995
bors Apr 23, 2023
9a33778
Auto merge of #10688 - klensy:no-semver, r=flip1995
bors Apr 23, 2023
bdd0545
Ignore `impl Trait`(s)
blyxyas Apr 23, 2023
4195522
Auto merge of #10701 - blyxyas:fix-fp-let_underscore_untyped, r=llogiq
bors Apr 23, 2023
a3ed905
Auto merge of #10578 - blyxyas:items_after_test_module, r=dswij
bors Apr 23, 2023
4beb0a4
Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup
flip1995 Apr 23, 2023
fffef0f
Update Cargo.lock
flip1995 Apr 23, 2023
bb63b59
Clippy book: hotfix for broken link
flip1995 Apr 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 4 additions & 5 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,8 @@ dependencies = [
"rustc-semver",
"rustc-workspace-hack",
"rustc_tools_util",
"semver",
"serde",
"syn 1.0.102",
"syn 2.0.8",
"tempfile",
"termize",
"tester",
Expand Down Expand Up @@ -746,9 +745,9 @@ dependencies = [

[[package]]
name = "compiletest_rs"
version = "0.9.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70489bbb718aea4f92e5f48f2e3b5be670c2051de30e57cb6e5377b4aa08b372"
checksum = "e2731272cf25196735df1b52ab5bcba22cf9f99455626c4c8dc092bd5f7f66d0"
dependencies = [
"diff",
"filetime",
Expand Down Expand Up @@ -973,7 +972,7 @@ version = "0.1.70"
dependencies = [
"itertools",
"quote",
"syn 1.0.102",
"syn 2.0.8",
]

[[package]]
Expand Down
120 changes: 118 additions & 2 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,126 @@ document.

## Unreleased / Beta / In Rust Nightly

[7f27e2e7...master](https://github.com/rust-lang/rust-clippy/compare/7f27e2e7...master)
[149392b0...master](https://github.com/rust-lang/rust-clippy/compare/149392b0...master)

## Rust 1.69

Current stable, released 2023-04-20

[7f27e2e7...149392b0](https://github.com/rust-lang/rust-clippy/compare/7f27e2e7...149392b0)

### New Lints

* [`no_mangle_with_rust_abi`]
[#10369](https://github.com/rust-lang/rust-clippy/pull/10369)
* [`significant_drop_tightening`]
[#10163](https://github.com/rust-lang/rust-clippy/pull/10163)
* [`suspicious_command_arg_space`]
[#10317](https://github.com/rust-lang/rust-clippy/pull/10317)
* [`let_underscore_untyped`]
[#10356](https://github.com/rust-lang/rust-clippy/pull/10356)
* [`question_mark_used`]
[#10342](https://github.com/rust-lang/rust-clippy/pull/10342)
* [`extra_unused_type_parameters`]
[#10028](https://github.com/rust-lang/rust-clippy/pull/10028)
* [`impl_trait_in_params`]
[10197](https://github.com/rust-lang/rust-clippy/pull/10197)
* [`transmute_int_to_non_zero`]
[#10360](https://github.com/rust-lang/rust-clippy/pull/10360)
* [`multiple_unsafe_ops_per_block`]
[#10206](https://github.com/rust-lang/rust-clippy/pull/10206)

### Moves and Deprecations

* Moved [`uninlined_format_args`] to `pedantic` (Now allow-by-default)
[#10265](https://github.com/rust-lang/rust-clippy/pull/10265)
* Moved [`unchecked_duration_subtraction`] to `pedantic` (Now allow-by-default)
[#10194](https://github.com/rust-lang/rust-clippy/pull/10194)

### Enhancements

* [`arithmetic_side_effects`]: No longer lints, if safe constant values are used.
[#10310](https://github.com/rust-lang/rust-clippy/pull/10310)
* [`needless_lifetimes`]: Now works in local macros
[#10257](https://github.com/rust-lang/rust-clippy/pull/10257)
* [`unused_io_amount`]: Now detects usages of `is_ok` and `is_err`
[#10225](https://github.com/rust-lang/rust-clippy/pull/10225)
* [`missing_docs_in_private_items`]: Added new configuration `missing-docs-in-crate-items` to lint
on items visible within the current crate. For example, `pub(crate)` items.
[#10303](https://github.com/rust-lang/rust-clippy/pull/10303)
* [`almost_swapped`]: Now detects almost swaps using `let` statements
[#10177](https://github.com/rust-lang/rust-clippy/pull/10177)
* [`wildcard_enum_match_arm`]: Now lints missing private variants, for local enums
[#10250](https://github.com/rust-lang/rust-clippy/pull/10250)

### False Positive Fixes

* [`explicit_auto_deref`]: Now considers projections, when determining if auto deref is applicable
[#10386](https://github.com/rust-lang/rust-clippy/pull/10386)
* [`manual_let_else`]: Now considers side effects of branches, before linting
[#10336](https://github.com/rust-lang/rust-clippy/pull/10336)
* [`uninlined_format_args`]: No longer lints for arguments with generic parameters
[#10343](https://github.com/rust-lang/rust-clippy/pull/10343)
* [`needless_lifetimes`]: No longer lints signatures in macros, if the lifetime is a metavariable
[#10380](https://github.com/rust-lang/rust-clippy/pull/10380)
* [`len_without_is_empty`]: No longer lints, if `len` as a non-default signature
[#10255](https://github.com/rust-lang/rust-clippy/pull/10255)
* [`unusual_byte_groupings`]: Relaxed the required restrictions for specific sizes, to reduce false
positives
[#10353](https://github.com/rust-lang/rust-clippy/pull/10353)
* [`manual_let_else`]: No longer lints `if-else` blocks if they can divergent
[#10332](https://github.com/rust-lang/rust-clippy/pull/10332)
* [`expect_used`], [`unwrap_used`], [`dbg_macro`], [`print_stdout`], [`print_stderr`]: No longer lint
in test functions, if `allow-expect-in-tests` is set
[#10391](https://github.com/rust-lang/rust-clippy/pull/10391)
* [`unnecessary_safety_comment`]: No longer lints code inside macros
[#10106](https://github.com/rust-lang/rust-clippy/pull/10106)
* [`never_loop`]: No longer lints, for statements following break statements for outer blocks.
[#10311](https://github.com/rust-lang/rust-clippy/pull/10311)

### Suggestion Fixes/Improvements

* [`box_default`]: The suggestion now includes the type for trait objects, when needed
[#10382](https://github.com/rust-lang/rust-clippy/pull/10382)
* [`cast_possible_truncation`]: Now suggests using `try_from` or allowing the lint
[#10038](https://github.com/rust-lang/rust-clippy/pull/10038)
* [`invalid_regex`]: Regex errors for non-literals or regular strings containing escape sequences will
now show the complete error
[#10231](https://github.com/rust-lang/rust-clippy/pull/10231)
* [`transmutes_expressible_as_ptr_casts`]: The suggestion now works, if the base type is borrowed
[#10193](https://github.com/rust-lang/rust-clippy/pull/10193)
* [`needless_return`]: Now removes all semicolons on the same line
[#10187](https://github.com/rust-lang/rust-clippy/pull/10187)
* [`suspicious_to_owned`]: The suggestion now shows all options clearly
[#10295](https://github.com/rust-lang/rust-clippy/pull/10295)
* [`bytes_nth`]: Now suggests the correct replacement based on the context
[#10361](https://github.com/rust-lang/rust-clippy/pull/10361)
* [`bool_assert_comparison`]: The suggestion is now machine applicable
[#10218](https://github.com/rust-lang/rust-clippy/pull/10218)
* [`cast_possible_truncation`]: Corrected the lint name in the help message
[#10330](https://github.com/rust-lang/rust-clippy/pull/10330)
* [`needless_return`]: The suggestion now works on if sequences
[#10345](https://github.com/rust-lang/rust-clippy/pull/10345)
* [`needless_lifetimes`]: The suggestion is now machine applicable
[#10222](https://github.com/rust-lang/rust-clippy/pull/10222)
* [`map_entry`]: The suggestion no longer expands macros
[#10346](https://github.com/rust-lang/rust-clippy/pull/10346)

### ICE Fixes

* [`needless_pass_by_value`]: Fixed an ICE, caused by how late bounds were handled
[#10328](https://github.com/rust-lang/rust-clippy/pull/10328)
* [`needless_borrow`]: No longer panics on ambiguous projections
[#10403](https://github.com/rust-lang/rust-clippy/pull/10403)

### Documentation Improvements

* All configurations are now documented in the Clippy Book
[#10199](https://github.com/rust-lang/rust-clippy/pull/10199)

## Rust 1.68

Current stable, released 2023-03-09
Released 2023-03-09

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

Expand Down Expand Up @@ -4615,6 +4730,7 @@ Released 2018-09-13
[`invisible_characters`]: https://rust-lang.github.io/rust-clippy/master/index.html#invisible_characters
[`is_digit_ascii_radix`]: https://rust-lang.github.io/rust-clippy/master/index.html#is_digit_ascii_radix
[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
[`items_after_test_module`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module
[`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect
[`iter_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_count
[`iter_kv_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_kv_map
Expand Down
5 changes: 2 additions & 3 deletions src/tools/clippy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ path = "src/driver.rs"

[dependencies]
clippy_lints = { path = "clippy_lints" }
semver = "1.0"
rustc_tools_util = "0.3.0"
tempfile = { version = "3.2", optional = true }
termize = "0.1"

[dev-dependencies]
compiletest_rs = { version = "0.9", features = ["tmp"] }
compiletest_rs = { version = "0.10", features = ["tmp"] }
tester = "0.9"
regex = "1.5"
toml = "0.5"
Expand All @@ -49,7 +48,7 @@ if_chain = "1.0"
itertools = "0.10.1"
quote = "1.0"
serde = { version = "1.0.125", features = ["derive"] }
syn = { version = "1.0", features = ["full"] }
syn = { version = "2.0", features = ["full"] }
futures = "0.3"
parking_lot = "0.12"
tokio = { version = "1", features = ["io-util"] }
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
- [Development](development/README.md)
- [Basics](development/basics.md)
- [Adding Lints](development/adding_lints.md)
- [Lint Passes](development/lint_passes.md)
- [Type Checking](development/type_checking.md)
- [Macro Expansions](development/macro_expansions.md)
- [Common Tools](development/common_tools_writing_lints.md)
- [Infrastructure](development/infrastructure/README.md)
- [Syncing changes between Clippy and rust-lang/rust](development/infrastructure/sync.md)
Expand Down
22 changes: 22 additions & 0 deletions src/tools/clippy/book/src/development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ If this is your first time contributing to Clippy, you should first read the
[Basics docs](basics.md). This will explain the basics on how to get the source
code and how to compile and test the code.

## Additional Readings for Beginners

If a dear reader of this documentation has never taken a class on compilers
and interpreters, it might be confusing as to why AST level deals with only
the language's syntax. And some readers might not even understand what lexing,
parsing, and AST mean.

This documentation serves by no means as a crash course on compilers or language design.
And for details specifically related to Rust, the [Rustc Development Guide][rustc_dev_guide]
is a far better choice to peruse.

The [Syntax and AST][ast] chapter and the [High-Level IR][hir] chapter are
great introduction to the concepts mentioned in this chapter.

Some readers might also find the [introductory chapter][map_of_territory] of
Robert Nystrom's _Crafting Interpreters_ a helpful overview of compiled and
interpreted languages before jumping back to the Rustc guide.

## Writing code

If you have done the basic setup, it's time to start hacking.
Expand All @@ -37,6 +55,10 @@ book](../lints.md).
> - Triage procedure
> - Bors and Homu

[ast]: https://rustc-dev-guide.rust-lang.org/syntax-intro.html
[hir]: https://rustc-dev-guide.rust-lang.org/hir.html
[rustc_dev_guide]: https://rustc-dev-guide.rust-lang.org/
[map_of_territory]: https://craftinginterpreters.com/a-map-of-the-territory.html
[clippy_rfc]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md
[rfc_stability]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees
[rfc_lint_cats]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/book/src/development/adding_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ The process of generating the `.stderr` file is the same, and prepending the
## Rustfix tests

If the lint you are working on is making use of structured suggestions, the test
file should include a `// run-rustfix` comment at the top. This will
file should include a `//@run-rustfix` comment at the top. This will
additionally run [rustfix] for that test. Rustfix will apply the suggestions
from the lint to the code of the test file and compare that to the contents of a
`.fixed` file.
Expand Down
114 changes: 114 additions & 0 deletions src/tools/clippy/book/src/development/lint_passes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Lint passes

Before working on the logic of a new lint, there is an important decision
that every Clippy developer must make: to use
[`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass].

In short, the `LateLintPass` has access to type and symbol information while the
`EarlyLintPass` doesn't. If you don't need access to type information, use the
`EarlyLintPass`.

Let us expand on these two traits more below.

## `EarlyLintPass`

If you examine the documentation on [`EarlyLintPass`][early_lint_pass] closely,
you'll see that every method defined for this trait utilizes a
[`EarlyContext`][early_context]. In `EarlyContext`'s documentation, it states:

> Context for lint checking of the AST, after expansion, before lowering to HIR.

Voilà. `EarlyLintPass` works only on the Abstract Syntax Tree (AST) level.
And AST is generated during the [lexing and parsing][lexing_and_parsing] phase
of code compilation. Therefore, it doesn't know what a symbol means or information about types, and it should
be our trait choice for a new lint if the lint only deals with syntax-related issues.

While linting speed has not been a concern for Clippy,
the `EarlyLintPass` is faster, and it should be your choice
if you know for sure a lint does not need type information.

As a reminder, run the following command to generate boilerplate for lints
that use `EarlyLintPass`:

```sh
$ cargo dev new_lint --name=<your_new_lint> --pass=early --category=<your_category_choice>
```

### Example for `EarlyLintPass`

Take a look at the following code:

```rust
let x = OurUndefinedType;
x.non_existing_method();
```

From the AST perspective, both lines are "grammatically" correct.
The assignment uses a `let` and ends with a semicolon. The invocation
of a method looks fine, too. As programmers, we might raise a few
questions already, but the parser is okay with it. This is what we
mean when we say `EarlyLintPass` deals with only syntax on the AST level.

Alternatively, think of the `foo_functions` lint we mentioned in
define new lints chapter.

We want the `foo_functions` lint to detect functions with `foo` as their name.
Writing a lint that only checks for the name of a function means that we only
work with the AST and don't have to access the type system at all (the type system is where
`LateLintPass` comes into the picture).

## `LateLintPass`

In contrast to `EarlyLintPass`, `LateLintPass` contains type information.

If you examine the documentation on [`LateLintPass`][late_lint_pass] closely,
you see that every method defined in this trait utilizes a
[`LateContext`][late_context].

In `LateContext`'s documentation we will find methods that
deal with type-checking, which do not exist in `EarlyContext`, such as:

- [`maybe_typeck_results`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html#method.maybe_typeck_results)
- [`typeck_results`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html#method.typeck_results)

### Example for `LateLintPass`

Let us take a look with the following example:

```rust
let x = OurUndefinedType;
x.non_existing_method();
```

These two lines of code are syntactically correct code from the perspective
of the AST. We have an assignment and invoke a method on the variable that
is of a type. Grammatically, everything is in order for the parser.

However, going down a level and looking at the type information,
the compiler will notice that both `OurUndefinedType` and `non_existing_method()`
**are undefined**.

As Clippy developers, to access such type information, we must implement
`LateLintPass` on our lint.
When you browse through Clippy's lints, you will notice that almost every lint
is implemented in a `LateLintPass`, specifically because we often need to check
not only for syntactic issues but also type information.

Another limitation of the `EarlyLintPass` is that the nodes are only identified
by their position in the AST. This means that you can't just get an `id` and
request a certain node. For most lints that is fine, but we have some lints
that require the inspection of other nodes, which is easier at the HIR level.
In these cases, `LateLintPass` is the better choice.

As a reminder, run the following command to generate boilerplate for lints
that use `LateLintPass`:

```sh
$ cargo dev new_lint --name=<your_new_lint> --pass=late --category=<your_category_choice>
```

[early_context]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.EarlyContext.html
[early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html
[late_context]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html
[late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html
[lexing_and_parsing]: https://rustc-dev-guide.rust-lang.org/overview.html#lexing-and-parsing
Loading