Commit Graph

8748 Commits

Author SHA1 Message Date
Philipp Krones 284b596ac4 Merge remote-tracking branch 'upstream/master' into rustup 2025-08-22 14:25:23 +02:00
Alex Macleod c18363c0e3 too_many_lines: only highlight the function signature (#15461)
resolves https://github.com/rust-lang/rust-clippy/issues/15430

changelog: [`too_many_lines`]: only highlight the function signature
2025-08-21 15:25:03 +00:00
Alex Macleod 743405d7bf Do not replace match by if if any arm contains a binding (#15352)
changelog: [`match_bool`]: do not replace `match` by `if` if any arm
contains a binding

Fixes rust-lang/rust-clippy#15351
2025-08-21 13:42:44 +00:00
Karol Zwolak 4b2b9c2a39 bless tests with new lint messages 2025-08-19 21:27:10 +02:00
Alejandra González 73b5a59c22 Do not suggest to use implicit DerefMut on ManuallyDrop reached through unions (#14387)
This requires making the `deref_addrof` lint a late lint instead of an
early lint to check for types.

changelog: [`deref_addrof`]: do not suggest implicit `DerefMut` on
`ManuallyDrop` union fields

Fix rust-lang/rust-clippy#14386
2025-08-18 15:10:31 +00:00
Alejandra González 1fd9504619 similar_names stop linting for 3-char names (#15100)
fixes rust-lang/rust-clippy#14869

Added a simple check if both chars are of length 3
If they are, we skip the check for that pair.

This won't handle the 4 v 3 case.
Not sure if this was the intent of the issue.

Also saw we have some hardcoded exemptions for `set, get` and `lhs, rhs`
Tried removing them thinking they would be handled by the new condition.
But we have to keep because they allow for `bla_lhs` v `bla_rhs` to be
skipped

changelog:[`similar_names`]: Stop triggering for 3-character names
2025-08-16 16:58:06 +00:00
Abderahmane Bouziane e41fb7ca52 similar_names stop linting for 3-char names 2025-08-16 12:36:50 -04:00
Jason Newcomb 9563a5ce46 {borrow,ptr}_as_ptr: don't lint inside proc-macros (#15473)
this could arguably be 2 separate PRs, but both of these were brought up
in the same issue, so..

fixes https://github.com/rust-lang/rust-clippy/issues/15398

- [x] I'm a bit doubtful about the last commit -- see the message for my
reasoning and do let me know whether it's right.

changelog: [`borrow_as_ptr`]: don't lint inside proc-macros
changelog: [`ptr_as_ptr`]: don't lint inside proc-macros
2025-08-15 13:34:52 +00:00
Ada Alakbarova 9570ed8363 ptr_as_ptr: don't allow in proc-macros
notice that this stops `inline!` from working as well
2025-08-15 14:04:37 +02:00
Stuart Cook 210097ad7e Rollup merge of #122661 - estebank:assert-macro-span, r=petrochenkov
Change the desugaring of `assert!` for better error output

In the desugaring of `assert!`, we now expand to a `match` expression instead of `if !cond {..}`.

The span of incorrect conditions will point only at the expression, and not the whole `assert!` invocation.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091.rs:2:13
   |
LL |     assert!(1,1);
   |             ^ expected `bool`, found integer
```

We no longer mention the expression needing to implement the `Not` trait.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091-2.rs:15:13
   |
LL |     assert!(x, x);
   |             ^ expected `bool`, found `BytePos`
```

Now `assert!(val)` desugars to:

```rust
match val {
    true => {},
    _ => $crate::panic::panic_2021!(),
}
```

Fix #122159.
2025-08-15 16:16:29 +10:00
Timo aeaa348b42 unnecessary_operation: add space between stmts in suggestion (#15432)
makes the suggestion a bit more legible

changelog: [`unnecessary_operation`]: add space between stmts in
suggestion
2025-08-14 18:06:06 +00:00
Timo 871df561a0 Fix match_ref_pats FP on match scrutinee of never type (#15474)
Closes rust-lang/rust-clippy#15378

changelog: [`match_ref_pats`] fix FP on match scrutinee of never type
2025-08-14 18:02:36 +00:00
yanglsh 05c2d72abc fix: match_ref_pats FP on match scrutinee of never type 2025-08-14 11:23:31 +08:00
Ada Alakbarova e19a11f3ac misc: import macros explicitly 2025-08-13 19:35:32 +02:00
Ada Alakbarova bc0e43c0f2 fix borrow_as_ptr: don't lint in proc-macros 2025-08-13 19:35:31 +02:00
Jason Newcomb 355e4bacf5 as_ptr_cast: move the unfixable case into a separate file (#15475)
allows creating `.fixed` for the main file

changelog: none
2025-08-13 17:11:14 +00:00
Vadim Petrochenkov cb3dedc624 Update clippy tests 2025-08-13 19:29:53 +03:00
Ada Alakbarova ff2b5e66a1 test: make suggestions the main file
since it's the one that has suggestions
2025-08-13 16:34:24 +02:00
Ada Alakbarova ad9686e0c7 test: move the main file to unfixable
since it's the one that makes no suggestions
2025-08-13 16:33:48 +02:00
Ada Alakbarova f0bb5cde69 as_ptr_cast: move the unfixable case into a separate file
allows creating `.fixed` for the main file
2025-08-13 16:09:04 +02:00
Ada Alakbarova af2dd2d3bc fix unnecessary_semicolon: don't lint on stmts with attrs 2025-08-12 19:12:47 +02:00
Esteban Küber 0a522ccfd9 Change the desugaring of assert! for better error output
In the desugaring of `assert!`, we now expand to a `match` expression
instead of `if !cond {..}`.

The span of incorrect conditions will point only at the expression, and not
the whole `assert!` invocation.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091.rs:2:13
   |
LL |     assert!(1,1);
   |             ^ expected `bool`, found integer
```

We no longer mention the expression needing to implement the `Not` trait.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091-2.rs:15:13
   |
LL |     assert!(x, x);
   |             ^ expected `bool`, found `BytePos`
```

`assert!(val)` now desugars to:

```rust
match val {
    true => {},
    _ => $crate::panic::panic_2021!(),
}
```

Fix #122159.

We make some minor changes to some diagnostics to avoid span overlap on
type mismatch or inverted "expected"/"found" on type errors.

We remove some unnecessary parens from core, alloc and miri.

address review comments
2025-08-12 16:30:48 +00:00
Ada Alakbarova 49666f64e9 too_many_lines: only highlight the function signature 2025-08-12 16:20:08 +02:00
Stuart Cook 12087f1d09 Rollup merge of #145273 - estebank:not-not, r=samueltardieu
Account for new `assert!` desugaring in `!condition` suggestion

`rustc` in https://github.com/rust-lang/rust/pull/122661 is going to change the desugaring of `assert!` to be

```rust
match condition {
    true => {}
    _ => panic!(),
}
```
which will make the edge-case of `condition` being `impl Not<Output = bool>` while not being `bool` itself no longer a straightforward suggestion, but `!!condition` will coerce the expression to be `bool`, so it can be machine applicable.

Transposing https://github.com/rust-lang/rust-clippy/pull/15453/ to the rustc repo.

r? `````@samueltardieu`````
2025-08-12 20:37:57 +10:00
Ada Alakbarova abfc498f98 give the test functions more complex signatures 2025-08-12 01:13:26 +02:00
Ada Alakbarova 9ea90b3bda add test case for a method 2025-08-12 00:38:19 +02:00
Esteban Küber c8c483df27 Account for new assert! desugaring in !condition suggestion
`rustc` is going to change the desugaring of `assert!` to be

```rust
match condition {
    true => {}
    _ => panic!(),
}
```
which will make the edge-case of `condition` being `impl Not<Output = bool>`
while not being `bool` itself no longer a straightforward suggestion,
but `!!condition` will coerce the expression to be `bool`, so it can be
machine applicable.
2025-08-11 21:38:44 +00:00
Esteban Küber bec5346038 fix clippy test 2025-08-11 20:04:27 +00:00
Timo 14dfc03597 feat: introduce path_to_local_with_projections (#15396)
As suggested in
https://github.com/rust-lang/rust-clippy/pull/15268#discussion_r2249249661

WIP because:
- [x] what should be done with the now-error-pattern-less
`tests/ui/double_ended_iterator_last_unfixable.rs`?
- [x] is the change in behaviour of `double_ended_iterator_last` okay in
general?
- cc @samueltardieu because this changes the code you added in
https://github.com/rust-lang/rust-clippy/pull/14140

changelog: none

r? @y21
2025-08-10 10:33:05 +00:00
Samuel Tardieu e6b63d15fa fix &str type check in from_str_radix_10 (#15410)
minor fix in `from_str_radix_10` lint, `is_type_diagnostic_item` only
checks `Adt`, use `.is_str()` instead

changelog: [`from_str_radix_10`]: properly lint references to `&str` as
well
2025-08-09 22:30:18 +00:00
Ada Alakbarova 04606e27dc introduce path_to_local_with_projections
combine two similar arms

use in `eager_transmute`

use in `double_ended_iterator_last`

use different numbers in the new test case to avoid possible confusion

move the other "unfixable" case as well; it shouldn't lint anyway, so
having it in the main test file is fine
2025-08-09 20:27:30 +02:00
Dave Rolsky 5c617b4867 Add "PowerPC" to the list of valid CamelCase strings in docs 2025-08-09 10:28:14 -05:00
dswij 386372a0e4 [[infinite_loop] fix infinite loop false positive (#15157)
changelog: [infinite_loop]: Improve handling of infinite loops in async
blocks

Fix rust-lang/rust-clippy#14000

This PR refines the [infinite_loop] lint to avoid false positives when
infinite loops occur inside async blocks that are not awaited (such as
those that are spawned or assigned to variables for later use). The lint
will now only trigger when the async block containing the loop is
directly awaited.
2025-08-09 15:08:54 +00:00
Jason Newcomb ea7ebaa825 Do not attempt to compute size of a type with escaping lifetimes (#15434)
A type with escaping bound vars cannot be wrapped in a dummy binder
during size computation.

Fixes rust-lang/rust-clippy#15429

changelog: [`zero_sized_hashmap_values`]: fix ICE in types with escaping
lifetimes

r? Jarcho

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

- [Beta
nomination](https://github.com/rust-lang/rust-clippy/pull/15434#issuecomment-3164866684)
by [samueltardieu](https://github.com/samueltardieu)

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

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
2025-08-09 14:09:43 +00:00
Ada Alakbarova ac9361e18a eta_reduction: don't refer to ADT constructors as "function"s 2025-08-08 11:00:49 +02:00
Chengxu Bian c945393f67 fix inf loop 2025-08-07 22:17:37 -04:00
Ada Alakbarova 26cf75a18e unnecessary_operation: add space between stmts in suggestion
makes the suggestion a bit more legible
2025-08-07 23:44:28 +02:00
Samuel Tardieu c752fb2802 Do not attempt to compute size of a type with escaping lifetimes
A type with escaping bound vars cannot be wrapped in a dummy binder
during size computation.
2025-08-07 18:29:10 +02:00
Philipp Krones eb15cf0a30 Merge commit '334fb906aef13d20050987b13448f37391bb97a2' into clippy-subtree-update 2025-08-07 17:05:15 +02:00
Philipp Krones f2b7e9ff52 Merge remote-tracking branch 'upstream/master' into rustup 2025-08-07 16:47:42 +02:00
llogiq d98d7c0ee8 Fix suggestion for collapsible_if and collapsible_else_if when the inner if is enclosed in parentheses (#15304)
changelog: [`collapsible_else_if`]: fix suggestion when inner `if` as
wrapped in parentheses
changelog: [`collapsible_if`]: fix suggestion when inner `if` as wrapped
in parentheses

fixes https://github.com/rust-lang/rust-clippy/issues/15303

I'm sure this is a bit dirty, but don't currently see a better way.
2025-08-06 12:45:27 +00:00
Zihan 7a113811fa fix &str type check in from_str_radix_10
changelog: none

Signed-off-by: Zihan <zihanli0822@gmail.com>
2025-08-05 09:50:17 -04:00
Huterenok 6249f33ca1 fix: unnecessary_sort_by lint method consistency in message and suggestion 2025-08-05 15:23:10 +03:00
Alejandra González 264bc97b26 Split possible_missing_else from suspicious_else_formatting (#15317)
This has always been one lint (added in rust-lang/rust-clippy#720), but
the two cases are also quite distinct.

changelog: Split `possible_missing_else` from
`suspicious_else_formatting`

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

-
[Feature-freeze](https://github.com/rust-lang/rust-clippy/pull/15317#issuecomment-3094592022)
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-08-04 22:57:06 +00:00
Fayti1703 5b22c0c1ed Remove rogue comma from infallible_try_from lint message 2025-08-04 16:38:31 +02:00
Jason Newcomb 88bcf1ca19 fix option-if-let-else lint (#15394)
some simple twists
Fixes rust-lang/rust-clippy#15002
Fixes rust-lang/rust-clippy#15379

changelog: [`option_if_let_else`]: Don't remove raw pointer derefs in
suggestions
changelog: [`option_if_let_else`]: Don't suggest passing argless
functions to `Result::map_or_else`
2025-08-03 06:55:48 +00:00
Jason Newcomb fa09b86bfc Simplify boolean expression in manual_assert (#15368)
Fixes rust-lang/rust-clippy#15359

changelog: [`manual_assert`]: simplify boolean expression
2025-08-03 05:41:51 +00:00
Zihan 8f6b43dd65 fix: option_if_let_else don't suggest argless function for Result::map_or_else
closes rust-clippy/issues/15002

Signed-off-by: Zihan <zihanli0822@gmail.com>
2025-08-02 16:58:18 -04:00
Zihan b8c16e47f4 fix: option_if_let_else keep deref op if the inner expr is a raw pointer
closes rust-clippy/issues/15379

Signed-off-by: Zihan <zihanli0822@gmail.com>
2025-08-02 13:07:11 -04:00
Timo e8185ec091 Extend implicit_clone to handle to_string calls (#14177)
Put another way, merge `string_to_string` into `implicit_clone`, as
suggested here:
https://github.com/rust-lang/rust-clippy/issues/14173#issuecomment-2645846915

Note: [I
wrote](https://github.com/rust-lang/rust-clippy/commit/b8913894a13431bea99400dc9f53a1fd9f41a6c6)
this comment:
https://github.com/rust-lang/rust-clippy/blob/6cdb7f68c39a2458c6b8f6dc63da4123a6a5af89/clippy_lints/src/methods/implicit_clone.rs#L43-L45

Here is the context for why I wrote it:
https://github.com/rust-lang/rust-clippy/pull/7978#discussion_r769128853

Regardless, it's probably time for the comment to go away. Extending
`implicit_clone` to handle `to_string` calls yields many hits within
Clippy's codebase.

changelog: extend `implicit_clone` to handle `to_string` calls
2025-08-02 11:41:00 +00:00