Commit graph

22427 commits

Author SHA1 Message Date
Timo
91ed6060bb
Consistently refer to the ? operator (#14687)
Matches the `rustc` terminology

changelog: none
2025-04-24 22:04:05 +00:00
Alex Macleod
736be8bbb1 Consistently refer to the ? operator 2025-04-24 13:40:57 +00:00
Timo
34f81f96e9
style: pull one more if into the let-chain (#14669)
`cargo dev fmt` seems to not work for some reason (possibly because of
all the comments in the let-chain), so I formatted it manually -- I hope
it's right

changelog: none
2025-04-23 19:59:20 +00:00
Manish Goregaokar
dc695f53cd
Reword needless_question_mark diagnostics and docs (#14682)
Fixes https://github.com/rust-lang/rust-clippy/issues/14675 by making it
clearer that the constructor needs to be removed as well
Also fixes https://github.com/rust-lang/rust-clippy/issues/8392

changelog: none
2025-04-23 19:57:48 +00:00
Alex Macleod
7c5312bdab Reword needless_question_mark diagnostics and docs 2025-04-23 19:07:27 +00:00
Manish Goregaokar
aa27ae3fee
remove non-existent pathspec from pre-commit hook (#14671)
it was added back in 6035e050e8, at which
time there were some files matching it, e.g.

6035e050e8/clippy_lints/src/lib.deprecated.rs

fixes rust-lang/rust-clippy#14670

changelog: none
2025-04-22 22:53:31 +00:00
Ada Alakbarova
2304a9cb76
remove non-existent pathspec from pre-commit hook
it was added back in 6035e050e8, at which
time there were some files matching it, e.g.
6035e050e8/clippy_lints/src/lib.deprecated.rs
2025-04-23 00:47:43 +02:00
Ada Alakbarova
bf713a0e78
style: pull one more if into the let-chain 2025-04-22 23:51:42 +02:00
Alex Macleod
2422f0b9ac
Restrict the cases where ptr_eq triggers (#14526)
`ptr_eq` was recently enhanced to lint on more cases of raw pointers
comparison:

- lint on all raw pointer comparison, by proposing to use
`[core|std]::ptr::eq(lhs, rhs)` instead of `lhs == rhs`;
- removing one symetric `as usize` on each size if needed
- peeling any level of `as *[const|mut] _` if the remaining expression
can still be coerced into the original one (i.e., is a ref or raw
pointer to the same type as before)

The current change restricts the lint to the cases where at least one
level of symetric `as usize`, or any conversion to a raw pointer, could
be removed. For example, a direct comparaison of two raw pointers will
not trigger the lint anymore.

changelog: [`ptr_eq`]: do not lint when comparing two raw pointers
directly with no casts involved

Fixes rust-lang/rust-clippy#14525
2025-04-22 16:05:34 +00:00
Philipp Krones
0621446356
Rustup (#14667)
Out of cycle sync, as the sync to Rust failed again and resolving
conflicts there is awkward.

r? @ghost

changelog: none
2025-04-22 14:01:53 +00:00
Philipp Krones
bdc432759d
Bump nightly version -> 2025-04-22 2025-04-22 15:56:20 +02:00
Philipp Krones
ac477dbde5
Merge remote-tracking branch 'upstream/master' into rustup 2025-04-22 15:55:19 +02:00
Jason Newcomb
c3fb102a41
Consider side effects when rewriting iterator behaviors (#14490)
Closes #9191
Closes #14444
Closes #8055

Adds a new helper to partly check for side effects by recursively
checking if the iterator type contains closures with mutable captures.

changelog: [`double_ended_iterator_last`] fix FP when iter has side
effects
changelog: [`needless_collect`] fix lint not consider side effects
2025-04-22 13:21:54 +00:00
yanglsh
a50e043d32 Expand mutable capture check for is_iter_with_side_effects() 2025-04-22 20:55:07 +08:00
Jason Newcomb
aeb6ac9a0b
Fix question_mark suggesting when type is behind Deref include parentheses (#14655)
Close rust-lang/rust-clippy#14615

changelog: [`question_mark`]: when type is behind Deref include
parentheses
2025-04-22 01:58:56 +00:00
Alexey Semenyuk
7a4d523200 Fix question_mark suggesting when type is behind Deref include parentheses 2025-04-21 22:25:36 +05:00
Timo
083ea7e6c4
manual_ok_err: don't lint subpatterns (#14661)
Fixes https://github.com/rust-lang/rust-clippy/issues/14660

changelog: none
2025-04-21 14:47:02 +00:00
Timo
cc00c77607
Replace interning of string literals with preinterned symbols (#14650)
On
8ddf3676d1
it's a slight improvement

```
$ hyperfine -w 2 -r 100 -p 'touch src/cargo/lib.rs' 'cargo +master clippy' 'cargo +preintern clippy'
Benchmark 1: cargo +master clippy
  Time (mean ± σ):      6.908 s ±  0.063 s    [User: 6.134 s, System: 0.690 s]
  Range (min … max):    6.757 s …  7.045 s    100 runs

Benchmark 2: cargo +preintern clippy
  Time (mean ± σ):      6.815 s ±  0.065 s    [User: 6.039 s, System: 0.692 s]
  Range (min … max):    6.653 s …  6.968 s    100 runs

Summary
  cargo +preintern clippy ran
    1.01 ± 0.01 times faster than cargo +master clippy
```

Part 1 of removing `Symbol <-> str` conversions

changelog: none
2025-04-21 14:38:52 +00:00
dswij
f829f8cd5b
Make borrow_as_ptr flag implicit casts as well (#14408)
While I like replacing `&x` by `&raw const x` and `&mut x` by `&raw mut
x`, I'm less sure I like the suggested reborrows such as `&raw const
*p`. There was one in Clippy sources, see the PR diff.

@RalfJung, any opinion on this?

Fix #14406

changelog: [`borrow_as_ptr`]: lint implicit casts as well
2025-04-21 12:38:11 +00:00
Alejandra González
48430c2970
iter_kv_map: recognize references on maps as well (#14596)
Fix rust-lang/rust-clippy#14595

changelog: [`iter_kv_map`]: recognize references on maps as well
2025-04-21 01:44:34 +00:00
Alex Macleod
8843067aec manual_ok_err: don't lint subpatterns 2025-04-20 22:52:40 +00:00
Alex Macleod
077475f1a5
ptr_cast_constness: show snippet from the right context (#14622)
changelog: [`ptr_cast_constness`]: do not replace suggestion by content
of macro

Fixes rust-lang/rust-clippy#14621
2025-04-20 17:18:52 +00:00
yanglsh
c6d76bb69d fix: needless_collect does not consider side effects 2025-04-19 16:45:58 +08:00
yanglsh
86a10f01d1 fix: double_ended_iterator_last FP when iter has side effects 2025-04-19 16:45:58 +08:00
Alex Macleod
b52bd96713 Replace interning of string literals with preinterned symbols 2025-04-18 22:44:16 +00:00
Timo
781fdab9a9
Move internal lints to their own crate (#13223)
This makes it so switching the internal feature on/off no longer
rebuilds `clippy_lints`.

r? @flip1995

changelog: none
2025-04-18 12:04:08 +00:00
Timo
bcd76c3384
empty_enum_variants_with_brackets: Do not lint reachable enums and enum variants used as functions in the same crate (#12971)
Fixes #12551

changelog: [`empty_enum_variants_with_brackets`]: Do not lint reachable
enums or enums which are used as functions within the same crate.

r? @xFrednet
2025-04-18 09:45:02 +00:00
Matthias Krüger
ed892e72dd Rollup merge of #139615 - nnethercote:rm-name_or_empty, r=jdonszelmann
Remove `name_or_empty`

Another step towards #137978.

r? ``@jdonszelmann``
2025-04-18 05:16:29 +02:00
Matthias Krüger
66dd172961 Rollup merge of #138528 - dianne:implicit-deref-patterns, r=Nadrieril
deref patterns: implement implicit deref patterns

This implements implicit deref patterns (per https://hackmd.io/4qDDMcvyQ-GDB089IPcHGg#Implicit-deref-patterns) and adds tests and an unstable book chapter.

Best reviewed commit-by-commit. Overall there's a lot of additions, but a lot of that is tests, documentation, and simple(?) refactoring.

Tracking issue: #87121

r? ``@Nadrieril``
2025-04-18 05:16:28 +02:00
Philipp Krones
e294f94448
Rustup (#14647)
r? @ghost

changelog: none
2025-04-17 16:43:03 +00:00
Philipp Krones
8a0b225605
Bump nightly version -> 2025-04-17 2025-04-17 18:38:03 +02:00
Philipp Krones
de90fa42dd
Merge remote-tracking branch 'upstream/master' into rustup 2025-04-17 18:36:59 +02:00
Aneesh K
fa9254feaf
Do not lint reachable enums and enum variants used as functions in the same crate 2025-04-17 21:59:06 +05:30
dswij
94f0994b1b
Check for lifetime uses in closures as well (#14608)
The `BodyLifetimeChecker` which checks for the use of any non-anonymous
non-static lifetime did not recurse into closures, missing lifetime
uses. This would lead to a bogus elision suggestion.

The `BodyLifetimeChecker` is not refined enough to avoid false
positives, as any conforming lifetime, including one coming from the
outer context, would be considered a hit. The number of false positives
might increase now that we check closures as well, in case those
closures define and use lifetimes themselves.

changelog: [`needless_lifetimes`]: do not suggest removing a lifetime
which is later used in a closure

Fixes rust-lang/rust-clippy#14607
2025-04-17 16:14:31 +00:00
Jason Newcomb
26f43ff346
match_single_binding: allow macros in scrutinee and patterns (#14635)
changelog: [`match_single_binding`]: allow macros in scrutinee and
patterns

Fixes rust-lang/rust-clippy#14634
2025-04-17 14:58:53 +00:00
Samuel Tardieu
a49ea2d63d
fix: unnecessary_lazy_evaluations suggests wrongly for async closure (#14644)
Closes rust-lang/rust-clippy#14578

changelog: [`unnecessary_lazy_evaluations`] fix wrong suggestions for
async closure
2025-04-17 14:42:15 +00:00
yanglsh
5a1dbea052 fix: unnecessary_lazy_evaluations suggests wrongly for async closure 2025-04-17 22:00:57 +08:00
Timo
ac88357f83
New lint: swap_with_temporary (#14046)
This lint detects inefficient or useless `{std,core}::mem::swap()` calls
such as:

```rust
    // Should be `a = temp();`
    swap(&mut a, &mut temp());
    // Should be `*b = temp();`
    swap(b, &mut temp());
    // Should be `temp1(); temp2();` if we want to keep the side effects
    swap(&mut temp1(), &mut temp2());
```

It also takes care of using a form appropriate for a `()` context if
`swap()` is part of a larger expression (don't ask me why this wouldn't
happen, I have no idea), by suggesting `{ x = y; }` (statement in block)
or `{std,core}::mem::drop((temp1(), temp2())`.

changelog: [`swap_with_temporary`]: new lint

Close #1968
2025-04-17 12:42:46 +00:00
Samuel Tardieu
05448bd9c7 New lint: swap_with_temporary 2025-04-17 13:17:43 +02:00
Timo
30e9cd5a26
Do not recurse forever in significant_drop_tightening (#14641)
Limit the recursion depth, as each level of nesting adds another deeper
projection.

There might be a more complex way of handling the problem, but infinite
recursions are bad, and don't allow Clippy to terminate properly.

changelog: [`significant_drop_tightening`]: do not recurse forever when
checking for attribute on type or its constituent

Fixes rust-lang/rust-clippy#13544

@rustbot label +L-nursery
2025-04-17 11:09:01 +00:00
Samuel Tardieu
cc6a3d8cd5 Do not recurse forever in significant_drop_tightening
Limit the recursion depth, as each level of nesting adds another deeper
projection.
2025-04-17 12:58:14 +02:00
Philipp Krones
3479fdfe4f
Add note feature to triagebot's config (#14620)
This will let people [add summary
notes](https://forge.rust-lang.org/triagebot/note.html) to an issue, for
example to add that an issue is best kept for first-timers.

changelog: none

I wanted to use it in
https://github.com/rust-lang/rust-clippy/issues/14617#issuecomment-2807090281.
2025-04-17 09:37:22 +00:00
Manish Goregaokar
949b3bcfb5
bool_to_int_with_if: properly handle macros (#14629)
- Do not replace macro results in then/else branches
- Extract condition snippet from the right context
- Make suggestion `MaybeIncorrect` if it would lead to losing comments

changelog: [`bool_to_int_with_if`]: properly handle macros

Fixes rust-lang/rust-clippy#14628
2025-04-17 02:15:21 +00:00
Alejandra González
222660bb36
Build complete usable type from a type-relative prefix (#14586)
Instead of looking for angle brackets in the source code, use the HIR
and Ty interfaces to either copy the original type, or complete it with
`_` placeholders if all type and const generic arguments are inferred.

Fixes rust-lang/rust-clippy#14581

changelog: [`from_iter_instead_of_collect`]: show correct type in
suggestion
2025-04-17 00:09:51 +00:00
Nicholas Nethercote
097c9c7542 Replace infallible name_or_empty methods with fallible name methods.
I'm removing empty identifiers everywhere, because in practice they
always mean "no identifier" rather than "empty identifier". (An empty
identifier is impossible.) It's better to use `Option` to mean "no
identifier" because you then can't forget about the "no identifier"
possibility.

Some specifics:
- When testing an attribute for a single name, the commit uses the
  `has_name` method.
- When testing an attribute for multiple names, the commit uses the new
  `has_any_name` method.
- When using `match` on an attribute, the match arms now have `Some` on
  them.

In the tests, we now avoid printing empty identifiers by not printing
the identifier in the `error:` line at all, instead letting the carets
point out the problem.
2025-04-17 09:50:52 +10:00
Samuel Tardieu
91658a7739
samueltardieu: vacation for ~3 weeks (#14636)
changelog: none

r? ghost
2025-04-16 21:41:21 +00:00
Samuel Tardieu
6c4c3a5e1a samueltardieu: vacation for ~3 weeks 2025-04-16 23:35:28 +02:00
Samuel Tardieu
10a83274e2 match_single_binding: allow macros in scrutinee and patterns 2025-04-16 23:15:20 +02:00
Samuel Tardieu
0bfcd0d3bc bool_to_int_with_if: properly handle macros
- Do not replace macro results in then/else branches
- Extract condition snippet from the right context
- Make suggestion `MaybeIncorrect` if it would lead to losing comments
2025-04-16 20:25:15 +02:00
Samuel Tardieu
8eed35023f
New lint: redundant_test_prefix (#13710)
This PR has started as an effort to proceed from the feedback in
rust-lang/rust-clippy#12861.

- Checks test functions (functions marked with `#[test]` annotation) for
redundant "test_" prefix.
- Auto-fix is supported (and handles collisions gracefully, see below).
- If removing "test_" prefix from, say, `test_foo()` results in a name
collision (either because function `foo()` is already defined within the
current scope, or because the `foo()` call exists within function --
thus creating an unwanted recursion), lint suggests function rename,
warning the user that a simple trimming of `test_` prefix will result in
a name collision.
- If removing "test_" prefix results in invalid identifier (consider
`test_const`, `test_`, `test_42`), then again no auto-fix is suggested,
user is asked to rename function, with a note that a simple prefix
trimming will result in an invalid function name.
(`Applicability::HasPlaceholders` is used and user is suggested to: drop
`test_` prefix + add `_works` suffix, i.e. `test_foo` becomes
`foo_works` -- but again, user has to apply those changes manually).
- If trimmed version of the function name is a valid identifier, doesn't
result in name collision or unwanted recursion, then user is able to run
auto-fix.

fixes rust-lang/rust-clippy#8931

changelog: new lint: [`redundant_test_prefix`]
2025-04-16 06:15:18 +00:00