Commit graph

24672 commits

Author SHA1 Message Date
Samuel Tardieu
669fbcb478
Fix map_unwrap_or fail to cover Result::unwrap_or (#15718)
Closes rust-lang/rust-clippy#15713
Closes rust-lang/rust-clippy#15714
Closes rust-lang/rust-clippy#15752
Closes rust-lang/rust-clippy#16258

changelog: [`map_unwrap_or`] add cover for `Result::unwrap_or`
2026-01-11 08:42:56 +00:00
llogiq
bcd52c1150
overhaul int_plus_one (#16373)
- add missing tests and fix previously uncaught regressions
- respect reduced applicability
- simplify lint logic

changelog: [`int_plus_one`]: respect reduced applicability
changelog: [`int_plus_one`]: fix FN with negative literals, e.g. `-1 + x
<= y`
2026-01-11 06:35:12 +00:00
Ada Alakbarova
e4dd947523
introduce Self::as_x_{plus,minus}_one
reduces duplication
2026-01-10 19:57:28 +01:00
llogiq
8bd0931bb5
refactor(suspicious_to_owned): improve lint messages (#16376)
changelog: [`suspicious_to_owned`]: improve lint messages
2026-01-10 15:24:45 +00:00
Ada Alakbarova
f228056c64
improve lint messages
- only mention the type once
- put types in backticks
- only highlight the method name in the suggestion
  - removes the need for a snippet
  - makes for finer diffs (seen through `cargo dev lint`)
2026-01-10 14:13:21 +01:00
Ada Alakbarova
9eb4d7c56e
remove no-rustfix
the suggestions are no longer overlapping?..
2026-01-10 13:58:47 +01:00
Samuel Tardieu
536682425d
refactor(floating_point_arithmetic): split each check into a separate module (#16367)
changelog: none
2026-01-10 12:53:57 +00:00
Samuel Tardieu
5ebb32296f
fix(useless_conversion): respect reduced applicability (#16372)
changelog: [`useless_conversion`]: respect reduced applicability
2026-01-10 12:51:07 +00:00
Samuel Tardieu
b94106a9cd
fix clippy_utils::std_or_core(_) (#16374)
While working on rust-lang/rust-clippy#16368, I found that this function
doesn't work correctly, presumably because the author was befuddled with
the negation.

r? @samueltardieu

---

changelog: none
2026-01-09 22:44:06 +00:00
Andre Bogus
ea591b55f4
fix clippy_utils::std_or_core(_) 2026-01-09 23:15:06 +01:00
Ada Alakbarova
ccaa2fa984
fix: respect reduced applicability
By building the whole suggestion in `emit_suggestion`, we avoid the need
to thread `Applicability` through `check_binop` into
`generate_suggestion`
2026-01-09 22:54:35 +01:00
Ada Alakbarova
d554092c27
get rid of Side 2026-01-09 22:38:58 +01:00
Ada Alakbarova
df65d1a6a8
introduce LeOrGe
removes the need for a wildcard match
2026-01-09 22:38:58 +01:00
Ada Alakbarova
0180ec4d5d
fix: negative literals are not literals 2026-01-09 22:38:58 +01:00
Ada Alakbarova
3ec7666a2a
clean-up 2026-01-09 22:38:58 +01:00
llogiq
11fe0c69b4
Fix LimitStack::pop_atr in release builds (#16371)
in `LimitStack::pop_atr` always call `stack.pop()`.
It used to only be called inside a `debug_assert!` so the stack was not
popped in release builds.

Running `TESTNAME=cognitive_complexity cargo uitest --release` used to
print
```
error: there was 1 unmatched diagnostic
   --> tests/ui/cognitive_complexity.rs:121:4
    |
121 | fn bloo() {
    |    ^^^^ Error[clippy::cognitive_complexity]: the function has a cognitive complexity
 of (2/1)
    |
```

The first commit adds to the ui test, which also fails in release, the
2nd commit fixes the tests.

changelog: [`cognitive_complexity`]: fix attribute stack not popping in
release builds
2026-01-09 20:14:30 +00:00
Ada Alakbarova
f73e504eea
fix(useless_conversion): respect reduced applicability 2026-01-09 20:20:35 +01:00
Samuel Tardieu
331a474142
Add new duration_suboptimal_units lint (#16250)
`Duration::from_mins` and `Duration::from_hours` where [recently
stabilized](https://github.com/rust-lang/rust/issues/140881) in Rust
1.91.0.

In our codebase we often times have things like

```rust
Duration::from_secs(5 * 60);
// Since Rust 1.91.0 one can use
Duration::from_mins(5)
```

During the Rust 1.91.0 bump I noticed we can finally switch to
`Duration::from_mins(5)`, but many users might not be aware of this. I
started manually updating the places, but halfway through I figured
"Can't a lint do this for me?", so I added exactly that in this PR. It
does it for all stabilized `from_XXX` time units.

changelog: Add new [`duration_suboptimal_units`] lint
Closes rust-lang/rust-clippy#16335
2026-01-09 16:08:40 +00:00
Sebastian Bernauer
0946c867a8
Add new duration_suboptimal_units lint 2026-01-09 16:40:04 +01:00
Wonko
13b82eb615
Fix LimitStack::pop_attrs in release mode
The `LimitStack::pop_attrs` function used to pop from the stack in
`debug_assert_eq!` and check the value. The `pop` operation was therefore
only executed in debug builds, leading to an unbalanced stack in
release builds when attributes were present.

This change ensures the `pop` operation is always executed, by moving
it out of the debug-only assertion. The assertion is kept for debug
builds.

changelog: fix unbalanced stack in attributes
2026-01-09 15:21:02 +01:00
Wonko
b022edce93
add test for unstacking cognitive_complexity= attribute 2026-01-09 15:17:06 +01:00
Jason Newcomb
0a83962264
chore(unnecessary_sort_by): small fixes and clean-up (#16350)
changelog: [`unnecessary_sort_by`]: respect applicability reduction due
to `Sugg`
changelog: [`unnecessary_sort_by`]: don't lint if `std` or `core` are
required for a suggestion but unavailable
2026-01-09 13:07:35 +00:00
Jason Newcomb
92608aae43
fix(float_point_arithmetic): respect reduced applicability (#16366)
changelog: [`float_point_arithmetic`]: respect reduced applicability
2026-01-09 13:05:18 +00:00
Jason Newcomb
ea21831bec
Do not warn on arithmetic side effect for String+String (#16358)
The previous fix only handled `String`+`str`.

changelog: [`arithmetic_side_effects`]: do not warn on `String` +
`String`

Fixes rust-lang/rust-clippy#14054 (for good hopefully)
2026-01-09 13:02:03 +00:00
Samuel Tardieu
b4dea7c1c8
transmuting_null: Add checks for without_provenance and without_provenance_mut (#16336)
changelog: [`transmuting_null`]: now checks for
[`ptr::without_provenance`](https://doc.rust-lang.org/core/ptr/fn.without_provenance.html)
and
[`ptr::without_provenance_mut`](https://doc.rust-lang.org/core/ptr/fn.without_provenance_mut.html)
which create null pointers
2026-01-09 10:59:07 +00:00
Coca
7d0b1e1449
transmuting_null: Add checks for without_provenance and without_provenance_mut
Currently `without_provenance`/`without_provenance_mut` do not have a `rustc_diagnostic_item` so this change is dependent on them being added before being ready to be used.

changelog: [`transmuting_null`]: now checks for [`ptr::without_provenance`](https://doc.rust-lang.org/core/ptr/fn.without_provenance.html) and [`ptr::without_provenance_mut`](https://doc.rust-lang.org/core/ptr/fn.without_provenance_mut.html) which create null pointers
2026-01-09 07:36:11 +00:00
Ada Alakbarova
44a41041fc
extract each check into a separate module 2026-01-08 23:08:17 +01:00
Ada Alakbarova
7a377d6672
move floating_point_arithmetic.rs to floating_point_arithmetic/mod.rs 2026-01-08 23:07:57 +01:00
Ada Alakbarova
cb9a079f60
fix(float_point_arithmetic): respect reduced applicability 2026-01-08 22:53:25 +01:00
Ada Alakbarova
d0d725133f
clean-up 2026-01-08 22:50:53 +01:00
llogiq
500e0ff187
Fix unnecessary_to_owned wrongly unmangled macros (#16354)
Closes rust-lang/rust-clippy#16351

changelog: [`unnecessary_to_owned`] fix wrongly unmangled macros
2026-01-08 20:24:49 +00:00
Jason Newcomb
adade16144
A return in an iterator closure should not trigger never_loop (#16364)
The iterator never loops when the closure used in, e.g., `.any()`,
panics, not when it diverges as a regular `return` lets the iterator
continue.

changelog: [`never_loop`]: do not consider `return` as preventing the
iterator from looping

Fixes rust-lang/rust-clippy#16363

r? @Jarcho
2026-01-08 19:34:23 +00:00
Samuel Tardieu
1a5bb37fb6
fix(single_range_in_vec_init): don't apply the suggestion automatically (#16365)
Fixes https://github.com/rust-lang/rust-clippy/issues/16306

changelog: [`single_range_in_vec_init`]: don't apply the suggestion
automatically
2026-01-08 19:16:47 +00:00
Ada Alakbarova
156b08184e
fix(single_range_in_vec_init): don't apply the suggestion automatically 2026-01-08 20:04:50 +01:00
Ada Alakbarova
bdb1050a0f
fix: don't lint if std or core are required for a suggestion but unavailable 2026-01-08 19:45:55 +01:00
Samuel Tardieu
68365697b3
A return in an iterator closure should not trigger never_loop
The iterator never loops when the closure used in, e.g., `.any()`,
panics, not when it diverges as a regular `return` lets the iterator
continue.
2026-01-08 19:45:49 +01:00
Ada Alakbarova
0cfc4ee541
fix: respect applicability reduction due to Sugg
By postponing the creation of `Sugg`s, we can properly account for their
effect on applicability
2026-01-08 19:40:50 +01:00
Ada Alakbarova
a4f0937a9a
clean-up 2026-01-08 19:40:50 +01:00
Philipp Krones
3b282feee6
Rustup (#16361)
r? @ghost

changelog: none
2026-01-08 17:41:55 +00:00
Philipp Krones
5356be04a8
Bump nightly version -> 2026-01-08 2026-01-08 18:36:51 +01:00
Philipp Krones
3fac496339
Merge remote-tracking branch 'upstream/master' into rustup 2026-01-08 18:36:44 +01:00
Samuel Tardieu
331f75f4a7
Do not warn on arithmetic side effect for String+String
The previous fix only handled `String`+`str`.
2026-01-08 16:42:25 +01:00
Jason Newcomb
bcf3c08230
Improve useless_conversion .into_iter() suggestion for nested references (#16238)
### Description
I updated the `useless_conversion` lint to stop applying adjustment
prefixes once it reaches the final target type.

Previously, the lint would continue applying adjustments even after the
type requirements were met, which often resulted in over-borrowed
suggestions like `&**y`. By breaking the loop early once the target type
is reached, we now emit the minimal, idiomatic suggestion (e.g., `*y`).

fixes rust-lang/rust-clippy#14847

### Test Plan
I added a targeted UI regression test: `tests/ui/useless_conversion.rs`.
This covers `.into_iter()` usage on nested slice references (`&&[T]`)
and verifies that Clippy now suggests `*items` instead of the previous
incorrect suggestion.

### Checklist

- [x] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Run `cargo dev fmt`

[lint_naming]:
https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

---

changelog: [`useless_conversion`]: refine `.into_iter()` suggestions to
stop at the final target type (fixing over-borrowed suggestions like
`&**y`)
2026-01-08 12:03:36 +00:00
Jason Newcomb
327c55852c
missing_enforced_import_rename: Do not enforce for underscores (#16352)
Fixes rust-lang/rust-clippy#16150 , do not error when importing
anonymously using an underscore.

In the issue it is suggested that perhaps there could be a flag to
enable/disable this new behavior, but I don't see a strong case for
disallowing "as _" when a rename was specified.

Please let me know if you think that flag would be useful and I can
implement that on top.

```
changelog: [`missing_enforced_import_rename`]: do not enforce renaming consistency in the case "import ... as _;"
```
2026-01-08 08:10:31 +00:00
Jason Newcomb
9302f1bd7b
More fixes for handling of macros (#16337)
Closes rust-lang/rust-clippy#16340
Continuation of rust-lang/rust-clippy#16296

More fixes for handling macros

changelog: [`string_from_utf8_as_bytes`] fix wrongly unmangled macros
changelog: [`redundant_pattern_matching`] fix wrongly unmangled macros
changelog: [`unnecessary_fold`] fix wrongly unmangled macros
changelog: [`match_as_ref`] fix wrongly unmangled macros
changelog: [`match_bool`] fix wrongly unmangled macros
changelog: [`match_ok_err`] fix wrongly unmangled macros
changelog: [`for_kv_map`] fix wrongly unmangled macros
changelog: [`question_mark`] fix wrongly unmangled macros
changelog: [`iter_kv_map`] fix wrongly unmangled macros
changelog: [`mutex_atomic`] fix wrongly unmangled macros

Maybe we should create an internal lint for this?
2026-01-08 08:06:48 +00:00
Linshu Yang
ac0b17bcf9 fix: unnecessary_to_owned wrongly unmangled macros 2026-01-07 22:32:16 +00:00
yanglsh
0db25dbd9d fix: map_unwrap_or suggests wrongly for empty slice 2026-01-07 22:06:52 +00:00
Linshu Yang
8c129e4219 fix: mutex_atomic wrongly unmangled macros 2026-01-07 19:00:45 +00:00
Linshu Yang
108436c6f9 fix: iter_kv_map wrongly unmangled macros 2026-01-07 19:00:45 +00:00
Linshu Yang
209e4d7d85 fix: question_mark wrongly unmangled macros 2026-01-07 19:00:44 +00:00