Commit Graph

22747 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 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
Catherine Flores a5a7eea0a2 chore: replace smart quote with straight quote in update_lints comment (#14949)
changelog: [update_lints]: replaced a smart quote
2025-06-01 14:18:54 +00:00
krikera 89dc07acb5 chore: fix smart quote in comment used by update_lints script 2025-06-01 19:20:33 +05:30
llogiq 466e0fb154 Do not count deprecated lints in lint total (#14948)
In order to be consistent with our documentation, deprecated lints
should not be counted when displaying the total number of lints on the
[web site](https://rust-lang.github.io/rust-clippy/master/index.html).

For example, as of 2025-06-01, there are 784 non-deprecated lints which
are referred to as "over 750 lints" in the documentation, but the web
site displays "Total number: 799". When one new lint will be added,
there will be a discrepancy ("over 750 lints" vs. "Total number: 800")
if this is not fixed.

changelog: none

r? @llogiq
2025-06-01 13:00:06 +00:00
Timo 3f48a2b01e Use interned symbols instead of strings in more places (#14855)
changelog: none
2025-06-01 12:02:36 +00:00
Samuel Tardieu d4aed518a5 Do not count deprecated lints in lint total
In order to be consistent with our documentation, deprecated lints
should not be counted when displaying the total number of lints on the
[web site](https://rust-lang.github.io/rust-clippy/master/index.html).

For example, as of 2025-06-01, there are 784 non-deprecated lints which
are referred to as "over 750 lints" in the documentation, but the web site
displays "Total number: 799". When one new lint will be added, there
will be a discrepancy ("over 750 lints" vs. "Total number: 800") if this
is not fixed.
2025-06-01 13:48:51 +02: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
Samuel Tardieu 3ed210c457 Use interned symbols instead of strings in more places 2025-05-31 18:25:49 +02:00
Philipp Krones 57cbadd68a Rustup (#14938)
r? @ghost

changelog: none
2025-05-31 12:16:32 +00:00
Philipp Krones cd71411f56 Bump nightly version -> 2025-05-31 2025-05-31 14:11:00 +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
Samuel Tardieu 10ec6fcfc5 Correct code comments (#14920)
Correct comments.

changelog: none
2025-05-30 09:44:50 +00:00
Boot0x7c00 b283ea3591 Corrected code comments 2025-05-30 09:14:35 +00:00
Samuel Tardieu af5b6e8c8e docs(trait_checking): import the right function (#14891)
`is_trait_method` is not even used in this codeblock, whereas
`implements_trait` is used but not imported

(not sure if this is _actually_ a "changelog: none", since the
documentation is at least contributor-facing)

changelog: none
2025-05-30 08:28:04 +00:00
Samuel Tardieu 1822006b11 clean-up modulo_arithmetic (#14898)
changelog: none
2025-05-30 08:12:05 +00:00
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
Andre Bogus e64dd8ed96 new restriction lint: pointer_format 2025-05-30 09:15:53 +02: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
bors 660aede530 Auto merge of #141717 - jhpratt:rollup-neu8nzl, r=jhpratt
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#138285 (Stabilize `repr128`)
 - rust-lang/rust#139994 (add `CStr::display`)
 - rust-lang/rust#141571 (coretests: extend and simplify float tests)
 - rust-lang/rust#141656 (CI: Add cargo tests to aarch64-apple-darwin)

Failed merges:

 - rust-lang/rust#141430 (remove `visit_clobber` and move `DummyAstNode` to `rustc_expand`)
 - rust-lang/rust#141636 (avoid some usages of `&mut P<T>` in AST visitors)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-29 08:53:27 +00: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
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
beetrees 1d903b6d10 Stabilise repr128 2025-05-28 15:14:34 +01: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
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