Commit graph

13206 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
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
llogiq
6fa2866a96
Use None::<u64> instead of 0 to denote an absence of value (#14957)
`clippy_lints::casts::utils::int_ty_to_nbits` used to return `0` to
indicate that the argument was not an integral type. It is more
idiomatic to use `Option<u64>` as a return type.

Also, I've added a few `FIXME:` at places where only `f32` and `f64` are
considered, as we now have `f16` and `f128` to deal with.

changelog: none
2025-06-02 12:41:09 +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
225abd6c0a
Use None::<u64> instead of 0 to denote an absence of value
`clippy_lints::casts::utils::int_ty_to_nbits` used to return `0` to
indicate that the argument was not an integral type. It is more
idiomatic to use `Option<u64>` as a return type.
2025-06-02 13:32:30 +02: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
krikera
89dc07acb5 chore: fix smart quote in comment used by update_lints script 2025-06-01 19:20:33 +05:30
Timo
3f48a2b01e
Use interned symbols instead of strings in more places (#14855)
changelog: none
2025-06-01 12:02:36 +00: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
3ed210c457
Use interned symbols instead of strings in more places 2025-05-31 18:25:49 +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
Samuel Tardieu
010c2d3793
[explicit_deref_methods]: do not lint on method chains (#14921)
changelog: [`explicit_deref_methods`]: do not lint on method chains
fixes rust-lang/rust-clippy#14593
2025-05-30 15:02:47 +00:00
a-yossy
bb19ae5e2b [explicit_deref_methods]: do not lint on method chains 2025-05-30 23:53:23 +09:00
Boot0x7c00
b283ea3591 Corrected code comments 2025-05-30 09:14:35 +00:00
Samuel Tardieu
1822006b11
clean-up modulo_arithmetic (#14898)
changelog: none
2025-05-30 08:12:05 +00:00
Andre Bogus
e64dd8ed96 new restriction lint: pointer_format 2025-05-30 09:15:53 +02: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
Jacob Pratt
f7a97cc7b2 Rollup merge of #141675 - nnethercote:ItemKind-field-order, r=fee1-dead
Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.

So they match the order of the parts in the source code, e.g.:
```
struct Foo<T, U> { t: T, u: U }
       <-><----> <------------>
       /   |       \
   ident generics  variant_data
```

r? `@fee1-dead`
2025-05-29 04:49:43 +02:00
Jacob Pratt
eeb4fa406c Rollup merge of #141638 - oli-obk:builtin-index, r=lcnr
Use `builtin_index` instead of hand-rolling it

Just using the dedicated method more
2025-05-29 04:49:42 +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
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
Oli Scherer
013ab6cdb1 Use builin_index instead of hand-rolling it 2025-05-28 10:03:01 +00:00
Nicholas Nethercote
cb27c8af94 Reorder ast::ItemKind::{Struct,Enum,Union} fields.
So they match the order of the parts in the source code, e.g.:
```
struct Foo<T, U> { t: T, u: U }
       <-><----> <------------>
       /   |       \
   ident generics  variant_data
```
2025-05-28 15:48:45 +10:00
Michael Goulet
327967c351 Rename unpack to kind 2025-05-27 11:14:45 +00:00
Guillaume Gomez
763a7bd148 Extend manual_is_variant_and lint to check for boolean map comparisons 2025-05-27 12:15:44 +02: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
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
Ada Alakbarova
028e1c28c9
use let-chains 2025-05-26 00:32:45 +02:00
Ada Alakbarova
f04eb5984e
use if-let 2025-05-26 00:25:16 +02:00
Ada Alakbarova
b72cb4847b
use ? 2025-05-26 00:25:16 +02:00
Ada Alakbarova
93a509fca3
exhaustive match instead of returns 2025-05-26 00:25:16 +02:00
yanglsh
7ffc886472 fix: manual_find suggests wrongly when return type needs adjustment 2025-05-25 15:05:05 +08:00
yanglsh
03af37302c fix: assign_op_pattern FP on unstable const trait 2025-05-25 02:02:11 +08: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
Nicholas Nethercote
a0760cf5c0 Rename kw::Empty as sym::empty.
Because the empty string is not a keyword.
2025-05-22 11:55:22 +10: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