Commit graph

10622 commits

Author SHA1 Message Date
Ada Alakbarova
c8c23bcf5b
fix(empty_enum): don't lint if all variants happen to be cfg-d out 2025-10-20 00:47:11 +02:00
Ada Alakbarova
70de06f70f
clean-up a bit 2025-10-20 00:16:29 +02:00
Philipp Krones
cf7aaa5ecf
Merge remote-tracking branch 'upstream/master' into rustup 2025-10-16 15:57:00 +02:00
llogiq
00e5e1b838
refactor(match_like_matches_macro): disentangle the if-let and match cases (#15854)
As discussed in [#clippy > `match_like_matches_macro` does the
work
of`match_same_arms`](https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/.60match_like_matches_macro.60.20does.20the.20work.20of.60match_same_arms.60/with/544003831)

Sorry for the large number of commits -- I could've gotten away just
three ("clean-up", and one for each inlining of `find_matches_sugg` and
subsequent simplifications), but I found the diff of that quite
difficult to understand.

changelog: none
2025-10-15 20:31:28 +00:00
llogiq
869753389b
overhaul mutex_{atomic,integer} (#15632)
- only lint on definitions of offending mutexes, not all their uses
(fixes https://github.com/rust-lang/rust-clippy/issues/13378)
- give more orderly help messages
- stop linting on `Mutex<*const T>` (see the corresponding commit for
context)
- offer (partial) suggestions

The last change might be deemed a bit too much for the feature freeze,
but it can be easily extracted out into a separate PR.

changelog: [`mutex_atomic`]: only lint the definitions, not uses
changelog: [`mutex_atomic`]: better help messages, and suggestions
changelog: [`mutex_atomic`]: don't lint `Mutex<*const T>`
changelog: [`mutex_integer`]: only lint the definitions, not uses
changelog: [`mutex_integer`]: better help messages, and suggestions
2025-10-15 20:29:59 +00:00
llogiq
ab9eb10ef7
feat: manual_rotate also recognize non-consts (#15402)
changelog: [`manual_rotate`]: also recognize non-consts

fixes https://github.com/rust-lang/rust-clippy/issues/13028

r? @llogiq
2025-10-15 19:12:24 +00:00
Jason Newcomb
8116b2354a
Dereference argument of manual_div_ceil() if needed (#15706)
Fixes rust-lang/rust-clippy#15705

changelog: [`manual_div_ceil`]: dereference argument when needed

r? Alexendoo
2025-10-15 02:22:39 +00:00
Jason Newcomb
ec8e8fde91
refactor(non_canonical_impls): lint starting from impls (#15749)
Based on
https://github.com/rust-lang/rust-clippy/pull/15520#discussion_r2372599748,
with the following changes/additions:
- No longer use the `Trait` enum for quickly filtering out irrelevant
impls -- instead, check the `trait_of` basically right away:
    1. pre-fetch `DefId`s of the relevant traits into the lint pass
2. reuse `cx.tcx.impl_trait_ref`'s output for the the `DefId` of the
trait being implemented
    3. compare those `DefId`s, which should be very cheap
- Next, check whether `self_ty` implements the other relevant trait.
- Pre-filter impl items in the same (lazy) iterator, but delay the
proc-macro check as much as possible

changelog: none

Not auto-assigning since @blyxyas and/or @Jarcho will be the ones
reviewing it:
r? ghost
2025-10-15 02:20:21 +00:00
Jason Newcomb
d230acd9cf
Allow explicit_write in tests (#15862)
Resolves rust-lang/rust-clippy#15780.

I didn't get any feedback on that issue. So I hope it is okay that I
charged ahead and addressed it.

changelog: Allow `explicit_write` in tests
2025-10-15 01:44:50 +00:00
Teodoro Freund
9cc0291582 unnecessary_safety_comment fix an ICE and
improve coverage

Considering comments above attributes for items

Fixed the ICE and safety comments between attributes

- No longer using attr.span()
- ignoring attributes manually

Improve error messages on unsafe fns
2025-10-14 22:23:53 +01:00
Samuel Moelius
1bd8cad5a2 Allow explicit_write in tests 2025-10-14 11:52:54 -04:00
Samuel Tardieu
a8d1258ba7
feat(multiple_inherent_impl): Add config option to target specific scope (#15843)
Add a config option `inherent-impl-lint-scope` to the lint
`multiple_inherent_impl` to target a different scope according to
people's needs. It can take three values: `module`, `file`, and `crate`
(default).

- `module` is the weakest option. It lints if there are two or more
impls in the same module.
- `file` is a bit stronger, since it lints if there are two or more
impls in the same file. So, this triggers the lint (where it did not
with module):
- `crate` is the strongest of them; it triggers as soon as there are two
or more impls anywhere in the crate. It is the current behaviour of the
lint, so it's the default option.

changelog: [`multiple_inherent_impl`] : Add config option (`module`,
`file` or `crate`) to target specific scope

fixes rust-lang/rust-clippy#14867
2025-10-13 05:07:54 +00:00
Paul MIALANE
9be213666e feat(multiple_inherent_impl): Add config option to target specific scope 2025-10-12 10:59:57 +02:00
Camille GILLOT
918b2d88e9 Diagnose liveness on MIR. 2025-10-11 20:50:21 +00:00
Timo
1f0b8b8629
fix(clone_on_ref_ptr): only name the generic type if possible (#15740)
Fixes https://github.com/rust-lang/rust-clippy/issues/15009

changelog: [clone_on_ref_ptr]: only name the generic type if possible
2025-10-11 14:15:19 +00:00
Alejandra González
d66e5db0f7
manual_unwrap_or: fix FP edge case (#15812)
changelog: [`manual_unwrap_or`]: fix FP edge case

Found this problem while investigating a different bug.
2025-10-11 11:15:44 +00:00
Ada Alakbarova
778da589c6
suggest adjusting the type ascription 2025-10-11 10:37:39 +02:00
Ada Alakbarova
e5fd571414
realize that a test case is incorrect
`Mutex<*const _>` doesn't make a lot of sense (there can be no
contention over a read-only reference), but `AtomicPtr::new(*const _)`
straight up doesn't compile
2025-10-11 10:37:39 +02:00
Ada Alakbarova
99ce6391dd
suggest replacing Mutex::new with AtomicX::new 2025-10-11 10:37:38 +02:00
Ada Alakbarova
38ac3d041c
only lint on definitions, not use 2025-10-11 10:37:38 +02:00
Ada Alakbarova
3ae047ee04
restructure messages
- The main message should point out what's wrong, not directly suggest a
  solution.
- The second part of the message is a separate advice, so it should be
  emitted separately.
2025-10-11 10:34:59 +02:00
Ada Alakbarova
6b076ca80b
feat(zero_repeat_side_effects): don't suggest unnecessary braces around stmts 2025-10-11 10:19:24 +02:00
Ada Alakbarova
bb5b5bce99
feat(zero_repeat_side_effects): put the suggestion on two lines 2025-10-11 10:19:23 +02:00
Samuel Tardieu
12e2542c55
Dereference argument of manual_div_ceil() if needed 2025-10-11 09:37:25 +02:00
Ada Alakbarova
097f2fd2f4
add missing test for macros
The missing external macro test for `non_canonical_clone_impl` was
caught thanks to lintcheck -- I went ahead and added all the other
combinations of the test while at it
2025-10-11 09:24:58 +02:00
Samuel Tardieu
ebbbbebf2d
Replace all item identification utils (#15682)
This introduces a new way of identifying items/paths using extension
traits with a composable set of functions rather than unique functions
for various combinations of starting points and target items. Altogether
this is a set of five traits:

* `MaybeTypeckRes`: Allows both `LateContext` and `TypeckResults` to be
used for type-dependent lookup. The implementation here will avoid ICEs
by returning `None` when debug assertions are disabled. With assertions
this will assert that we don't silently lookup anything from a different
body than the current one and that a definition actually exists.
* `HasHirId`: Simply a convenience to allow not typing `.hir_id` at call
sites.
* `MaybeQPath`: This is the old `MaybePath`. Extension functions for
type-dependent path lookups exist here. A lot of these functions aren't
used in the current PR, but what they accomplish is done in various
places I haven't cleaned up yet.
* `MaybeResPath`: Like `MaybeQPath`, but only does non-type-dependent
lookup (`QPath::Resolved`).
* `MaybeDef`: Extension functions for identifying the current definition
and accessing properties. Implemented for several types for convenience.

`MaybeDef` is implemented for `Option` to allow chaining methods
together. e.g.
`cx.ty_based_def(e).opt_parent(cx).opt_impl_ty(cx).is_diag_item(..)`
would chaining `and_then` or `if let` on every step. `MaybeQPath` and
`MaybeResPath` are also implemented for `Option` for the same reason.

`ty_based_def` is just a shorter name for `type_dependent_def`. I'm not
really attached to it, but it's nice that it's a little shorter.

changelog: none
2025-10-11 07:03:12 +00:00
Jason Newcomb
42f2ba1869
fix(zero_repeat_side_effects): don't suggest unsuggestable types (#15815)
Fixes https://github.com/rust-lang/rust-clippy/issues/14998

changelog: [`zero_repeat_side_effects`]: don't suggest unsuggestable
types
2025-10-11 04:15:13 +00:00
Jason Newcomb
cb32444ee6 Remove is_path_diagnostic_item 2025-10-10 22:30:57 -04:00
Michael Howell
e0e5d478c1 manual_unwrap_or: fix FP edge case 2025-10-10 16:54:33 -07:00
Nick Drozd
b71fe9254d Check structs and enums for use_self 2025-10-09 18:23:12 -05:00
Alejandra González
57913b4737
Honor allow/expect attributes on ADT and impl Clone nodes (#15849)
changelog: [`expl_impl_clone_on_copy`]: honor `allow`/`expect`
attributes on both the type declaration and the `impl`

Fixes rust-lang/rust-clippy#15842

r? @blyxyas
2025-10-09 22:09:37 +00:00
llogiq
e6febbd13b
Add lint unnecessary_option_map_or_else (#14662)
changelog: [`unnecessary_option_map_or_else`]: Added lint
unnecessary_option_map_or_else. As suggested in the issue description,
the implementation takes as reference the issue
rust-lang/rust-clippy#7328. The tests for lints `option_if_let_else` and
`or_fun_call` needed to be adjusted to comply with new lint.
fixes rust-lang/rust-clippy#14588
2025-10-09 21:56:14 +00:00
Ada Alakbarova
6d0fafd849
clean-up 2025-10-09 20:34:47 +02:00
Ada Alakbarova
6b697dba79
fix(clone_on_ref_ptr): only name the generic type if possible 2025-10-09 11:43:31 +02:00
Timo
e70b206665
chore: multipart_suggestions for manual_assert (#13787)
This should address
https://github.com/rust-lang/rust-clippy/issues/13099 for the let_unit
test.

changelog: [manual_assert]: Updated manual_assert to use
multipart_suggestions where appropriate
2025-10-08 21:32:11 +00:00
Samuel Tardieu
69bd890ff1
Honor allow/expect attributes on ADT and impl Clone nodes 2025-10-08 22:02:14 +02:00
Scott Gerring
8ef90574a2
chore: update manual_assert span suggestions 2025-10-08 11:58:50 +01:00
Samuel Tardieu
f110f3412d
Fix needless_continue FP when match type is not unit or never (#15547)
Closes rust-lang/rust-clippy#14550
Closes rust-lang/rust-clippy#15548

changelog: [`needless_continue`] fix FP when match type is not unit or
never
2025-10-07 16:24:56 +00:00
yanglsh
13bd9b5d0f fix: needless_continue wrongly unmangled macros 2025-10-08 00:03:48 +08:00
yanglsh
7117bd9a27 fix: needless_continue FP when match type is not unit or never 2025-10-08 00:03:48 +08:00
Samuel Tardieu
0a2eeceefc
Add replace_box lint (#14953)
Adds a new lint that detects `var = Default::default()` when `var` is
`Box<T>` and `T` implements `Default`.

changelog: [`replace_box`]: new lint
2025-10-07 15:56:38 +00:00
dswij
ea54123fd4
fix(collapsible_match): exclude binding modes from struct field pattern suggestions (#15608)
Fixes https://github.com/rust-lang/rust-clippy/issues/13287

changelog: [`collapsible_match`]: exclude binding modes from struct
field pattern suggestions
2025-10-07 15:49:47 +00:00
+merlan #flirora
517ef604af Add replace_box lint 2025-10-07 11:33:54 -04:00
Timo
c1f61242e2
legacy_numeric_constants: add ctxt check for internal macro (#15816)
Fixes rust-lang/rust-clippy#15805

ICE bisects to 9457d640b7, which handles the span incorrectly when part
of the path originates from internal declarative macro.

changelog: none
2025-10-07 08:34:10 +00:00
Matthias Krüger
3f1e8cc1b5 Rollup merge of #147165 - Muscraft:subtract-code-offset, r=davidtwco
test: Subtract code_offset from width for ui_testing

`annotate-snippets` does not have a "UI test" mode like `rustc`, [where the code offset is not subtracted from the column width](f34ba774c7/compiler/rustc_errors/src/emitter.rs (L1985-L1987)). This makes it so `annotate-snippets` will shift the output for some very long tests 5 - 7 columns to the left. As part of my work to have `rustc` use `annotate-snippets`, and to reduce the test differences between the two, I figured it would be best if `rustc` started subtracting the code offset from the width as well.

The first commit exists to keep the test output changes of adding a new line to a test separate from adding the `--diagnostic-width` flag in the second commit. This makes it easier to verify that adding the flag does not affect the test's output.

[Zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/147480-t-compiler.2Fdiagnostics/topic/annotate-snippets.20hurdles)
2025-10-07 07:04:17 +02:00
Nick Drozd
5318883d75 Use expect for lint warnings 2025-10-06 20:17:12 -04:00
Samuel Tardieu
5b23bd479e
Remove no-rustfixes (#15827)
Remove no-rustfixes where it's not required anymore

changelog: none
2025-10-06 21:08:58 +00:00
Samuel Tardieu
2c71638be5
Implement volatile_composites lint (#15686)
Volatile reads and writes to non-primitive types are not well-defined,
and can cause problems.

Fixes rust-lang/rust-clippy#15529

changelog: [`volatile_composites`]: Lint when read/write_volatile is
used on composite types
(structs, arrays, etc) as their semantics are not well defined.
2025-10-06 21:06:29 +00:00
Alexey Semenyuk
f97b493fa5 Remove no-rustfix 2025-10-06 21:21:02 +03:00
dswij
4f21c9929c
extend while_let_loop to loop { let else } (#15701)
now lints on
```rs
let mut x = [1,2,3].into_iter();
loop {
   let Some(x) = x.next() else { break };
   dbg!(x);
}
```
```
changelog: [`while_let_loop`]: extend to lint on `let else`
```
2025-10-06 17:29:19 +00:00