Commit graph

23130 commits

Author SHA1 Message Date
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
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
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
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
Boot0x7c00
c20faa0512 fix needless_for_each suggests wrongly for macros 2025-07-15 03:02:06 +00:00
Samuel Tardieu
ba8da7a8e8
useless_conversion: move all the impl to the same lint pass (#15274)
Needed to split the lints crate.

changelog: none
2025-07-14 22:33:14 +00:00
Jason Newcomb
7796773d3e useless_conversion: move all the impl to the same lint pass 2025-07-14 12:05:07 -04:00
Samuel Tardieu
fdf37fc7e7
ineffective_open_options: remove method_call use (#15271)
This is needed to split the lint crate.

changelog: none
2025-07-14 15:07:22 +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
Jason Newcomb
104e265b96 ineffective_open_options: don't subtract a constant BytePos 2025-07-14 10:57:27 -04: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
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
06e6927d55 ineffective_open_options: refactor, don't use method_call 2025-07-14 08:26:38 -04: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
Jason Newcomb
43f18915e9
Fix manual_abs_diff suggests wrongly behind refs (#15265)
Closes rust-lang/rust-clippy#15254

changelog: [`manual_abs_diff`] fix wrong suggestions behind refs
2025-07-14 07:33:52 +00:00
yanglsh
901ab5b8bd fix: manual_assert suggests wrongly for macros 2025-07-14 00:19:05 +08:00
Alejandra González
6f2567d16d
Update manual_is_variant_and documentation to include equality comparison (#15239)
Update `manual_is_variant_and` documentation to include equality
comparison patterns

This commit updates the documentation for the `manual_is_variant_and`
lint to include all linted cases. Previously, the documentation only
mentioned the `.map(f).unwrap_or_default()` pattern, but the lint also
catches equality comparison patterns like `option.map(f) == Some(true)`
and `result.map(f) == Ok(true)`.

changelog: [`manual_is_variant_and`]: Update documentation to include
equality comparison patterns

fixes rust-lang/rust-clippy#15217
2025-07-13 15:24:29 +00:00
Krishna Ketan Rai
b4fc33ae8b Lint: Improve manual_is_variant_and to support equality comparison
- Add equality pattern support to manual_is_variant_and
- Update documentation and Clippy manual
2025-07-13 19:51:45 +05:30
yanglsh
9d964048ec fix: manual_abs_diff suggests wrongly behind refs 2025-07-13 21:23:51 +08:00
Alejandra González
7e2d26f4b2
Fix approx_const for some new cases (#15236)
Fix some cases for `approx_const`:
- When the literal has more digits than significant ones, the string
comparison wasn't working
- When numbers are formatted in a non trivial way (with leading `0`s or
using `_`) the lint now finds those cases

changelog: [`approx_const`]: Fix when used over overly precise literals
and non trivially formatted numerals

Fixes rust-lang/rust-clippy#15194
2025-07-12 13:57:16 +00:00
Timo
3c3ee9bddb
{flat_,}map_identity: recognize |[x, y]| [x, y] as an identity function as well (#15229)
changelog: [`map_identity`,`flat_map_identity`]: also recognize `|[x,
y]| [x, y]`

fixes rust-lang/rust-clippy#15198
2025-07-12 13:10:23 +00:00
Ada Alakbarova
e610584a9a
{flat_,}map_identity: also recognize |[x, y]| [x, y] 2025-07-12 14:02:41 +02:00
Ada Alakbarova
415438718c
Use Ty::is_fn instead of manually matching on TyKind 2025-07-12 13:34:32 +02:00
dswij
3d7188d06d
Add uninlined_format_args example for {:?} (#15228)
Before this, you had to guess how to fix a `{:?}` formatting argument. I
have happened to guess `{:?var}` in the past, got frustrated, and
disabled the lint. This additional example would have saved me a bit of
trouble.

changelog: [`uninlined_format_args`]: added an example of how to fix a
`{:?}` parameter.
2025-07-12 06:20:15 +00:00
Teodoro Freund
093b6e5de9 Fix approx_const for some new cases
Improved naming and comment
2025-07-12 07:16:23 +01:00
relaxcn
1d1b97d514 fix false negative of expect_used 2025-07-12 01:44:55 +08:00
Samuel Tardieu
d5b10f0c7e
Use $RUSTC instead of rustc to get version if var is available 2025-07-11 14:22:23 +02:00
Samuel Tardieu
e2270bb9e5
Reduce clippy lints page size (#15235)
Follow-up of https://github.com/rust-lang/rust-clippy/pull/15208.

Removed some unneeded wrappings and shortened some CSS class name.

The diff is big because of one indent level getting removed. :-/

Before this PR: 1751301
With this PR: 1663634
Reduction: -5%

r? @samueltardieu

changelog: Reduce page size and number of DOM elements on clippy lints
page
2025-07-11 05:36:30 +00:00
Samuel Tardieu
488f4dd04d
fix legacy_numeric_constants suggestion when call is wrapped in parens (#15191)
Fixes rust-lang/rust-clippy#15008

changelog: [`legacy_numeric_constants`]: fix suggestion when call is
inside parentheses like `(i32::max_value())`
2025-07-11 05:28:23 +00:00
Alejandra González
b5e701efc5
arithmetic_side_effects: don't warn on NonZeroU*.get() - 1 (#15238)
changelog: [`arithmetic_side_effects`]: don't warn on `NonZeroU*.get() -
1`

fixes rust-lang/rust-clippy#15225
2025-07-10 22:57:30 +00:00
Ada Alakbarova
a745e2cae3
fix(arithmetic_side_effects): don't warn on NonZeroU*.get() - 1 2025-07-11 00:40:38 +02:00
llogiq
df5a0ee919
or_fun_call: lint method calls inside map_or first arg (#15074)
<strike>blocked on rust-lang/rust-clippy#15073</strike>

Lint method calls inside `map_or` too, so for this, lint will be showed:
```rust
Some(4).map_or("asd".to_string().len() as i32, f);
```
previously it worked only for:
```rust
Some(4).map_or(slow_fun(), f);
```

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

Sorry for multiple `or_fun_call` PRs.

changelog: [`or_fun_call`]: lint method calls inside map_or first arg
2025-07-10 21:27:09 +00:00