22694 Commits

Author SHA1 Message Date
Samuel Tardieu
77f4e00219
Show total count lints (#14901)
Suppose it might be interesting to see up to date total number of lints
something like this

<img width="1276" alt="Screenshot 2025-05-26 at 21 35 46"
src="https://github.com/user-attachments/assets/66c67eb4-f4c6-44ae-9bf4-284a4c4da3e0"
/>
changelog: none
2025-05-30 08:07:49 +00:00
Samuel Tardieu
6275f5235a
Improve wording of manual_contains docs (#14917)
This is mainly to avoid the phrase "more fast" since that is not
idiomatic English

changelog: [`manual_contains`]: Improved documentation wording
2025-05-29 23:20:58 +00:00
Ethan Brierley
e34368b48d
Improve wording of manual_contains docs
This is mainly to avoid the phrase "more fast" since that is not idiomatic English
2025-05-29 22:15:01 +01:00
Jason Newcomb
beaf15532a
while_let_loop: Include let assignment in suggestion (#14756)
Placeholders are still given for the content of the whole block.
However, if the result of the original `if let` or `match` expression
was assigned, the assignment is reflected in the suggestion.

No-op assignments (`let x = x;`) are skipped though, unless they contain
an explicit type which might help the compiler (`let x: u32 = x;` is
kept).

Closes rust-lang/rust-clippy#362

changelog: [`while_let_loop`]: include `let` assignment in suggestion
2025-05-28 16:26:14 +00:00
Samuel Tardieu
b90880d408
Optimize unit_return_expecting_ord (#14905)
This lint was previously written very clumsily, not short-circuiting and
doing a lot of unnecessary work.

Now it makes sure to do the cheaper functions earlier and in general, is
just smarter.
(I specifically focused on minimizing binder instantiation

Sadly, I'm not finding any relevant result in a benchmark. Still with
the LLVM coverage instruments, the expensive bits are called lots of
less times (The binder instantiation that I care about is reduced from
95k to 10k throughout our test suite).

changelog:[`unit_return_expecting_ord`]: Optimize the lint
2025-05-28 16:05:48 +00:00
blyxyas
7e590de435 Optimize unit_return_expecting_ord
This lint was previously written very clumsily, not
shortcircuiting and doing a lot of unnecessary work.

Now it makes sure to do the cheaper functions earlier
and in general, just be smarter.
(I specifically focused on minimizing binder instantiation)

Also, avoid allocating unnecessarily
2025-05-28 18:00:16 +02:00
Alejandra González
3a1159ed9f
needless_return: look inside else if parts as well (#14798)
`if` expressions don't necessarily contain a block in the `else` part in
the presence of an `else if`. The `else` part, if present, must be
handled as a regular expression, not necessarily as a block expression.

Found while applying Clippy to triagebot and looking at the result. This
also found an issue in Clippy itself.

changelog: [`needless_return`]: look inside `else if` parts as well
2025-05-28 15:42:03 +00:00
Philipp Krones
291b8fd3be
[book] fix the trait checking example code (#14908)
Fix the argument in the example for "Trait Checking".

changelog: none
2025-05-28 15:41:03 +00:00
Alejandra González
a31d3b0fc4
Mark myself as on vacation until June 30 (#14909)
https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/Outside.20rotation.20until.20June.2030/with/520912074

changelog: none
2025-05-28 15:27:29 +00:00
blyxyas
854a0b65b0 Mark myself as on vacation until June 30 2025-05-28 16:49:46 +02:00
Kazuki Obata
402fc8105b
Update trait_checking.md 2025-05-28 23:37:31 +09:00
Samuel Tardieu
551870df96
Extend manual_is_variant_and lint to check for boolean map comparisons (#14646)
Fixes rust-lang/rust-clippy#14542.

changelog: [`manual_is_variant_and`]: Extend to check for boolean map
comparisons

r? @samueltardieu
2025-05-28 10:25:11 +00:00
Guillaume Gomez
634f875e8a Add regression test for manual_is_variant_and extension 2025-05-27 12:15:44 +02:00
Guillaume Gomez
763a7bd148 Extend manual_is_variant_and lint to check for boolean map comparisons 2025-05-27 12:15:44 +02:00
Alex Macleod
3927a61a54
[manual_flatten]: Fix with nested Some or Ok pattern (#14846)
changelog: [`manual_flatten`]: fix with nested `Some` or `Ok` pattern
fixes rust-lang/rust-clippy#6776
2025-05-26 21:03:39 +00:00
Timo
b719f99090
Consider consts in patterns as refutable (#14887)
changelog: none
2025-05-26 18:13:29 +00:00
a-yossy
816fa0a923 changelog: [manual_flatten]: fix with nested Some or Ok pattern 2025-05-27 02:28:30 +09:00
Alexey Semenyuk
8cced0fd6f Show total count lints 2025-05-26 21:40:25 +05:00
Timo
32a3744efc
refactor(mut_reference): replace match with if-let to reduce nesting (#14890)
One downside to this is that, since the patterns matched against (on the
left) are quite long, it's a bit difficult to see what's even getting
matched. Using `matches!()` could help with that

changelog: none
2025-05-26 10:13:33 +00:00
Ada Alakbarova
c256bcc057
refactor(mut_reference): replace match with if-let to reduce nesting 2025-05-26 11:54:09 +02:00
dswij
954034b497
Fix manual_find suggests wrongly when return type needs adjustment (#14892)
Closes rust-lang/rust-clippy#14826

changelog: [`manual_find`] fix wrong suggestions when return type needs
adjustment
2025-05-25 18:55:31 +00:00
Samuel Tardieu
c12bc22167
Update askama to 0.14.0 version (#14888)
No breaking changes for clippy in this update (which only impacts the
lint page).

The askama release information is
[here](https://github.com/askama-rs/askama/releases/tag/v0.14.0).

r? @samueltardieu

changelog: update askama version to `0.14.0`
2025-05-25 07:26:12 +00:00
yanglsh
7ffc886472 fix: manual_find suggests wrongly when return type needs adjustment 2025-05-25 15:05:05 +08:00
Guillaume Gomez
f674c809c8 Update askama to 0.14.0 version 2025-05-24 21:18:16 +02:00
llogiq
b6b97a741c
Fix assign_op_pattern FP on unstable const trait (#14886)
Closes rust-lang/rust-clippy#14871

----

changelog: [`assign_op_pattern`]: fix false positive on unstable const
trait
2025-05-24 19:08:46 +00:00
Alex Macleod
843a45f384 Consider consts in patterns as refutable 2025-05-24 18:11:35 +00:00
yanglsh
03af37302c fix: assign_op_pattern FP on unstable const trait 2025-05-25 02:02:11 +08:00
dswij
24a2a6629d
Support different lintcheck CARGO_TARGET_DIR env variables (#14859)
Make lintcheck support different `CARGO_TARGET_DIR`, do not hardcode
`target` (useful for perf)

changelog:none
2025-05-24 16:57:47 +00:00
llogiq
836c6579d7
Remove compiletest headers test (#14884)
`ui_test` detects old style headers so it's redundant

changelog: none
2025-05-24 16:20:01 +00:00
Alex Macleod
e3adf1428b Remove compiletest headers test 2025-05-24 15:27:31 +00:00
Jason Newcomb
1029572c19
Optimize documentation lints **a lot** (2/2) (7.5% -> 1%) (#14870)
So, after https://github.com/rust-lang/rust-clippy/pull/14693 was
merged,
this is the continuation. It performs some optimizations on
`Fragments::span`
, makes it so we don't call it so much, and makes a 85.75% decrease
(7.51% -> 1.07%)
in execution samples of `source_span_for_markdown_range` and a 6.39% ->
0.88%
for `core::StrSearcher::new`. Overall a 13.11% icount decrase on
docs-heavy crates.

Benchmarked mainly on `regex-1.10.5`.

@rustbot label +performance-project

This means that currently our heaviest function is
`rustc_middle::Interners::intern_ty`, even
for documentation-heavy crates

Along with rust-lang/rust-clippy#14693, this makes the lint a 7% of what
it was before and makes it so that even in the most doc-heavy of crates
it's not an issue.

changelog:Optimize documentation lints by a further 85%

r? @Jarcho
2025-05-24 00:22:26 +00:00
blyxyas
4a7598f815 [HEAVY PERF] Optimize documentation lints 2/2
So, after https://github.com/rust-lang/rust-clippy/pull/14693 was merged,
this is the continuation. It performs some optimizations on `Fragments::span`
, makes it so we don't call it so much, and makes a 85.75% decrease (7.51% -> 10.07%)
in execution samples of `source_span_for_markdown_range` and a 6.39% -> 0.88%
for `core::StrSearcher::new`. Overall a 13.11% icount decrase on docs-heavy crates.

Benchmarked mainly on `regex-1.10.5`.

This means that currently our heaviest function is `rustc_middle::Interners::intern_ty`, even
for documentation-heavy crates

Co-authored-by: Roope Salmi <rpsalmi@gmail.com>
2025-05-23 19:46:28 +02:00
Alejandra González
7ab910f935
needless_borrow: do not contradict dangerous_implicit_autorefs (#14810)
Rust 1.88 introduces the `dangerous_implicit_autorefs` lint which warns
about using implicit autorefs on a place obtained from a raw pointer, as
this may create aliasing issues.

Prevent `clippy::needless_borrow` from triggering in this case, by
disabling the lint when taking a reference on a raw pointer dereference.
There might be a better way for doing this in the long run with a finer
way of distinguish the problematic cases, but this will prevent Clippy
from contradicting the compiler in the meantime.

Fixes rust-lang/rust-clippy#14743

changelog: [`needless_borrow`]: do not contradict the compiler's
`dangerous_implicit_autorefs` lint even though the refererences are not
mandatory

@rustbot label +beta-nominated

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

- [Beta nomination for
1.88](https://github.com/rust-lang/rust-clippy/pull/14810#issuecomment-2883753957)
by [samueltardieu](https://github.com/samueltardieu)

Generated by triagebot, see
[help](https://forge.rust-lang.org/triagebot/note.html) for how to add
more
<!--
TRIAGEBOT_SUMMARY_DATA_START$${"entries_by_url":{"https://github.com/rust-lang/rust-clippy/pull/14810#issuecomment-2883753957":{"title":"Beta
nomination for
1.88","comment_url":"https://github.com/rust-lang/rust-clippy/pull/14810#issuecomment-2883753957","author":"samueltardieu"}}}$$TRIAGEBOT_SUMMARY_DATA_END
-->

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
2025-05-23 17:37:41 +00:00
Samuel Tardieu
c364717b15
needless_return: look inside else if parts as well
`if` expressions don't necessarily contain a block in the `else` part in
the presence of an `else if`. The `else` part, if present, must be
handled as a regular expression, not necessarily as a block expression.
2025-05-23 13:24:04 +02:00
Samuel Tardieu
0a059d9e97
needless_borrow: do not contradict dangerous_implicit_autorefs
Rust 1.88 introduces the `dangerous_implicit_autorefs` lint which warns
about using implicit autorefs on a place obtained from a raw pointer,
as this may create aliasing issues.

Prevent `clippy::needless_borrow` from triggering in this case,
by disabling the lint when taking a reference on a raw pointer
dereference. There might be a better way for doing this in the long run
with a finer way of distinguish the problematic cases, but this will
prevent Clippy from contradicting the compiler in the meantime.
2025-05-23 11:12:31 +02:00
Alejandra González
5dccb101ed
Fix needless_for_each suggests wrongly when closure has no braces (#14735)
Closes rust-lang/rust-clippy#14734

changelog: [`needless_for_each`] wrong suggestions when closure has no
braces
2025-05-22 16:25:49 +00:00
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
blyxyas
f1ad1cd799 Support different lintcheck CARGO_TARGET_DIR 2025-05-21 17:24:20 +00: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
yanglsh
520cb092b8 Apply needless_for_each to clippy itself 2025-05-20 18:07:57 +08:00
yanglsh
e5617a79fb fix: needless_for_each suggests wrongly when closure has no braces 2025-05-20 18:07:57 +08:00