Commit Graph

22653 Commits

Author SHA1 Message Date
Jason Newcomb a6e40fa9e9 [Perf] Optimize documentation lints **a lot** (1/2) (18% -> 10%) (#14693)
Turns out that `doc_markdown` uses a non-cheap rustdoc function to
convert from markdown ranges into source spans. And it was using it a
lot (about once every 17 lines of documentation on `tokio`, which ends
up being about 2000 times).

This ended up being about 18% of the total Clippy runtime as discovered
by lintcheck --perf in docs-heavy crates. This PR optimizes one of the
cases in which Clippy calls the function, and a future PR once
pulldown-cmark/pulldown-cmark#1034 is merged will be opened. This PR
lands the use of the function into the single-digit zone.

Note that not all crates were affected by this crate equally, those with
more docs are affected far more than those light ones.

changelog:[`clippy::doc_markdown`] has been optimized by 50%
2025-05-21 22:01:41 +00:00
blyxyas acff5d36cc Review comments & Add testing 2025-05-21 23:44:28 +02:00
Samuel Tardieu 3da4c1033a Improve speed of cargo dev fmt (#14862)
This stops using `cargo fmt` and instead calls rustfmt directly with the
list of all files.

All `cargo fmt` does is find the crate roots and passes the edition from
`cargo.toml`. Since the edition is set in `rustfmt.toml` for the test
files and we're already iterating through all the files this is not
needed.

`--skip-children` is used since we already pass all the files, so the
automatic detection isn't buying us anything other than running slower.

~Second commit~ (part of the first commit now) is a change to only use
the `ignore` option in `rustfmt.toml` rather than having a way in `cargo
dev fmt` to ignore files.

r? @samueltardieu

changelog: none
2025-05-21 20:31:46 +00:00
Jason Newcomb 9fa448a119 Make trivial-copy-size-limit consistently the size of the target pointer (#13319)
Fixes
https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Ambiguous.20default.20value.20for.20.60trivial-copy-size-limit.60

The current situation is

| Target width | `trivial-copy-size-limit`|
|--------|--------|
| 8-bit | 2 |
| 16-bit | 4 |
| 32-bit | 8 |
| 64-bit | 8 |

~~Since practically speaking it's almost always 8, let's go with that as
the unconditional default to make it easier to understand~~

Now defaults to `target_pointer_width`

changelog: [`trivial-copy-size-limit`] now also defaults to the size of
a target pointer (unchanged for 64-bit targets)
2025-05-21 20:05:31 +00:00
Jason Newcomb 106ac79ecb Add expect_action helper to clippy_dev 2025-05-21 15:09:35 -04:00
Jason Newcomb 544c300fb6 Improve speed of cargo dev fmt. 2025-05-21 15:09:35 -04:00
Philipp Krones cadf98bb7d Rustup (#14860)
r? @ghost

Quick out-of cycle sync to fix an ICE that was already reported twice

changelog: none
2025-05-21 12:55:45 +00:00
Philipp Krones 8a28b797b8 Bump nightly version -> 2025-05-21 2025-05-21 14:50:25 +02:00
Philipp Krones 910e640f9b Merge remote-tracking branch 'upstream/master' into rustup 2025-05-21 14:50:06 +02:00
Timo 03ba508d0e Fixes manual_slice_size_computation ICE and triggers in const context (#14804)
The first commit fixes rust-lang/rust-clippy#14802: when a slice is
directly present, it must be dereferenced (instead of referenced -1
times) before being passed to `mem::size_of_val()`.

The second commit triggers the lint in a `const` contact when MSRV ≥
1.85.

changelog: [`manual_slice_size_computation`]: fix ICE in suggestion to
efficiently compute the size of a slice, and trigger the lint in `const`
context as well
2025-05-20 22:35:15 +00:00
Timo 5687ed5aae Various macro fixes for loop lints (#14631)
The `explicit_into_iter_loop`, `explicit_iter_loop` and `iter_next_loop`
will now:

- trigger only when the triggering expression is not located into macro
code;
- properly expose code rewrite proposal with code coming from the root
context.

changelog: [`explicit_into_iter_loop`, `explicit_iter_loop`,
`iter_next_loop`]: behave in macro context

Fixes rust-lang/rust-clippy#14630
2025-05-20 22:17:38 +00:00
Jason Newcomb f00c58b374 Make lint span smaller for needless return (#14790)
Fixes rust-lang/rust-clippy#14750 by reducing the lint span for
needless_return.

changelog: [`needless_return`]: Lint span no longer wraps to previous
line
2025-05-20 09:23:56 +00:00
Jason Newcomb 6753e164be Fix ICE while computing type layout (#14837)
If a type is incomplete, for example if generic parameters are not
available yet, although they are not escaping, its layout may not be
computable. Calling `TyCtxt::layout_of()` would create a delayed bug in
the compiler.

changelog: [`zero_sized_map_values`]: fix ICE

Fixes rust-lang/rust-clippy#14822

r? @Jarcho
2025-05-19 23:33:39 +00:00
Samuel Tardieu 72a4e33d69 Fix ICE while computing type layout
If a type is incomplete, for example if generic parameters are not
available yet, although they are not escaping, its layout may not
be computable. Calling `TyCtxt::layout_of()` would create a delayed bug
in the compiler.
2025-05-20 01:21:22 +02:00
Samuel Tardieu 8224956dff Various macro fixes for loop lints
The `explicit_into_iter_loop`, `explicit_iter_loop` and `iter_next_loop`
will now:

- trigger only when the triggering expression is not located into macro
  code;
- properly expose code rewrite proposal with code coming from the root
  context.
2025-05-20 00:48:19 +02:00
Alejandra González 66697e84b1 needless_match: do not pretend that return is not significant in an expression (#14757)
A `return` in an expression makes it divergent and cannot be removed
blindly. While this stripping might have been introduced as a way to
catch more cases, it was improperly used, and no tests exhibit a failure
when this special handling is removed.

changelog: [`needless_match`]: do not strip `return` as it might make
the `if let` or `match` divergent in some cases

Fixes rust-lang/rust-clippy#14754
2025-05-19 22:12:43 +00:00
Jason Newcomb b87e90b28f Use interned symbols instead of strings in more places (#14840)
This patch series makes heavy use of interned symbols when matching
against known method names:

- the first commit reorders the current list of symbols in
`clippy_utils::sym`
- the second commit adds symbol reordering and order checking to `clippy
dev fmt` / `clippy dev fmt --check`
- the third commit converts many uses of string matching during linting
to symbols matching

The symbols are kept as-is (not rendered as strings) as much as possible
to avoid needing locking the interner as much as possible. Static
strings have been kept when they are only used when emitting a
diagnostic, as there is no benefit in using interned strings for
de-interning them right after.

changelog: none

r? @Alexendoo
2025-05-19 21:07:29 +00:00
Samuel Tardieu e16801e68c Use symbols instead of &str when possible 2025-05-19 22:47:57 +02:00
Samuel Tardieu 82bf659dc8 Ensure that symbols list stays sorted 2025-05-19 22:47:57 +02:00
Samuel Tardieu bb724f3421 Sort the existing list of symbols 2025-05-19 22:47:57 +02:00
Alejandra González d4e7e5ba31 Access items through rustc_session instead of rustc_lint_defs (#14852)
Items such as the `declare_tool_lint!()` macro are publicly reexported
from `rustc_lint_defs` to `rustc_session`. Use the latter for
consistency.

changelog: none
2025-05-19 18:17:04 +00:00
Jason Newcomb e34e8ac42b cargo dev fmt: format clippy_lints_internal as well (#14853)
changelog: none
r? @Jarcho
2025-05-19 17:22:14 +00:00
Samuel Tardieu ac7c87e044 Remove obsolete restriction in code (#14851)
changelog: none
2025-05-19 16:56:31 +00:00
Samuel Tardieu 608f6822ca cargo dev fmt: format clippy_lints_internal as well 2025-05-19 18:10:59 +02:00
Samuel Tardieu e2b1de107f Access items through rustc_session instead of rustc_lint_defs
Items such as the `declare_tool_lint!()` macro are publicly reexported
from `rustc_lint_defs` to `rustc_session`. Use the latter for
consistency.
2025-05-19 18:05:34 +02:00
Samuel Tardieu db42c7dddc Remove obsolete restriction in code 2025-05-19 17:50:22 +02:00
Samuel Tardieu ebc2a68fe8 Add new useless_concat lint (#13829)
Fixes #13793.

Interestingly enough, to actually check that the macro call has at least
two arguments, we need to use the rust lexer after getting the original
source code snippet.

changelog: Add new `useless_concat` lint
2025-05-19 15:11:37 +00:00
Alejandra González df33aaf540 Check if dropping an expression may have indirect side-effects (#14594)
It is not enough to check if an expression type implements `Drop` to
determine whether it can have a significant side-effect.

Also, add tests for unchecked cases which were explicitly handled in the
code, such as checking for side effect in a `struct`'s fields, or in its
base expression.

Fix rust-lang/rust-clippy#14592

changelog: [`no_effect_underscore_binding`]: do not propose to remove
the assignment of an object if dropping it might indirectly have a
visible side effect
2025-05-19 11:41:40 +00:00
Samuel Tardieu d44e35d595 Docs: Use spaces in good first issue label (#14844)
This unifies the Clippy repo with the rest of the rust org repos.

changelog: none
2025-05-19 07:55:42 +00:00
Philipp Krones 7123f2acf7 Docs: Use spaces in good first issue label
This unifies the Clippy repo with the rest of the rust org repos.
2025-05-19 09:37:47 +02:00
Stuart Cook a22efe773d Rollup merge of #140874 - mejrs:rads, r=WaffleLapkin
make `rustc_attr_parsing` less dominant in the rustc crate graph

It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly.

Previous graph:
![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd)

Graph with this PR:
![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a)

The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*.

The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-19 13:24:54 +10:00
Samuel Tardieu 375c65030b fix: unnecessary_to_owned FP when map key is a reference (#14834)
Closes rust-lang/rust-clippy#14833

changelog: [`unnecessary_to_owned`] fix FP when map key is a reference
2025-05-18 19:49:20 +00:00
llogiq b03370b9ce Add a reason to/remove some //@no-rustfix annotations (#14839)
changelog: none
2025-05-18 18:53:22 +00:00
yanglsh 492c4e197d fix: unnecessary_to_owned FP when map key is a reference 2025-05-19 00:27:53 +08:00
Alex Macleod 19e967c6b7 Add a reason to/remove some //@no-rustfix annotations 2025-05-18 16:15:43 +00:00
mejrs 035146e398 Remove rustc_attr_data_structures re-export from rustc_attr_parsing 2025-05-18 18:14:43 +02:00
Alex Macleod 618ccd7f03 Do not call TyCtxt::type_of() on a trait (#14830)
changelog: [`useless_as_ref`]: fix ICE on trait method

Fixes rust-lang/rust-clippy#14828
2025-05-18 12:22:57 +00:00
Samuel Tardieu 15d47d74bf Fixing minor typo in book (#14835)
fix minor typo in book: toolcahin => toolchain

changelog: none
2025-05-18 08:42:27 +00:00
Pete LeVasseur 1e3fc3cc46 fix minor typo: toolcahin => toolchain
changelog: none
2025-05-18 17:26:28 +09:00
Samuel Tardieu b7caa1b3e0 Do not call TyCtxt::type_of() on a trait 2025-05-18 09:38:19 +02:00
Timo da7b678992 empty_struct_with_brackets: do not lint code coming from macro expansion (#14623)
Do not attempt to fetch a snippet from expansion. Without this change,
the inside of macros could[*] be shown as the source of the problem.

[*] Due to the way the source code is processed and reparsed in this
macro, the declarative macro has to be located outside the current
source file for the bug to appear. Otherwise, the macro call itself will
be (mis)identified as a potential `struct` field definition and the lint
will not trigger.

changelog: [`empty_struct_with_brackets`]: do not lint code coming from
macro expansion
2025-05-17 10:43:54 +00:00
Timo daeb6a1d18 Misc changes (#14702)
This mainly fixes `with_leading_whitespace` not always adding the
whitespace it can.

changelog: None
2025-05-17 10:40:21 +00:00
Samuel Tardieu 9ebfb84fe0 Refactor and speed up cargo dev fmt (#14638)
Based on rust-lang/rust-clippy#14616

`cargo dev fmt` should now run almost instantly rather than taking a few
seconds.

changelog: None
2025-05-17 10:16:07 +00:00
Jason Newcomb 232be55859 clippy_dev: refactor rustfmt calls 2025-05-17 06:11:19 -04:00
Jason Newcomb 9d47e0c8ce clippy_dev: remove the need for markers when bumping the version 2025-05-17 04:27:39 -04:00
Samuel Tardieu c97b4761d8 excessive_precision: Fix false positive when exponent has leading zero (#14824)
Fixes rust-lang/rust-clippy#6341.

changelog: [`excessive_precision`] no longer triggers on an exponent
with leading zeros
2025-05-17 05:56:05 +00:00
Michael Hackner e666b83b11 excessive_precision: Fix false positive when exponent has leading zero 2025-05-16 21:35:09 -07:00
Samuel Tardieu dcd8bb6d7e Skip inner ordering checking in presence of #[repr(…)] (#14610)
A representation attribute `#[repr(…)]` might indicate that the ordering
of the fields or the variants is dictated by the API the code is
interfacing with. Better not lint with `arbitrary_source_item_ordering`
in this case.

changelog: [`arbitrary_source_item_ordering`]: do not lint inside items
with `#[repr]` attribute
2025-05-16 19:34:32 +00:00
Samuel Tardieu 604b7b0c5c Extend cargo dev rename_lint (#14633)
Based on rust-lang/rust-clippy#14616

Extends `rename_lint` to handle more cases and makes `update_lints` sort
`deprecated_lints.rs`.

changelog: None
2025-05-16 15:06:30 +00:00
llogiq 94cfebb397 Rewrite non_copy_const (#13207)
fixes #12979
fixes #12951
fixes #13233

Tests still need to be finished and the docs still need to be updated,
but this should otherwise ready.

changelog: Lint `declare_interior_mutable_const` and
`borrow_interior_mutable_const` more precisely
2025-05-16 15:05:36 +00:00