Commit graph

23162 commits

Author SHA1 Message Date
lolbinarycat
a19b46d745
fix markdown
Co-authored-by: Philipp Krones <hello@philkrones.com>
2025-07-24 14:10:12 -05:00
binarycat
6017fe6596 expand the issue template for new lints
When I first tried contributing to clippy,
I encountered the problem that a lot of lint suggestions overlapped
with existing lints, so I would spend a bunch of time implementing
something only to figure out it wasn't actually needed.

The "comparison with existing lints" field should hopefully reduce
this somewhat, while not incresing the burden of
requesting a new lint too much due to not being mandatory.
2025-07-24 12:31:41 -05:00
Timo
7d5833fd84
Correct help message for arc_with_non_send_sync (#15332)
Small typo fix for the `arc_with_non_send_sync` lint.

changelog: none
2025-07-24 10:28:48 +00: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
yanglsh
bebae76f23 fix: module_name_repetitions FP on exported macros 2025-07-21 21:49:41 +08:00
Timo
d4dea4bbe7
Fix false positive in useless_attribute with redundant_imports (#15318)
Fix false positive in `useless_attribute` with `redundant_imports`

Add `redundant_imports` to the list of allowed lints on use items to
prevent
`useless_attribute` from triggering false positives when
`#[expect(redundant_imports)]`
or similar attributes are used on use statements.

fixes rust-lang/rust-clippy#15316

---

changelog: [`useless_attribute`]: fix false positive when using
`#[expect(redundant_imports)]` and similar lint attributes on `use`
statements
2025-07-21 11:53:28 +00: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
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
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
Alex Macleod
b916841ccc
Remove unused option None for LEVEL_FILTERS_DEFAULT (#15315)
Take to account that we don't have lints under under `None` for
`LEVEL_FILTERS_DEFAULT` so far
https://rust-lang.github.io/rust-clippy/master/index.html?levels=none,
we can remove it.

changelog: none
2025-07-19 12:20:34 +00:00
yanglsh
6cf00e9490 fix: needless_range_loop FP on array literals 2025-07-19 19:38:25 +08:00
Alexey Semenyuk
048a64a214 Remove unused option fir LEVEL_FILTERS_DEFAULT 2025-07-19 16:29:16 +05:00
dswij
5acb1d432a
Fix empty_with_brackets span handling (#15311)
This is blocking rust-lang/rust-clippy#14724

changelog: none
2025-07-19 06:36:44 +00:00
Jason Newcomb
ae8ff77d00
Warn about const instability wrt MSRV (#15297)
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.

~~It includes the content of PR rust-lang/rust-clippy#15296 as its first
commit. I separated them because this one is more complex, and
rust-lang/rust-clippy#15296 may be merged more rapidly.~~

changelog: [`incompatible_msrv`]: check the right MSRV when in a `const`
context

r? Jarcho @rustbot label +C-bug +I-false-negative
2025-07-18 19:11:27 +00:00
Jason Newcomb
cca924bf9f Simplify must_use_candidate spans. 2025-07-18 14:44:17 -04:00
Jason Newcomb
1df3b96e8b Fix empty_with_brackets span handling. 2025-07-18 10:59:43 -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
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
Jason Newcomb
e62e27bf5b
Warn about types not meeting MSRV (#15296)
For example, the `Duration` type from the standard library was only
introduced in Rust 1.3.0.

changelog: [`incompatible_msrv`]: recognize types exceeding MSRV as well

r? Jarcho @rustbot label +C-bug +I-false-negative
2025-07-17 12:31:15 +00: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
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
dswij
2a4c83dcc1
Move uninlined_format_args to pedantic (#15287)
Fixes https://github.com/rust-lang/rust-clippy/issues/15151

See also
https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/uninlined_format_args.20is.20contentious/

changelog: Move [`uninlined_format_args`] to `pedantic`
2025-07-16 15:50:38 +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
041a0f633d
Get myself off assignment rotation (#15288)
I'll be mostly AFK starting on Friday for about one week.

changelog: none
2025-07-16 13:33:00 +00:00
Samuel Tardieu
39a1d52137
Get myself off assignment rotation 2025-07-16 15:27:16 +02:00
Alex Macleod
32263f5fe1 Move uninlined_format_args to pedantic 2025-07-16 12:30:52 +00:00
Samuel Tardieu
ad97abcad8
unsafe_derive_deserialize: do not consider pin!() as unsafe (#15137)
In Rust 1.88, the `pin!()` macro uses `unsafe` and triggers
`unsafe_derive_deserialize`.

Fixes rust-lang/rust-clippy#15120

changelog: [`unsafe_derive_deserialize`]: do not trigger because of the
standard library's `pin!()` macro
2025-07-16 10:04:39 +00: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
Philipp Krones
ae1d3aea41
Use $RUSTC instead of rustc to get version if var is available (#15250)
Fixes rust-lang/rust-clippy#15249

For the builtin rustc, it should return "dev" as the release channel.
Clippy tests pass with this patch in both the Clippy standalone
repository and from within the compiler repository.

changelog: none
2025-07-15 18:51:39 +00:00
yanglsh
038295adf8 fix: filter_map_bool_then wrongly showed macro definition in suggestions 2025-07-15 23:07:39 +08:00
Alex Macleod
fc441986b4
Use Ty::is_fn instead of manually matching on TyKind (#15089)
just makes the code a bit more concise

changelog: none
2025-07-15 14:12:13 +00:00
Samuel Tardieu
e1be06240d
gh-pages: reduce page size by skipping spaces (#15278)
This removes preserved spaces after lint name, marginally reducing page
size.
Changing `~}}` into `-}}` will break things: lint name will touch copy
buttons on it's right side.

cc @GuillaumeGomez as one who touched this last time

changelog: none
2025-07-15 13:03:50 +00:00
klensy
016e53480c gh-pages: reduce page size by skipping spaces 2025-07-15 15:42:23 +03:00
Jason Newcomb
0bf4d5a617
fix suggestion causes error of needless_for_each (#15262)
Fixes: rust-lang/rust-clippy#15256

changelog: fix suggestion causes error of [`needless_for_each`] when the
`body.value` comes from macro expansion.
2025-07-15 07:06:10 +00:00