Commit graph

10228 commits

Author SHA1 Message Date
Philipp Krones
c98e60a56e
Merge remote-tracking branch 'upstream/master' into rustup 2025-07-25 15:04:01 +02:00
Alejandra González
98205e60cc
Fix if_then_some_else_none FP when require type coercion (#15267)
Closes rust-lang/rust-clippy#15257

changelog: [`if_then_some_else_none`] fix FP when require type coercion
2025-07-24 23:50:14 +00:00
León Orell Valerian Liehr
49e0ae0b9b Rollup merge of #144014 - dianne:edition-guide-links, r=estebank
don't link to the nightly version of the Edition Guide in stable lints

As reported in rust-lang/rust#143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them.

This does not change the link for `rust_2024_incompatible_pat`. That's handled in rust-lang/rust#144006.
2025-07-24 15:08:21 +02:00
Marvin Friedrich
5cd24d70cb
Correct help message for arc_with_non_send_sync 2025-07-24 12:18:14 +02:00
Alejandra González
8ad5c67ff9
Fix module_name_repetitions FP on exported macros (#15319)
Closes rust-lang/rust-clippy#14095

changelog: [`module_name_repetitions`] fix FP on exported macros
2025-07-23 23:11:01 +00:00
Alex Macleod
b2c8c02a02
Fix unused_async FP on function with todo! (#15308)
Closes rust-lang/rust-clippy#15305

changelog: [`unused_async`] fix FP on function with `todo!`
2025-07-23 13:43:55 +00:00
yanglsh
6a8780473e fix: unused_async FP on function with todo! 2025-07-22 23:25:31 +08:00
许杰友 Jieyou Xu (Joe)
97380318b4 Rollup merge of #144027 - RalfJung:clippy, r=Mark-Simulacrum
clippy: make tests work in stage 1

This finally fixes https://github.com/rust-lang/rust/issues/78717 :)

Similar to what Miri already does, the clippy test step needs to carefully consider  which compiler is used to build clippy and which compiler is linked into clippy (and thus must be used to build the test dependencies). On top of that we have some extra complications that Miri avoided by using `cargo-miri` for building its test dependencies: we need cargo to use the right rustc and the right sysroot, but https://github.com/rust-lang/cargo/issues/4423 makes this quite hard to do. See the long comment in `src/tools/clippy/tests/compile-test.rs` for details.

Some clippy tests tried to import rustc crates; that fundamentally requires a full bootstrap loop so it cannot work in stage 1. I had to kind of guess what those tests were doing so I don't know if my changes there make any sense.

Cc ```@flip1995``` ```@Kobzol```
2025-07-22 00:54:28 +08:00
yanglsh
bebae76f23 fix: module_name_repetitions FP on exported macros 2025-07-21 21:49:41 +08:00
Krishna Ketan Rai
92111dcc67 Fix false positive in useless_attribute with redundant_imports
The useless_attribute lint was incorrectly flagging #[expect(redundant_imports)]
as useless when applied to macro re-exports. This occurred because the lint
didn't recognize 'redundant_imports' as a valid rustc lint name.

This commit:
- Adds 'redundant_imports' to the list of known rustc lints in sym.rs
- Updates the useless_attribute lint to properly handle this case
- Adds a regression test to prevent future false positives
2025-07-21 17:13:43 +05:30
Ralf Jung
50f36c0d34 clippy: make tests work in stage 1 2025-07-20 22:55:15 +02:00
dswij
0b168815a4
fix: ignore pattern_type_mismatch when external macro owns the match (#15306)
Don't trigger the `ignore_type_mismatch` lint when the `match scrutinee`
is generated by a macro.

If the macro generates

```
match &scrutinee {
    _ => {},
    () => {},
}
```

We don't expect it to hit on `()`.

Rust Playground example:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b23aca42440f006660bd7440d02db196

changelog: [`pattern_type_mismatch`]: fix unwanted hit in external macro
2025-07-20 15:29:46 +00:00
Timo
c8e333c8c0
Fixed issue #15192 (#15241)
Fixes rust-lang/rust-clippy#15192 by adding checks for no_std while
giving out Box recommendation

```
changelog: [`large_enum_variant`]: Dont suggest `Box` in `no_std` mode
```
2025-07-20 10:37:58 +00:00
lakshay bhatia
b738d96325 Improve Help Message in large_enum_variant to satisfy #[no_std]
- Updated the `help:` text to include a more general suggestion
- Ensures compatibility with `#[no_std]` environments where boxing is
  still possible via `alloc`.
2025-07-20 13:51:45 +05:30
yanglsh
1b883197d7 fix: if_then_some_else_none FP when require type coercion 2025-07-20 13:52:18 +08:00
Alejandra González
56de455c7f
Fix capacity overflow in single_match with deref patterns (#15124)
Fixes rust-lang/rust-clippy#14882

changelog: [`single_match`]: fix ICE with deref patterns and string
literals
2025-07-20 00:24:24 +00:00
Alejandra González
6543a096bf
Fix never_loop forget to remove break in suggestion (#15064)
Closes rust-lang/rust-clippy#15007

Removes the `break` stmt and the dead code after it when appropriate.

changelog: [`never_loop`] Make sure to remove `break` in suggestions
2025-07-20 00:23:46 +00:00
Timo
72243f469d
Fix missing_inline_in_public_items FP on functions with extern (#15313)
Closes rust-lang/rust-clippy#15301

changelog: [`missing_inline_in_public_items`] fix FP on functions with
`extern`
2025-07-19 16:25:13 +00:00
yanglsh
75811dfb66 fix: missing_inline_in_public_items FP on functions with extern 2025-07-20 00:00:04 +08:00
Alex Macleod
fd7076bd00
Fix filter_map_bool_then wrongly suggests macro definitions (#15048)
Closes rust-lang/rust-clippy#15047

changelog: [`filter_map_bool_then`] fix wrongly showed macro definitions
in suggestions
2025-07-19 12:34:23 +00:00
llogiq
17968e7585
Fix needless_range_loop FP on array literals (#15314)
Closes rust-lang/rust-clippy#15309

changelog: [`needless_range_loop`] fix FP on array literals
2025-07-19 12:34:07 +00:00
Alex Macleod
f85cdbbd6f
Simplify must_use_candidate spans (#15310)
This is blocking rust-lang/rust-clippy#14724

changelog: none
2025-07-19 12:24:02 +00:00
yanglsh
6cf00e9490 fix: needless_range_loop FP on array literals 2025-07-19 19:38:25 +08:00
Jason Newcomb
cca924bf9f Simplify must_use_candidate spans. 2025-07-18 14:44:17 -04:00
Kristof Mattei
b2c4e6de2f
fix: ignore pattern_type_mismatch when external macro owns the match
changelog: [`pattern_type_mismatch`]: fix unwanted hit in external macro
2025-07-17 16:47:44 -07:00
bors
11e3ae31d8 Auto merge of #143879 - fee1-dead-contrib:push-lrlpoouyqqry, r=fmease
parse `const trait Trait`

r? oli-obk or anyone from project-const-traits

cc `@rust-lang/project-const-traits`
2025-07-17 15:54:33 +00:00
Samuel Tardieu
167ac052df
Warn about const instability wrt MSRV
This makes `const` contexts use the `const`-stability version information
instead of the regular stability one, as `const`-stability may happen
much later than stability in non-`const` contexts.
2025-07-17 14:44:56 +02:00
Deadbeef
19f8c5004e parse const trait Trait 2025-07-17 18:06:26 +08:00
Samuel Tardieu
11bfeca960
Warn about types not meeting MSRV
For example, the `Duration` type from the standard library was only
introduced in Rust 1.3.0.
2025-07-17 11:53:19 +02:00
Matthias Krüger
a6be68a6ca Rollup merge of #143914 - shepmaster:mismatched-lifetime-syntaxes-rewording, r=traviscross,jieyouxu
Reword mismatched-lifetime-syntaxes text based on feedback

Key changes include:

- Removal of the word "syntax" from the lint message. More accurately, it could have been something like "syntax group" or "syntax category", but avoiding it completely is easier.
- The primary lint message now reflects exactly which mismatch is occurring, instead of trying to be general. A new `help` line is general across the mismatch kinds.
- Suggestions have been reduced to be more minimal, no longer also changing non-idiomatic but unrelated aspects.
- Suggestion text no longer mentions changes when those changes don't occur in that specific suggestion.

r? ``@jieyouxu``
2025-07-17 10:41:47 +02:00
llogiq
ed176b7b88
Fix ptr_as_ptr suggests wrongly with turbo fish (#15289)
Closes rust-lang/rust-clippy#15283

----

changelog: [`ptr_as_ptr`]: fix wrong suggestions with turbo fish
2025-07-16 17:05:35 +00:00
Jason Newcomb
c0dc3b616d
Various improvements to the incompatible_msrv lint (#14433)
This PR supersedes #14328 following the [2025-03-18 Clippy meeting
discussion](https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/Meeting.202025-03-18/with/506527762).
It uses a simpler approach than what was proposed initially in #14328
and does not add new options.

First, it documents how `cfg_attr` can be used to change the MSRV
considered by Clippy to trigger the lint. This allows the MSRV to be
feature gated, or to be raised in tests.

Also, the lint stops warning about items which have been explicitly
allowed through a rustc feature. This works even if the feature has been
stabilized since. It allows using an older compiler with some features
turned on, as is done in Rust for Linux. This fixes #14425.

Then, if the lint triggers, and it looks like the code is located below
a `cfg` or `cfg_attr` attribute, an additional note is issued, once, to
indicate that the `clippy::msrv` attribute can be controlled by an
attribute.

Finally, the lint is extended to cover any path, not just method and
function calls. For example, enumeration variants, or constants, were
not MSRV checked. This required replacing two `u32::MAX` by
`u32::max_value()` in MSRV-limited tests.

An extra commit adds a TODO for checking the const stability also, as
this is not done right now.

@Centri3 I'll assign this to you because you were assigned #14328 and
you were the one who nominated the issue for discussion (thanks!), but
of course feel free to reroll!

r? @Centri3

changelog: [`incompatible_msrv`]: better documentation, honor the
`features` attribute, and lint non-function entities as well
2025-07-16 16:24:01 +00:00
Jason Newcomb
e113e66606
Propose to exchange ranges only when it is safe to do so (#14432)
To avoid false positives, the `range_plus_one` and `range_minus_one`
lints will restrict themselves to situations where the iterator types
can be easily switched from exclusive to inclusive or vice-versa. This
includes situations where the range is used as an iterator, or is used
for indexing.

On the other hand, assignments of the range to variables, including
automatically typed ones or wildcards, will no longer trigger the lint.
However, the cases where such an assignment would benefit from the lint
are probably rare.

In a second commit, the `range_plus_one` and `range_minus_one` logic are
unified, in order to properly emit parentheses around the suggestion
when needed.

Fix rust-lang/rust-clippy#3307
Fix rust-lang/rust-clippy#9908

changelog: [`range_plus_one`, `range_minus_one`]: restrict lint to cases
where it is safe to switch the range type

*Edit:* as a consequence, this led to the removal of three
`#[expect(clippy::range_plus_one)]` in the Clippy sources to avoid those
false positives.
2025-07-16 16:21:45 +00:00
Jason Newcomb
786330e02c
Fix ptr_arg suggests changes when it's actually better not to bother (#15105)
No longer suggests `&[i32]` or `&mut [i32]` instead of `&Vec<i32>` or
`&mut Vec<i32>` (also: `Path` and `PathBuf`, etc.) for the parameter
type when the parameter name starts with an underscore (or, if that does
not start with one, then a local `let` binding in the function body,
pointing to the same value, does) – (Fixes rust-lang/rust-clippy#13489,
fixes rust-lang/rust-clippy#13728)

~changelog: fix false positive: [`ptr_arg`] no longer triggers with
underscore binding to `&mut` argument~
changelog: fix false positive: [`ptr_arg`] no longer triggers with
underscore binding to `&T` or `&mut T` argument
*Edit:* This change has been extended to all references, not just
mutable ones. See [discussion below](#issuecomment-3006386877).
2025-07-16 15:37:28 +00:00
yanglsh
df529eb8cc fix: ptr_as_ptr suggests wrongly with turbo fish 2025-07-16 22:56:49 +08:00
yanglsh
8d941d22ba fix: never_loop forget to remove break in suggestion 2025-07-16 22:14:34 +08:00
Samuel Tardieu
b49e36041b
unsafe_derive_deserialize: do not consider pin!() as unsafe
In Rust 1.88, the `pin!()` macro uses `unsafe` and triggers
`unsafe_derive_deserialize`.
2025-07-16 11:59:51 +02:00
Philipp Krones
21943a9056
Don't trigger unused_trait_names in macros (#14947)
Closes rust-lang/rust-clippy#14924

changelog: [`unused_trait_names`] no longer triggers in macros
2025-07-16 09:10:54 +00:00
dianne
413f8db4a9 future-incompat lints: don't link to the nightly edition-guide version 2025-07-16 01:44:02 -07:00
yanglsh
038295adf8 fix: filter_map_bool_then wrongly showed macro definition in suggestions 2025-07-15 23:07:39 +08:00
Boot0x7c00
c20faa0512 fix needless_for_each suggests wrongly for macros 2025-07-15 03:02:06 +00:00
Michael Howell
bfc4d17864 Add more tests, clean up code 2025-07-14 17:19:23 -07:00
bors
f4b827abeb Auto merge of #143745 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update

r? `@Manishearth`

Cargo.lock update due to `ui_test` bump and restructure.
2025-07-14 19:53:18 +00:00
Samuel Tardieu
8d6de0b82e
Fix expect_fun_call producing invalid suggestions (#15122)
Previously expect_fun_call would too eagerly convert cases like
`foo.expect(if | block | match)` into `foo.unwrap_or_else`.
Additionally, it would also add to_string() even though the argument is
being passed into format!() which can accept a &str. I also discovered
some other cases where this lint would either produce invalid results,
or be triggered unnecessarily:

- Clippy would suggest changing expect to unwrap_or_else even if the
expression inside expect contains a return statement
- opt.expect(const_fn()) no longer triggers the lint
- The lint would always add braces to the closure body, even if the body
of expect is a single expression
- opt.expect({"literal"}) used to get turned into
```opt.unwrap_or_else(|| panic!("{}", {"literal"}.to_string()))```

Fixes rust-lang/rust-clippy#15056

changelog: [`expect_fun_call`]: fix expect_fun_call producing invalid
suggestions
2025-07-14 15:05:59 +00:00
Kamal Ahmad
fcd064da75 expect_fun_call: only lint const fn's if they're not inside a const context 2025-07-14 18:57:15 +05:00
Jake Goulding
ff1ae2b994 Reword mismatched-lifetime-syntaxes text based on feedback
Key changes include:

- Removal of the word "syntax" from the lint message. More accurately,
  it could have been something like "syntax group" or "syntax
  category", but avoiding it completely is easier.
- The primary lint message now reflects exactly which mismatch is
  occurring, instead of trying to be general. A new `help` line is
  general across the mismatch kinds.
- Suggestions have been reduced to be more minimal, no longer also
  changing non-idiomatic but unrelated aspects.
- Suggestion text no longer mentions changes when those changes don't
  occur in that specific suggestion.
2025-07-14 09:52:58 -04:00
immersum
75c330bb7f
Fix ptr_arg suggests changes when it's actually better not to bother
changelog: fix false positive: [`ptr_arg`] no longer triggers with
underscore binding to `&mut` argument
2025-07-14 15:00:27 +02:00
Jason Newcomb
1c64211aee
Fix manual is multiple of (#15205)
Fix several issues with `manual_is_multiple_of`

- `&a % &b == 0` compiles, but requires dereferencing `b` when replacing
with `a.is_multiple_of(b)`.
- In `a % b == 0`, if type of `a` is not certain, `a.is_multiple_of(b)`
might not be typable.
- In `a % b == 0`, `a` and `b` must be unsigned integers, not any
arbitrary types implementing `Rem` and outputing an integer.

Those fixes have required increasing the precision of type certainty
determination in the two first patches.

Fixes rust-lang/rust-clippy#15203
Fixes rust-lang/rust-clippy#15204

changelog: [`manual_is_multiple_of`]: fix various false positive
2025-07-14 08:33:27 +00:00
Samuel Tardieu
ba947c5728
Fix manual_assert suggests wrongly for macros (#15264)
Closes rust-lang/rust-clippy#15227

changelog: [`manual_assert`] fix wrong suggestions for macros
2025-07-14 07:55:25 +00:00
Jason Newcomb
d9acd919ad
fix false negative of expect_used (#15253)
Fixes: rust-lang/rust-clippy#15247

changelog: Fix the false negative of [`expect_used`] when metting
`Option::ok().expect`.
2025-07-14 07:52:48 +00:00