Commit graph

23879 commits

Author SHA1 Message Date
Ada Alakbarova
8e3315f292
misc: extend let-chain 2025-10-04 21:35:01 +02: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
dswij
aa1fa10458
split copies lints each into its own module (#15721)
changelog: none
2025-10-02 18:12:24 +00: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
12e0c4c637
map_identity: simplify lint emission (#15797)
Instead of calling `span_lint_and_*` in multiple places, call
`span_lint_and_then` once and then use the `Diag` methods.

Diff best viewed with whitespace ignored

changelog: none
2025-10-01 16:27:32 +00: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
Alejandra González
e74d4bdc5d
clean-up match_same_arms a bit (#15727)
changelog: none
2025-09-30 22:03:03 +00: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
Ada Alakbarova
b3219502d7
map_identity: simplify lint emission
Instead of calling `span_lint_and_*` in multiple places, call
`span_lint_and_then` once and then use the `Diag` methods.
2025-09-30 18:02:31 +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
Ada Alakbarova
f6dd112a0a
fix: create the suggestion "differentially" 2025-09-29 22:05:24 +02:00
Ada Alakbarova
48ee4705dd
fix: actually use the Applicability 2025-09-29 22:05:24 +02:00
Ada Alakbarova
c3e4d2bb90
clean-up 2025-09-29 22:05:23 +02:00
Jason Newcomb
dfd8b2d3ee
Fix new_without_default FP on private type with trait impl (#15782)
Closes rust-lang/rust-clippy#15778

changelog: [`new_without_default`] fix FP on private type with trait
impl
2025-09-29 18:43:30 +00:00
yanglsh
642feb7e56 fix: if_then_some_else_none FP when return exists in block expr 2025-09-30 02:28:54 +08:00
yanglsh
17cecfd311 fix: new_without_default FP on private type with trait impl 2025-09-30 02:00:06 +08:00
Ada Alakbarova
2d2d143a18
fix: respect crate's edition 2025-09-29 14:18:20 +02:00
Ada Alakbarova
26a9a371ee
clean-up: extract should_implement_trait
Also put `SelfKind` into `lib.rs`, since it's shared with
`wrong_self_convention` -- not `utils.rs`, because it's not really a
utility function
2025-09-29 14:18:20 +02:00
Ada Alakbarova
f6e223cdb5
clean-up 2025-09-29 14:17:56 +02:00
Alex Macleod
3c93ba0c1d
is_async_fn: use FnKind::asyncness (#15772)
changelog: none
2025-09-28 22:52:39 +00:00
Ada Alakbarova
6b4febeeb7
simplify and inline is_async_fn 2025-09-28 17:31:03 +02:00
Ada Alakbarova
dc534c49b3
doc: add more examples, and a "Use instead" section, don't be condescending 2025-09-28 12:11:02 +02:00
Ada Alakbarova
75b68606bc
add an unfixable case
as recommended in
https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/problem.20when.20suggestion.20only.20removes.20one.20.22level.22.20of.20a.20lint/near/532894687
2025-09-28 12:11:02 +02:00
Ada Alakbarova
554680683f
remember all the nested types while we loop
see https://rust-lang.zulipchat.com/#narrow/channel/25732
2025-09-28 12:11:02 +02:00
Ada Alakbarova
9a1b2bcc9f
peel _all_ extra &muts
see
https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/problem.20when.20suggestion.20only.20removes.20one.20.22level.22.20of.20a.20lint/near/532889973
2025-09-28 12:11:02 +02:00
Ada Alakbarova
4053c44654
misc: import more from hir 2025-09-28 12:11:02 +02:00