Commit graph

10586 commits

Author SHA1 Message Date
Jason Newcomb
cb32444ee6 Remove is_path_diagnostic_item 2025-10-10 22:30:57 -04:00
Nick Drozd
b71fe9254d Check structs and enums for use_self 2025-10-09 18:23:12 -05:00
Alejandra González
57913b4737
Honor allow/expect attributes on ADT and impl Clone nodes (#15849)
changelog: [`expl_impl_clone_on_copy`]: honor `allow`/`expect`
attributes on both the type declaration and the `impl`

Fixes rust-lang/rust-clippy#15842

r? @blyxyas
2025-10-09 22:09:37 +00:00
llogiq
e6febbd13b
Add lint unnecessary_option_map_or_else (#14662)
changelog: [`unnecessary_option_map_or_else`]: Added lint
unnecessary_option_map_or_else. As suggested in the issue description,
the implementation takes as reference the issue
rust-lang/rust-clippy#7328. The tests for lints `option_if_let_else` and
`or_fun_call` needed to be adjusted to comply with new lint.
fixes rust-lang/rust-clippy#14588
2025-10-09 21:56:14 +00:00
Timo
e70b206665
chore: multipart_suggestions for manual_assert (#13787)
This should address
https://github.com/rust-lang/rust-clippy/issues/13099 for the let_unit
test.

changelog: [manual_assert]: Updated manual_assert to use
multipart_suggestions where appropriate
2025-10-08 21:32:11 +00:00
Samuel Tardieu
69bd890ff1
Honor allow/expect attributes on ADT and impl Clone nodes 2025-10-08 22:02:14 +02:00
Scott Gerring
8ef90574a2
chore: update manual_assert span suggestions 2025-10-08 11:58:50 +01:00
Samuel Tardieu
f110f3412d
Fix needless_continue FP when match type is not unit or never (#15547)
Closes rust-lang/rust-clippy#14550
Closes rust-lang/rust-clippy#15548

changelog: [`needless_continue`] fix FP when match type is not unit or
never
2025-10-07 16:24:56 +00:00
yanglsh
13bd9b5d0f fix: needless_continue wrongly unmangled macros 2025-10-08 00:03:48 +08:00
yanglsh
7117bd9a27 fix: needless_continue FP when match type is not unit or never 2025-10-08 00:03:48 +08:00
Samuel Tardieu
0a2eeceefc
Add replace_box lint (#14953)
Adds a new lint that detects `var = Default::default()` when `var` is
`Box<T>` and `T` implements `Default`.

changelog: [`replace_box`]: new lint
2025-10-07 15:56:38 +00:00
dswij
ea54123fd4
fix(collapsible_match): exclude binding modes from struct field pattern suggestions (#15608)
Fixes https://github.com/rust-lang/rust-clippy/issues/13287

changelog: [`collapsible_match`]: exclude binding modes from struct
field pattern suggestions
2025-10-07 15:49:47 +00:00
+merlan #flirora
517ef604af Add replace_box lint 2025-10-07 11:33:54 -04:00
Timo
c1f61242e2
legacy_numeric_constants: add ctxt check for internal macro (#15816)
Fixes rust-lang/rust-clippy#15805

ICE bisects to 9457d640b7, which handles the span incorrectly when part
of the path originates from internal declarative macro.

changelog: none
2025-10-07 08:34:10 +00:00
Nick Drozd
5318883d75 Use expect for lint warnings 2025-10-06 20:17:12 -04:00
Samuel Tardieu
5b23bd479e
Remove no-rustfixes (#15827)
Remove no-rustfixes where it's not required anymore

changelog: none
2025-10-06 21:08:58 +00:00
Samuel Tardieu
2c71638be5
Implement volatile_composites lint (#15686)
Volatile reads and writes to non-primitive types are not well-defined,
and can cause problems.

Fixes rust-lang/rust-clippy#15529

changelog: [`volatile_composites`]: Lint when read/write_volatile is
used on composite types
(structs, arrays, etc) as their semantics are not well defined.
2025-10-06 21:06:29 +00:00
Alexey Semenyuk
f97b493fa5 Remove no-rustfix 2025-10-06 21:21:02 +03:00
dswij
4f21c9929c
extend while_let_loop to loop { let else } (#15701)
now lints on
```rs
let mut x = [1,2,3].into_iter();
loop {
   let Some(x) = x.next() else { break };
   dbg!(x);
}
```
```
changelog: [`while_let_loop`]: extend to lint on `let else`
```
2025-10-06 17:29:19 +00:00
Philipp Krones
15727e0522
Merge remote-tracking branch 'upstream/master' into rustup 2025-10-06 17:26:03 +02:00
Zihan
0ba022a858
legacy_numeric_constants: add ctxt check for internal macro
changelog: none

Signed-off-by: Zihan <zihanli0822@gmail.com>
2025-10-06 09:28:27 -04:00
Samuel Tardieu
d289009eea
Const eval changes (#15773)
First commit treats all constants containing a macro call as non-local
and renames `eval_simple` to be a little clearer.

Second commit removes `CoreConstant` and treats most of them as though
they were local. A couple of the constants like `usize::MAX` are treated
as non-local as different targets may have different values.
`const_is_empty` will now ignore non-local constants since there's no
guarantee that they are the same across all targets/features/versions.

The third commit just changes some `eval` calls to `eval_local`. Most of
these were style lints which shouldn't be assuming the value of a
constant won't ever change.

changelog: none
2025-10-04 18:16:35 +00:00
Jason Newcomb
47b0f903a3 Use eval_local in more places. 2025-10-04 10:41:35 -04:00
Jason Newcomb
3d351c839d Const eval changes:
* Remove `CoreConstant`.
* Treat most constants from core as though they were inlined.
* Don't evaluate `is_empty` for named constants.
2025-10-04 10:41:35 -04:00
Samuel Tardieu
19343bf41d
fix(zero_repeat_side_effects): better identify exprs with side effects (#15814)
Fixes https://github.com/rust-lang/rust-clippy/issues/14681

changelog: [`zero_repeat_side_effects`]: better identify exprs with side
effects
2025-10-04 13:28:19 +00:00
Ada Alakbarova
adff9baeb3
fix(zero_repeat_side_effects): better identify exprs with side effects 2025-10-04 15:22:52 +02:00
Samuel Tardieu
0a7b3282af
Upgrade toml to 0.9.7 and remove the serde feature (#15806)
With this and rust-lang/rust-clippy#13084 our toml version will be
pushed to `0.9.7`. This is different from rustc's version, but the
changes in rust-lang/rust-clippy#13084 already require an incompatible
version.

The `serde` feature is also removed since it was only used in one spot
with a mostly trivial replacement.

changelog: none
2025-10-04 13:16:56 +00:00
Ada Alakbarova
24befed727
clean-up
- inline `array_span_lint`
- use `match` instead of `if-let`
- give a more descriptive help message
2025-10-04 15:16:54 +02:00
Alejandra González
82297010ed
Fix let_unit_value suggests wrongly for field init shorthand (#15791)
Closes rust-lang/rust-clippy#15789

changelog: [`let_unit_value`] fix wrong suggestions for field init
shorthand
2025-10-03 22:35:31 +00:00
Jason Newcomb
3d2a8df077 Upgrade toml to 0.9.7 and remove the serde feature. 2025-10-02 15:31:42 -04:00
Jason Newcomb
6cc8f8dbaa
Do not trigger inefficient_to_string after Rust 1.82 (#15729)
Starting with Rust version 1.82.0, the compiler generates similar code
with and without the `with_ref` cfg:

```rust
fn f(x: impl IntoIterator<Item = String>) {
    for y in x { println!("{y}"); }
}

fn main() {
    #[cfg(with_ref)]
    let a = ["foo", "bar"].iter().map(|&s| s.to_string());
    #[cfg(not(with_ref))]
    let a = ["foo", "bar"].iter().map(|s| s.to_string());
    f(a);
}
```

The generated code is strictly identical with `-O`, and identical modulo
some minor reordering without.

changelog: [`inefficient_to_string`]: do not trigger for Rust ≥ 1.82.0
2025-10-01 22:02:53 +00:00
Samuel Tardieu
951d35eeb6
Do not trigger inefficient_to_string after Rust 1.82
Starting with Rust version 1.82.0, the compiler generates similar code with
and without the `with_ref` cfg:

```rust
fn f(x: impl IntoIterator<Item = String>) {
    for y in x { println!("{y}"); }
}

fn main() {
    #[cfg(with_ref)]
    let a = ["foo", "bar"].iter().map(|&s| s.to_string());
    #[cfg(not(with_ref))]
    let a = ["foo", "bar"].iter().map(|s| s.to_string());
    f(a);
}
```

The generated code is strictly identical with `-O`, and identical modulo
some minor reordering without.
2025-10-01 23:13:33 +02:00
Alejandra González
0c7e0344cf
Do not suggest using a if let chain if it is not supported (#15746)
This might be due to a low edition (< 2024) or too low a MSRV. In this
case, we will suggest only `match`.

Fixes rust-lang/rust-clippy#15744

changelog: [`unnecessary_unwrap`]: do not suggest using `if let` chains
if this is not supported with the current edition or MSRV
changelog:[`collapsible_if`]: Do not suggest using `if let` if this is
not supported with the current edition or MSRV
2025-10-01 16:08:15 +00:00
Jason Newcomb
3e24d50407 Rename eval_simple to eval_local and take the SyntaxContext as an argument. 2025-10-01 05:20:44 -04:00
Samuel Tardieu
f1079915b4
Do not suggest using a if let chain if it is not supported
This might be due to a low edition (< 2024) or too low a MSRV.
2025-10-01 07:41:49 +02:00
Samuel Tardieu
f08486481f
assertions_on_constants: Suggest using a const block when using a named constant (#15774)
changelog: [`assertions_on_constants`]: Suggest using a const block when
the assertion uses a named constant.
2025-09-30 19:40:20 +00:00
Jason Newcomb
61b1f0e37f assertions_on_constants: Don't suggest removing assertions with non-local constants. 2025-09-30 13:59:06 -04:00
Samuel Tardieu
d423321f72
Fix mem_replace_with_default wrongly unmangled macros (#15786)
Closes rust-lang/rust-clippy#15785

changelog: [`mem_replace_with_default`] fix wrongly unmangled macros
2025-09-30 17:32:42 +00:00
Alejandra González
8fafe7aa14
test: remove extraneous #[allow(clippy::uninlined_format_args)] (#15799)
These were probably added automatically to avoid code churn. I'd like to
get rid of them bit by bit, so here's the first bit

changelog: none
2025-09-30 16:44:44 +00:00
yanglsh
f9852613a9 fix: mem_replace_with_default wrongly unmangled macros 2025-10-01 00:33:32 +08:00
Ada Alakbarova
e9ede27a5d
test: remove extraneous #[allow(clippy::uninlined_format_args)]
These were probably added automatically to avoid code churn. I'd like to
get rid of them bit by bit, so here's the first bit
2025-09-30 18:08:37 +02:00
yanglsh
089fbd35aa fix: let_unit_value suggests wrongly for field init shorthand 2025-09-30 23:51:17 +08:00
Alex Macleod
3ca0738650
Fix if_then_some_else_none FP when return exists in block expr (#15783)
Closes rust-lang/rust-clippy#15770

changelog: [`if_then_some_else_none`] fix FP when return exists in block
expr
2025-09-30 15:06:35 +00:00
Samuel Tardieu
189b4c31f3
fix(new_without_default): if new has #[cfg], copy that onto impl Default (#15720)
Fixes https://github.com/rust-lang/rust-clippy/issues/14552

changelog: [`new_without_default`]: if `new` has `#[cfg]`, copy that
onto `impl Default`
2025-09-30 08:01:15 +00:00
Jason Newcomb
1a415e6ddf
double_parens: add structured suggestions, fix bug (#15420)
The issue that I saw made me rethink the lint design by quite a lot, so
I decided to include that change in this PR

fixes rust-lang/rust-clippy#9000

changelog: [`double_parens`]: add structured suggestions
changelog: [`double_parens`]: fix FP when macros are involved
2025-09-29 23:33:37 +00:00
Ada Alakbarova
7a04adae7d
fix(new_without_default): if new has #[cfg], copy that onto impl Default 2025-09-30 01:24:10 +02:00
Ada Alakbarova
93355f1c7b
clean-up
- reduce indentation
- use `snippet_with_applicability`
2025-09-30 01:08:56 +02:00
Samuel Tardieu
b05d55eeed
fix(should_implement_trait): only suggest traits that are in the prelude (#15776)
Fixes https://github.com/rust-lang/rust-clippy/issues/6752

changelog: [should_implement_trait]: only suggest traits that are in the
prelude
2025-09-29 22:30:39 +00:00
Samuel Tardieu
5ab16d118a
fix(let_unit_value): create the suggestion "differentially" (#15788)
I.e, instead of constructing a whole new `LetStmt` to replace the old
one, suggest to only change the part of the `LetStmt` that we don't
like. This makes the suggestion less likely to introduce spurious
changes, but also makes the diagnostic much nicer imo.

Fixes rust-lang/rust-clippy#15771 by not adding a semicolon that the
initial `LetStmt` didn't have
Fixes rust-lang/rust-clippy#15784 by using the `init.span` with the
correct `SyntaxContext`

changelog: [`let_unit_value`]: don't add spurious semicolon
changelog: [`let_unit_value`]: don't mangle macro calls
2025-09-29 22:08:35 +00:00
Alejandra González
98a92bf093
overhaul mut_mut (#15417)
This PR:
- adds structured suggestions to all 3 lint scenarios
- adds more examples of linted patterns, and recommended fixes
- moves some test cases to `_unfixable.rs`, to allow running rustfix on
the main file
- stops the lint from firing multiple times on types like `&mut &mut
&mut T`

Open questions:
- I'd like to add a note explaining why chained `&mut` are useless.. but
can't really come up with something consice. I very much don't like the
one in the docs -- it's a bit too condescending imo.
- see comments in the diff for more

I do realize that the PR ended up being quite wide-scoped, but that's
primarily because once I added structured suggestions to one of the lint
cases, `ui_test` started complaining about warnings remaining after the
rustfix run, which of course had to with the fact that the other two
lint cases didn't actually fix the code they linted, only warned. I
_guess_ `ui_test` could be smarter about this, by understanding that if
a warning was created without a suggestion, then that warning will still
remain in the fixed file. But oh well.

changelog: [`mut_mut`]: add structured suggestions, improve docs

fixes rust-lang/rust-clippy#13021
2025-09-29 21:21:56 +00:00