23725 Commits

Author SHA1 Message Date
Manish Goregaokar
e1130b694a
fix option_if_let_else when Err variant is ignored (#14429)
This fixes an issue where clippy suggests passing a function that takes
no arguments as the first argument of `Result::map_or_else`. The
function needs to take one argument. Example that triggers the issue:
[Playground
link](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=0b6f9bc7b6ab4dcd26745065544e0b8a)

Fixes #10335.

changelog: [`option_if_let_else`]: fix incorrect suggestion when the
contents of an `Err` variant are ignored
2025-09-18 05:00:41 +00:00
Daniel Gulotta
15ce2093d5 test cases for option_if_let_else 2025-09-17 20:39:20 -07:00
Jason Newcomb
a67fe9c35d
Do not look for Cargo.toml inside target (#15692)
This test, which checks that we do not define new profiles directly in
Clippy's multiple `Cargo.toml` files, must not look inside `target` as
`lintcheck` might place some third-party sources there. Of course those
third-party sources are allowed to define profiles in their
`Cargo.toml`.

changelog: none
2025-09-17 23:31:32 +00:00
Samuel Tardieu
7a5f0bdd5d
Remove jujutsu directory from search tools. (#15695)
This prevents ripgrep from searching the directory by default.

changelog: none
2025-09-17 21:36:50 +00:00
Jason Newcomb
80db273b64 Remove jujutsu directory from search tools. 2025-09-17 16:34:12 -04:00
Alex Macleod
90d0085ff4
match_as_ref: do not lint if other arm is not None => None (#15693)
Fixes rust-lang/rust-clippy#15691

changelog: [`match_as_ref`]: do not lint if other arm is not `None =>
None`
2025-09-17 17:56:20 +00:00
Samuel Tardieu
d457260ee2
suggestion for rest_pat_in_fully_bound_structs (#15648)
changelog: [`rest_pat_in_fully_bound_structs`]: add suggestion
2025-09-17 17:43:12 +00:00
Samuel Tardieu
c1f782919b
match_as_ref: do not lint if other arm is not None => None 2025-09-17 19:35:05 +02:00
Samuel Tardieu
e84b5ca1dd
Do not look for Cargo.toml inside target
This test, which checks that we do not define new profiles directly in
Clippy's multiple `Cargo.toml` files, must not look inside `target` as
`lintcheck` might place some third-party sources there. Of course those
third-party sources are allowed to define profiles in their `Cargo.toml`.
2025-09-17 18:56:25 +02:00
Alex Macleod
55570c9b25
Fix unnecessary_unwrap false negative (#12295) (#15689)
Fix `unnecessary_unwrap` false negative when unwrapping a known value
inside a macro call

Fixes rust-lang/rust-clippy#12295
Produces no changes to `lintcheck`

changelog: [`unnecessary_unwrap`]: Fix false negative when unwrapping a
known value inside a macro call

I made sue to run `cargo dev fmt`.
I also ran the following checks (in order) on a fresh clone of mi fork:
1. `cargo build`
2. `cargo test`
3. `cargo lintcheck`

Running `cargo test` after `lintcheck` causes a test to fail, but this
also happens on a clean fork without my changes
2025-09-17 15:03:50 +00:00
dswij
f37b9c05ef
fix(transmute_ptr_to_ref): don't suggest .cast when to-type is DST (#15621)
Fixes https://github.com/rust-lang/rust-clippy/issues/13357

Determining the exact placement of the `if !to_ref_ty.is_sized()`s
required meticulously constructing the suggestion/truth table of
`is_sized`, `msrv.meets` and `has_erased_regions`. The test cases should
hopefully cover all the new combinations.

changelog: [`transmute_ptr_to_ref`]: don't suggest `.cast` when to-type
is DST
2025-09-17 13:41:48 +00:00
galileocap
19e5286c80
Fix unnecessary_unwrap false negative when unwrapping a known value inside a macro call
Fixes https://github.com/rust-lang/rust-clippy/issues/12295

changelog: [`unnecessary_unwrap`]: Fix false negative when unwrapping a known value inside a macro call
2025-09-16 19:20:39 -03:00
Philipp Krones
49ae1d415d
Changelog for Clippy 1.90 🍂 (#15670)
Violets are red,
Roses are blue,
As September leaves turn,
Let what's old become new.

-----

Meet George @DaBs's little (de)bugger, our winner at
rust-lang/rust-clippy#15375

![cat](https://github.com/user-attachments/assets/ae5877bb-4a5e-4490-aea6-de961627f097)

-----

Cats for the next release can be traditionally nominated in the
comments.
Thanks @blyxyas for organizing the previous votes.

changelog: none

r? flip1995
2025-09-16 17:25:44 +00:00
Jason Newcomb
2a6197e375
Recognize canonical ? pattern with Result (#15680)
This recognizes the following expression as being equivalent to the
question mark:

```rust
match x {
    Ok(v) => v,
    Err(e) => return Err(e.into()), // or `Into::into(x)` or `<T as Into<U>>::into(x)`
}
```

Fixes rust-lang/rust-clippy#15679

changelog: [`question_mark`]: recognizes a match with an early return
with a call to `.into()` as possibly equivalent to a question mark
2025-09-16 01:08:21 +00:00
Samuel Tardieu
c4da39cca3
Recognize canonical ? pattern with Result 2025-09-15 19:17:32 +02:00
Alexey Semenyuk
8af6638666
Changelog for Clippy 1.90 2025-09-14 20:16:51 +05:00
Samuel Tardieu
7a12684741
Refactor ptr_offset_with_cast (#15613)
Putting this lint in `/methods` is simpler and probably slightly more
efficient.

changelog: [`ptr_offset_with_cast`]: respect MSRV when suggesting fix,
and lint even more cases
2025-09-14 15:01:46 +00:00
Folkert de Vries
f981739fcf
refactor ptr_offset_with_cast 2025-09-14 16:49:18 +02:00
Samuel Tardieu
e7421ccb1a
fix(elidable_lifetime_names): avoid overlapping spans in suggestions (#15667)
Fixes https://github.com/rust-lang/rust-clippy/issues/14157
Fixes https://github.com/rust-lang/rust-clippy/issues/15666

changelog: [`elidable_lifetime_names`]: avoid overlapping spans in
suggestions

r? clippy
2025-09-14 10:06:50 +00:00
Ada Alakbarova
25881bfc34
fix(elidable_lifetime_names): avoid overlapping spans in suggestions 2025-09-14 11:31:23 +02:00
dswij
181034735b
Remove unnecessary #![allow] in test (#15675)
Noticed while working on rust-lang/rust-clippy#15673.

changelog: none
2025-09-14 08:33:46 +00:00
Samuel Tardieu
cb286b4479
fix(multiple_unsafe_ops_per_block): ignore unsafe ops from .await desugaring (#15654)
Fixes https://github.com/rust-lang/rust-clippy/issues/13879

changelog: [`multiple_unsafe_ops_per_block`]: ignore unsafe ops from
`.await` desugaring
2025-09-14 07:17:04 +00:00
Samuel Tardieu
074bff027e
Remove unnecessary #![allow] in test 2025-09-14 09:08:46 +02:00
Jason Newcomb
adcd2defc7
Implement Debug for SourceText (#15672)
This is useful for using it with `dbg!()`.

changelog: none
r? Jarcho
2025-09-14 02:51:32 +00:00
Samuel Tardieu
cd196aa72a
Implement Debug for SourceText
This is useful for using it with `dbg!()`.
2025-09-13 20:56:52 +02:00
Alejandra González
544e24a79f
Remove expect collapsible_span_lint_calls and use span_lint_and_help (#15612)
Remove expected `collapsible_span_lint_calls` and use
`span_lint_and_help` since rust-lang/rust-clippy#7698 was resolved

changelog:none
2025-09-13 15:46:38 +00:00
Samuel Tardieu
0c87db2449
fix(needless_return): FP with cfgd code after return (#15669)
Fixes https://github.com/rust-lang/rust-clippy/issues/14474

changelog: [`needless_return`]: FP with `cfg`d code after `return`
2025-09-13 11:04:21 +00:00
Ada Alakbarova
6f3f1f3aa7
fix(needless_return): FP with cfgd code after return 2025-09-13 12:24:01 +02:00
Samuel Tardieu
1d0582a0e2
refactor: split return lints into separate modules (#15646)
decided to put each lint extraction into a separate commit this time --
do let me know if you prefer all of that being in a single commit
instead

changelog: none
2025-09-13 10:03:55 +00:00
Ada Alakbarova
51ee8d8f0e
split returns module 2025-09-13 11:53:04 +02:00
Ada Alakbarova
af82c3db6c
tiny clean-up 2025-09-13 11:53:04 +02:00
Samuel Tardieu
472768ad5e
fix(ref_option): don't lint in external and proc-macros (#15668)
Fixes https://github.com/rust-lang/rust-clippy/issues/14063

changelog: [`ref_option`]: don't lint in external and proc-macros
2025-09-13 09:42:13 +00:00
Ada Alakbarova
b901ba725e
fix(ref_option): don't lint in external and proc-macros 2025-09-13 11:29:24 +02:00
Ada Alakbarova
25cf36ac78
clean-up
- move tests to `ui-toml/`, since they all use `clippy.toml`
- remove the trait test case from `ref_option.rs`, because it's already
  covered by `ref_option_traits.rs`
2025-09-13 11:29:24 +02:00
Ada Alakbarova
382c964f3e
small clean-up 2025-09-13 00:34:17 +02:00
Valdemar Erk
8f84324ec9 autofix for rest_pat_in_fully_bound_structs 2025-09-12 20:30:38 +02:00
Samuel Tardieu
9f02cbc7a8
clippy_utils: make peel_*_ty_refs class of functions a bit more consistent (#15515)
I was looking for the function that peels refs from a type while also
returning the number of refs peeled, and it turns out there were
actually two of them?? I removed the by far less popular one, and made
some other clean-up along the way

changelog: none
2025-09-12 16:54:00 +00:00
Samuel Tardieu
601ddccd57
fix(use_self): don't early-return if the outer type has no lifetimes (#15611)
Fixes https://github.com/rust-lang/rust-clippy/issues/13277

Unfortunately breaks another case, which has only been working thanks to
the now fixed bug -- see last commit.

changelog: [`use_self`]: don't early-return if the outer type has no
lifetimes
2025-09-12 16:33:40 +00:00
Ada Alakbarova
da6d23b116
fix: ignore unsafe ops from .await desugaring 2025-09-12 18:23:29 +02:00
Ada Alakbarova
8938bb268d
clean-up tests 2025-09-12 18:21:36 +02:00
Ada Alakbarova
31c7e621c2
reorganize peel_*_ty_refs functions
- give `ty::walk_ptrs_hir_ty` a more standard name
  `peel_hir_ty_refs_and_ptrs`
- move it out of `ty`, since that's for `middle::ty::Ty`

- remove `ty::walk_ptrs_ty_depth` for equivalent `peel_middle_ty_refs`
- rename the latter into `ty::peel_and_count_ty_refs`
- incorporate mutability tracking (from
  `ty::peel_mid_ty_refs_is_mutable`) into that
2025-09-12 18:13:20 +02:00
Ada Alakbarova
68a3adad2a
other clean-up 2025-09-12 17:54:38 +02:00
Samuel Tardieu
8ca5332b10
Fix invalid_upcast_comparisons wrongly unmangled macros (#15663)
Closes rust-lang/rust-clippy#15662

changelog: [`invalid_upcast_comparisons`] fix wrong unmangle of macros
2025-09-12 15:21:12 +00:00
Alex Macleod
af7fa538c6
Fix as_underscore to only suggest when it's suggestable (#15652)
Have `as_underscore` only make a suggestion when the type is
suggestable.

changelog: [`as_underscore`]: Don't suggest a fix if the type is not
suggestable

Fixes rust-lang/rust-clippy#15282
2025-09-12 13:28:28 +00:00
Teodoro Freund
745b79097f Only suggest type in as_underscore when it's suggestable 2025-09-12 07:57:16 +01:00
yanglsh
066a9794df fix: invalid_upcast_comparisons wrongly unmangled macros 2025-09-12 09:09:44 +08:00
Jason Newcomb
c057abd268
Add suggestion to cast_sign_loss and cast_possible_wrap using the cast_{un,}signed() methods (#15384)
changelog: [`cast_sign_loss`, `cast_possible_wrap`]: add suggestion
using `cast_{un,}signed()` methods

Fixes rust-lang/rust-clippy#14150

This PR adds a suggestion to `cast_sign_loss` and `cast_possible_wrap`,
which fixes reported warnings using the `cast_{un,}signed()` methods, as
proposed in rust-lang/rust-clippy#14150. Suggestions are only made if
MSRV is >=1.87.

Also, I'm not 100% sure about the suggestion message yet. I'm open for
suggestions.
2025-09-11 19:58:54 +00:00
Timo
467efe0cf6
fix(len_zero): don't eagerly call GenericArgs::type_at (#15660)
Fixes https://github.com/rust-lang/rust-clippy/issues/15657

changelog: [`len_zero`]: fix ICE when `fn len` has a return type without
generic type params

r? @y21
2025-09-11 19:08:08 +00:00
Jason Newcomb
990aaf684d
refactor: split derive lints into separate modules (#15622)
changelog: none
2025-09-11 18:52:42 +00:00
dswij
077d11606d
fix(needless_closure): don't lint on AsyncFn*s (#15649)
Fixes https://github.com/rust-lang/rust-clippy/issues/13892

changelog: [`needless_closure`]: don't lint on `AsyncFn`s
2025-09-11 18:42:54 +00:00