Commit graph

24491 commits

Author SHA1 Message Date
dswij
f245d85a2f
transmuting_null: Check const integer casts (#16227)
Additionally removed the comment about MIR const propagation as it is
now outdated

changelog: [`transmuting_null`]: now checks const integers being casted
to pointers
2025-12-18 15:43:05 +00:00
llogiq
741b684c90
New lint - same_length_and_capacity (#15656)
Fixes rust-lang/rust-clippy#5955

I understand that there's a feature freeze right now. I had started
working on this before I was aware of the feature freeze. I don't mind
waiting as long as I need to for feedback.

changelog: [`same_length_and_capacity`]: adds a new lint that checks for
usages of `from_raw_parts` where the same expression is passed for the
length and the capacity

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

-
[Feature-freeze](https://github.com/rust-lang/rust-clippy/pull/15656#issuecomment-3276620004)
by [github-actions[bot]](https://github.com/github-actions[bot])

*Managed by `@rustbot`—see
[help](https://forge.rust-lang.org/triagebot/note.html) for details*

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
2025-12-18 13:55:44 +00:00
llogiq
6110c8074a
Fix needless_type_cast suggesting invalid code for non-literal initializers (#16248)
When the initializer is a function call or suffixed literal (e.g.,
`size_of::<T>()` or `10u8`), suggest casting the initializer too, since
changing only the type annotation would fail to compile. Fixes
rust-lang/rust-clippy#16240

```
changelog: [`needless_type_cast`]: Fix suggesting invalid code for non-literal initializers
```
2025-12-18 07:03:43 +00:00
Samuel Onoja
0f17de76b8 skip needless_type_cast for single-use non-coercible casts 2025-12-17 16:23:28 +01:00
Samuel Tardieu
37330eb80a
New internal lint: repeated_is_diagnostic_item (#15937)
As described in
https://github.com/rust-lang/rust-clippy/pull/15528#issuecomment-3214018887

changelog: none
2025-12-17 12:36:12 +00:00
Ada Alakbarova
29659288ff
feat(repeated_is_diagnostic_item): new internal lint 2025-12-17 12:20:51 +01:00
Ada Alakbarova
3e55ab1adf
dogfood the lint
This commit is put before the one that actually introduces the lint,
since, were they put in the opposite order, the first commit wouldn't
pass dogfood
2025-12-17 12:20:51 +01:00
Samuel Tardieu
020c7cffa3
Fix empty_enum_variants_with_brackets misses removing brackets in patterns (#16160)
Closes rust-lang/rust-clippy#16157

changelog: [`empty_enum_variants_with_brackets`] fix missing to remove
brackets in patterns
2025-12-16 23:44:30 +00:00
Jason Newcomb
498d4bf2ea
Move collapsible_else_if to pedantic (#16211)
Looks like a good number of people disagree with this lint so it
shouldn't be on by default

Fixes https://github.com/rust-lang/rust-clippy/issues/16209

changelog: [`collapsible_else_if`]: move to `pedantic`
2025-12-16 20:32:43 +00:00
Linshu Yang
96423581b2 Make empty_enum_variants_with_brackets to support empty variant with braces 2025-12-16 20:13:53 +00:00
llogiq
40ad1a6ce2
Move needless_type_cast lint to nursery (#16246)
changelog: [`needless_type_cast`]: move into nursery until bugs are
ironed out

[Zulip
thread](https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/Moving.20.60needless_type_cast.60.20to.20.60nursery.60)
2025-12-16 06:07:45 +00:00
Catherine Flores
c614b57d0a
Do not look for disallowed methods inside desugared code (#16186)
changelog: [`disallowed_methods`]: do not check compiler-generated code

Fixes rust-lang/rust-clippy#16185
2025-12-16 00:21:09 +00:00
Jason Newcomb
acc50245d2
Parent of struct constructor is the struct itself (#16245)
The `Fn`/`AssocFn` cases were not tested anywhere, and according to the
comments inside `TyCtxt::res_generic_def_id()` could have made the
`TyCtxt::generics_of()` call also trigger an ICE.

changelog: [`needless_type_cast`]: do not ICE on struct constructor

Fixes rust-lang/rust-clippy#16243
2025-12-15 20:38:36 +00:00
Samuel Tardieu
344ddcf9f2
Move needless_type_cast lint to nursery
The lint is new and already has several bugs filed against it, including
an ICE.
2025-12-15 20:13:34 +01:00
Samuel Tardieu
ebfe9698f0
Parent of struct constructor is the struct itself
Also, the `Fn`/`AssocFn` cases were not tested anywhere, and according
to the comments inside `TyCtxt::res_generic_def_id()` could have made
the `TyCtxt::generics_of()` call also trigger an ICE.
2025-12-15 19:18:49 +01:00
Alejandra González
d93e1eb294
Fix branches-sharing-code suggests wrongly on const and static (#15522)
Closes rust-lang/rust-clippy#15347

changelog: [`branches-sharing-code`] fix wrong suggestions on `const`
and `static`
2025-12-15 17:26:29 +00:00
Jason Newcomb
4d4789cdec
Count unsafe operations and macro calls once towards the innermost unsafe block (#16117)
changelog: [`multiple_unsafe_ops_per_block`]: count unsafe operations
only towards the innermost unsafe block

Fixes rust-lang/rust-clippy#16116

r? Jarcho
2025-12-15 14:57:23 +00:00
Samuel Tardieu
099062d6b0
Fix set-contains-or-insert FP when set is mutated before insert (#16009)
Closes rust-lang/rust-clippy#15990

changelog: [`set-contains-or-insert`] fix FP when set is mutated before
`insert`
2025-12-15 13:19:09 +00:00
Samuel Tardieu
95d5990b99
Fix map_entry suggests wrongly for insert with cfg-ed out code (#15800)
Closes rust-lang/rust-clippy#15781

changelog: [`map_entry`] fix wrong suggestions for insert with cfg-ed
out code
2025-12-15 13:10:42 +00:00
Samuel Tardieu
924f153dcd
Fix match_like_matches_macro wrongly unmangled macros (#16018)
Closes rust-lang/rust-clippy#16015

changelog: [`match_like_matches_macro`] fix wrongly unmangled macros
2025-12-15 12:49:30 +00:00
Samuel Tardieu
893677fc14
feat(format_push_string): give a (possibly incomplete) suggestion (#16093)
Resolves https://github.com/rust-lang/rust-clippy/issues/8824

Supersedes https://github.com/rust-lang/rust-clippy/pull/15828 -- I
wasn't able to get `TyCtxt::in_scope_traits` to work, so here's a more
basic implementation that just adds a note about the possible need to
import `std::fmt::Write`.

changelog: [`format_push_string`]: add a suggestion
2025-12-15 12:46:15 +00:00
Jason Newcomb
d36794f5ec
Add iterator reduction coverage to never_loop (#16222)
Fixes rust-lang/rust-clippy#16061.

Extend `never_loop` to also lint iterator reduction methods (e.g.
`for_each`, `try_for_each`, `fold`, `try_fold`, `reduce`, `all`, `any`)
when the closure’s body diverges (return type `!`). Add a UI test
`never_loop_iterator_reduction` to cover these cases.

Testing:
- TESTNAME=never_loop_iterator_reduction cargo uitest

changelog: [`never_loop`]: lint diverging iterator reduction closures
like `for_each` and `fold`
2025-12-15 12:00:31 +00:00
Cuong Le
c59da4f809
loops: reuse iterator checks for unused_enumerate_index 2025-12-15 15:11:48 +07:00
dswij
80fce9b0f5
Fix if_not_else wrong unmangled macros (#15931)
Closes rust-lang/rust-clippy#15924

changelog: [`if_not_else`] fix wrongly unmangled macros
2025-12-14 03:58:00 +00:00
Cuong Le
9dca2a8ad3
Refactor loops MethodCall handling into single match 2025-12-14 09:56:35 +07:00
Jason Newcomb
9a089b63a0
Fix unchecked_time_subtraction FN on Ops::sub method call (#16233)
Closes rust-lang/rust-clippy#16230
Closes rust-lang/rust-clippy#16234
Closes rust-lang/rust-clippy#16236

changelog: [`unchecked_time_subtraction`] fix FN on `Ops::sub` method
call
2025-12-13 22:19:32 +00:00
Linshu Yang
e0a74c3335 fix: manual_instant_elapsed wrongly unmangled macros 2025-12-13 20:57:44 +00:00
Linshu Yang
e95ceddbc6 fix: unchecked_time_subtraction wrongly unmangled macros 2025-12-13 20:44:14 +00:00
Linshu Yang
075548e9e9 fix: unchecked_time_subtraction FN on Ops::sub method call 2025-12-13 20:44:10 +00:00
Jason Newcomb
f206ef8452
Fix clippy::ref_as_ptr for non-temporary references in let/const (#16214)
Fix `ref_as_ptr` false positives for temporary values and
let/static/const initializers.

Fixes rust-lang/rust-clippy#16220

changelog: [`ref_as_ptr`]: Only lint on non-temporary expressions)
2025-12-13 18:42:05 +00:00
abd002
aefb01b852 Fix clippy::ref_as_ptr for non-temporary references in let/const 2025-12-13 19:27:43 +02:00
Cuong Le
51580d3835
Refine never_loop iterator reduction check 2025-12-13 21:34:20 +07:00
Jason Newcomb
d06ae84771
feat(unnecessary_fold): lint on folds with Add::add/Mul::mul (#16124)
Resurrects https://github.com/rust-lang/rust-clippy/pull/13475

changelog: [`unnecessary_fold`]: lint on `fold`s with
`Add::add`/`Mul::mul`
2025-12-12 18:39:22 +00:00
Jason Newcomb
89aeed1c24
Fix if_then_some_else_none FP when encountering await codes (#16178)
changelog: Fix FP of [`if_then_some_else_none`] when the `then` block
contains `await` codes.

That is because `bool:then` doesn't work with await code.

Closes: rust-lang/rust-clippy#16176
2025-12-12 15:44:52 +00:00
Coca
8f9a93d0fd
transmuting_null: Check const integer casts
changelog: [`transmuting_null`]: now checks const integers being casted
to pointers
2025-12-12 14:29:28 +00:00
Cuong Le
fefd58b32b
Clean up unused try_reduce entry in sym 2025-12-12 10:37:34 +07:00
Cuong Le
89a848c439
Fix fmt and dogfood lints for never_loop iterator reduction 2025-12-12 10:24:49 +07:00
Cuong Le
36201bdf3e
Add iterator reduction coverage to never_loop 2025-12-12 10:01:58 +07:00
Philipp Krones
9e3e9649cb
Rustup (#16217)
r? @ghost

changelog: none
2025-12-11 18:00:44 +00:00
Philipp Krones
1ff4682590
Bump Clippy version -> 0.1.94 2025-12-11 18:48:15 +01:00
Philipp Krones
42c8b68ee9
Bump nightly version -> 2025-12-11 2025-12-11 18:48:10 +01:00
Philipp Krones
de365c057e
Merge remote-tracking branch 'upstream/master' into rustup 2025-12-11 18:48:00 +01:00
Ada Alakbarova
34551be259
feat(format_push_string): add a suggestion 2025-12-11 10:53:04 +01:00
Ada Alakbarova
2a224f3e79
clean-up 2025-12-11 10:48:45 +01:00
Ada Alakbarova
254e0cb3bc
feat(unnecessary_fold): lint on folds with Add::add/Mul::mul 2025-12-11 10:18:30 +01:00
Ada Alakbarova
4ce7628869
clean-up 2025-12-10 19:38:09 +01:00
Linshu Yang
dc0bf26dd4 fix: match_like_matches_macro wrongly unmangled macros 2025-12-10 17:59:18 +00:00
Matthias Krüger
d196db781e Rollup merge of #149489 - scottmcm:try-bikeshed, r=nnethercote
Experimentally add *heterogeneous* `try` blocks

rust-lang/rust#148725 moved the default to being homogeneous; this adds heterogeneous ones back under an obvious-bikeshed syntax so people can experiment with that as well.

Essentially resolves rust-lang/rust#149025 by letting them move to this syntax instead.

New tracking issue: rust-lang/rust#149488
Related RFC: https://github.com/rust-lang/rfcs/pull/3721#issuecomment-3208342727 (specifically about experimenting)
2025-12-10 17:16:47 +01:00
Alex Macleod
961ea1c46b
feat(manual_saturating_arithmetic): lint x.checked_sub(y).unwrap_or_default() (#15845)
Resolves https://github.com/rust-lang/rust-clippy/issues/15655

changelog: [`manual_saturating_arithmetic`]: lint
`x.checked_sub(y).unwrap_or_default()`
2025-12-10 15:53:23 +00:00
Alex Macleod
06ded880d2
fix(match_like_matches_macro): FP with guards containing if let (#15876)
Fixes https://github.com/rust-lang/rust-clippy/issues/15841

changelog: [`match_like_matches_macro`]: FP with guards containing `if
let`
2025-12-10 15:35:51 +00:00