Commit graph

9979 commits

Author SHA1 Message Date
Samuel Tardieu
a4debd2345
Lint reversed ordering in partial ord impl (#14945)
Fixes rust-lang/rust-clippy#14574

Lint reversed ordering in partial ord impl

changelog: [`non_canonical_partial_ord_impl`] lint reversed ordering
2025-06-03 15:37:41 +00:00
donkomura
3b64c5c465
Lint reversed ordering in partial ord impl
changelog: [non_canonical_partial_ord_impl] lint reversed ordering

Co-authored-by: Samuel Tardieu <sam@rfc1149.net>
2025-06-04 00:00:19 +09:00
Jason Newcomb
eafef84736
missing_const_for_fn: consider constness of instance (#14759)
When determining when a function or method can be called from a `const`
context, the determination must be made on the instance, not on the
declaration. This makes a difference, for example, with `const_trait`
traits whose implementations may or may not be `const`.

changelog: [`missing_const_for_fn`]: when checking if a function or
method can be called from a `const` context, look at the concrete
implementation rather than at the trait definition

Fixes rust-lang/rust-clippy#14658

r? @Jarcho
2025-06-03 14:03:51 +00:00
Jason Newcomb
716eadf674
zombie_processes: do not complain about early early returns (#14912)
If an early return is found under the HIR local declaration node but
before the child process is created, it should not trigger the lint
because the child process has not yet been created.

changelog: [`zombie_process`]: do not complain about early early returns

Fixes rust-lang/rust-clippy#14911
2025-06-03 13:48:53 +00:00
Alex Macleod
9b8c42cbb1
Test that all interned symbols are referenced in Clippy sources (#14842)
This test checks that all symbols defined in Clippy's `sym.rs` file are
used in Clippy. Otherwise, it will fail with a list of symbols which are
unused.

This test only runs when the `internal` feature is set, to allow
developers to temporarily define new, yet unused symbols without failing
the tests. Also, it will not run as part of the compiler test suite, as
an extra symbol should never be seen as a fatal problem in the compiler
repo.

changelog: none
2025-06-02 15:22:31 +00:00
llogiq
d7b27ecbf3
add lint infallible_try_from (#14813)
Looks for `TryFrom` implementations with uninhabited error types and
suggests to implement `From` instead.

Fixes rust-lang/rust-clippy#2144

---

changelog: Add [`infallible_try_from`] lint
2025-06-02 11:52:57 +00:00
Samuel Tardieu
88bb8d169b
Fix semicolon_outside_block suggests wrongly when inside macros (#14954)
Closes rust-lang/rust-clippy#14926

changelog: [`semicolon_outside_block`] fix wrong suggestions when inside
macros
2025-06-02 09:17:55 +00:00
yanglsh
12fc6c7cc9 fix: semicolon_outside_block suggests wrongly when inside macros 2025-06-02 17:03:08 +08:00
Samuel Tardieu
1652187a03
new restriction lint: pointer_format (#14792)
I read a blog post about kernel security, and how various features might
get lost while porting to Rust. In kernel C, they have some guardrails
against divulging pointers. An easy way to replicate that in Rust is a
lint for pointer formatting. So that's what this lint does.

---

changelog: new [`pointer_format`] lint
2025-06-01 09:48:27 +00:00
Samuel Tardieu
43b7d87be1
missing_const_for_fn: consider constness of instance
When determining when a function or method can be called from a `const`
context, the determination must be made on the instance, not on the
declaration. This makes a difference, for example, with `const_trait`
traits whose implementations may or may not be `const`.
2025-05-31 22:22:41 +02:00
Philipp Krones
384b53eee2 Merge remote-tracking branch 'upstream/master' into rustup 2025-05-31 14:09:03 +02:00
llogiq
2948678647
Fix dbg_macro fail to handle async coroutine desugar (#14937)
Closes rust-lang/rust-clippy#14914

----

changelog: [`dbg_macro`]: fix mishandling of async coroutine desugar
2025-05-31 08:47:19 +00:00
yanglsh
76316488e8 fix: dbg_macro fail to handle async coroutine desugar 2025-05-31 15:44:36 +08:00
a-yossy
bb19ae5e2b [explicit_deref_methods]: do not lint on method chains 2025-05-30 23:53:23 +09:00
Andre Bogus
e64dd8ed96 new restriction lint: pointer_format 2025-05-30 09:15:53 +02:00
Samuel Tardieu
3c8bfd144b
zombie_processes: do not complain about early early returns
If an early return is found under the HIR local declaration node but
before the child process is created, it should not trigger the lint
because the child process has not yet been created.
2025-05-28 20:40:05 +02: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
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
beetrees
1d903b6d10 Stabilise repr128 2025-05-28 15:14:34 +01:00
Guillaume Gomez
634f875e8a Add regression test for manual_is_variant_and extension 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
Dan Johnson
8e581e31a2 add lint infallible_try_from
Looks for `TryFrom` implementations with uninhabited error types and
suggests to implement `From` instead.
2025-05-26 08:39:07 -07:00
Samuel Tardieu
d82e51b640
Test that all interned symbols are referenced in Clippy sources 2025-05-25 11:52:24 +02:00
yanglsh
7ffc886472 fix: manual_find suggests wrongly when return type needs adjustment 2025-05-25 15:05:05 +08: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
Alex Macleod
e3adf1428b Remove compiletest headers test 2025-05-24 15:27:31 +00: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
Matthias Krüger
7e5c819796 Rollup merge of #141130 - mejrs:use_self, r=compiler-errors
rustc_on_unimplemented cleanups

Addresses some of the fixmes from https://github.com/rust-lang/rust/pull/139091 and https://github.com/rust-lang/rust/pull/140307.

- switch from `_Self` to `Self` in library
- properly validate that arguments in the `on` filter and the format strings are actually valid

See https://github.com/rust-lang/rustc-dev-guide/pull/2357 for the relevant documentation.
2025-05-22 16:02:30 +02: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
544c300fb6 Improve speed of cargo dev fmt. 2025-05-21 15:09:35 -04:00
Philipp Krones
7debaf6b44 Merge commit 'cadf98bb7d' into clippy-subtree-update 2025-05-21 15:15:38 +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
e5617a79fb fix: needless_for_each suggests wrongly when closure has no braces 2025-05-20 18:07:57 +08: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
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