2059 Commits

Author SHA1 Message Date
Samuel Tardieu
e16801e68c
Use symbols instead of &str when possible 2025-05-19 22:47:57 +02:00
Samuel Tardieu
82bf659dc8
Ensure that symbols list stays sorted 2025-05-19 22:47:57 +02:00
Samuel Tardieu
bb724f3421
Sort the existing list of symbols 2025-05-19 22:47:57 +02:00
Samuel Tardieu
ebc2a68fe8
Add new useless_concat lint (#13829)
Fixes #13793.

Interestingly enough, to actually check that the macro call has at least
two arguments, we need to use the rust lexer after getting the original
source code snippet.

changelog: Add new `useless_concat` lint
2025-05-19 15:11:37 +00:00
Timo
daeb6a1d18
Misc changes (#14702)
This mainly fixes `with_leading_whitespace` not always adding the
whitespace it can.

changelog: None
2025-05-17 10:40:21 +00:00
llogiq
94cfebb397
Rewrite non_copy_const (#13207)
fixes #12979
fixes #12951
fixes #13233

Tests still need to be finished and the docs still need to be updated,
but this should otherwise ready.

changelog: Lint `declare_interior_mutable_const` and
`borrow_interior_mutable_const` more precisely
2025-05-16 15:05:36 +00:00
Samuel Tardieu
feb70b51c4
match_same_arms, ifs_same_cond: lint once per same arm/condition (#14637)
A large fraction of the lints emitted in CI lintcheck come from [this
`match`](https://github.com/unicode-rs/unicode-normalization/blob/v0.1.23/src/tables.rs#L34289),
currently for `n` same arms `((n - 1) * n)/2` lints are emitted, with
this change it will be emitted as a single lint

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

changelog: none
2025-05-16 14:16:45 +00:00
Alex Macleod
39ab00a3a1 match_same_arms, ifs_same_cond: lint once per same arm/condition 2025-05-16 12:56:25 +00:00
Jason Newcomb
57782e0ff1 Rewrite non_copy_const 2025-05-16 06:08:35 -04:00
Philipp Krones
0bb1b5bd3b
Merge remote-tracking branch 'upstream/master' into rustup 2025-05-15 19:19:08 +02:00
Guillaume Gomez
0d25090d26 Improve code and apply suggestions 2025-05-14 19:05:05 +02:00
llogiq
7bac114c86
Add new lint: cloned_ref_to_slice_refs (#14284)
Added lint for catching `&[foo.clone()]` where foo is a reference and
suggests `std::slice::from_ref(foo)`.

changelog: new lint: [`cloned_ref_to_slice_refs`]
2025-05-13 05:32:33 +00:00
asdfish
40e1b0ed00 add lint cloned_ref_to_slice_refs
remove merge

removed false positive and improved tests

clarify known problems for `cloned_ref_to_slice_refs`
2025-05-12 21:12:58 -04:00
Guillaume Gomez
7b06d2b776 Move concat macro path into clippy_utils::paths 2025-05-12 14:14:45 +02:00
dswij
f60807dfee
Resolve through local re-exports in lookup_path (#14772)
Fixes https://github.com/rust-lang/rust-clippy/issues/14767

A long standing issue revealed by
https://github.com/rust-lang/rust-clippy/pull/14397

changelog: none
2025-05-10 16:55:19 +00:00
Samuel Tardieu
bde939058b
char::is_digit() is const-stable only since Rust 1.87
The `to_digit_is_some()` lint suggests using `char::is_digit()`. It
should not trigger in const contexts before Rust 1.87.
2025-05-10 00:20:55 +02:00
Alex Macleod
e4d82aefd9 Resolve through local re-exports in lookup_path 2025-05-09 22:13:35 +00:00
Michael Goulet
303c4ecfdd Require T: TypeFoldable in Binder<T> visit 2025-05-07 16:00:21 +00:00
Alex Macleod
5aac708398 Replace Symbol::as_str usage in match expressions 2025-05-07 13:52:11 +00:00
Jason Newcomb
77157f5988 Actually check for a problematic line comment in with_leading_whitespace 2025-05-06 21:42:32 -04:00
Jason Newcomb
a25c195101 Remove redundant work in trait_ref_of_method. 2025-05-06 21:42:04 -04:00
Alex Macleod
737d3b3363 Remove some unused #![feature]s 2025-05-06 14:07:39 +00:00
Samuel Tardieu
50e0bf1b71
Gate collapsible_if let_chains lints on edition 2024 and MSRV (#14723)
The MSRV being for crates targeting 1.85-1.87 on edition 2024

This enables the lint for regular nightly users without the feature gate
enabled

r? @samueltardieu

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

changelog: none
2025-05-06 05:40:37 +00:00
Alex Macleod
8c93668a71 Gate collapsible_if let_chains lints on edition 2024 and MSRV 2025-05-06 02:23:28 +00:00
Alex Macleod
f23772ce8c Move lookup_path and similar into clippy_utils::paths 2025-05-04 17:13:02 +00:00
Alex Macleod
b768fbe4bc Replace str path utils with new PathLookup type 2025-05-04 15:26:37 +00:00
Manish Goregaokar
56f018286b
fix: manual_slice_fill FP on IndexMut overload (#14719)
Closes rust-lang/rust-clippy#14685

changelog: [`manual_slice_fill`] fix FP on `IndexMut` overload
2025-05-02 17:07:07 +00:00
yanglsh
33ea0b482c fix: manual_slice_fill FP on IndexMut overload 2025-05-02 15:09:00 +08:00
dswij
a53acefef7
Remove is_normalizable (#14717)
Supersedes rust-lang/rust-clippy#12550

`layout_of` no longer contains a `delay_bug` so there's no need for this
anymore.

changelog: None
2025-05-01 16:45:14 +00:00
Philipp Krones
dd5113daab Merge commit '03a5b6b976ac121f4233775c49a4bce026065b47' into clippy-subtree-update 2025-05-01 10:22:55 +02:00
Philipp Krones
43797675c2
Merge remote-tracking branch 'upstream/master' into rustup 2025-05-01 09:50:42 +02:00
Jason Newcomb
36c3617bb1 Remove is_normalizable. layout_of no longer contains a delay_bug. 2025-04-30 19:31:24 -04:00
Oli Scherer
bca637ce5d Add or-patterns to pattern types 2025-04-28 07:50:18 +00:00
Timo
0dd9722cdc
Replace some Symbol::as_str usage (#14679)
Follow up to https://github.com/rust-lang/rust-clippy/pull/14650

Replaces uses in the form `s.as_str() == "literal"`

r? @y21

changelog: none
2025-04-27 12:56:14 +00:00
Alex Macleod
7b337f6e25 Replace some Symbol::as_str usage 2025-04-25 01:03:03 +00:00
Alex Macleod
736be8bbb1 Consistently refer to the ? operator 2025-04-24 13:40:57 +00:00
Philipp Krones
dd5948ccc2 Clippy: Fix doc issue 2025-04-23 10:51:22 +02:00
Philipp Krones
ff428d91c2 Merge commit '0621446356e20fd2ead13a6763bb936c95eb0cfa' into clippy-subtree-update 2025-04-22 18:24:43 +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
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
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
Philipp Krones
de90fa42dd
Merge remote-tracking branch 'upstream/master' into rustup 2025-04-17 18:36:59 +02: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
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
Nicholas Nethercote
4d47d7f38c Rename LifetimeName as LifetimeKind.
It's a much better name, more consistent with how we name such things.

Also rename `Lifetime::res` as `Lifetime::kind` to match. I suspect this
field used to have the type `LifetimeRes` and then the type was changed
but the field name remained the same.
2025-04-16 07:16:40 +10:00
Victor Farazdagi
e2422a618d new lint: redundant_test_prefix 2025-04-15 14:42:09 +03:00
Alejandra González
02764f611a
Various fixes for manual_is_power_of_two (#14463)
Fix #14461:

- insert parentheses as required in suggestion
- check MSRV before suggesting fix in `const` context
- do not lint macro expansion result

Commits have been logically separated to facilitate review, and start
with a refactoring (and simplification) of the existing code.

changelog: [`manual_is_power_of_two`]: insert parentheses as required in
suggestion, check MSRV before suggesting fix in `const` context, do not
lint macro expansion results
2025-04-14 22:56:38 +00:00