Commit Graph

2113 Commits

Author SHA1 Message Date
Samuel Tardieu fe4b4e8329 mem::size_of_val is const-stable since Rust 1.85 2025-05-14 23:38:37 +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
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
Alex Macleod 5aac708398 Replace Symbol::as_str usage in match expressions 2025-05-07 13:52:11 +00: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 8a91bbfa91 Bump nightly version -> 2025-05-01 2025-05-01 09:50:54 +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 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
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 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
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
Samuel Tardieu 4d343d56e1 Check MSRV before suggesting fix in const context 2025-04-14 22:05:44 +02:00
Nicholas Nethercote d891f77363 Move has_self field to hir::AssocKind::Fn.
`hir::AssocItem` currently has a boolean `fn_has_self_parameter` field,
which is misplaced, because it's only relevant for associated fns, not
for associated consts or types. This commit moves it (and renames it) to
the `AssocKind::Fn` variant, where it belongs.

This requires introducing a new C-style enum, `AssocTag`, which is like
`AssocKind` but without the fields. This is because `AssocKind` values
are passed to various functions like `find_by_ident_and_kind` to
indicate what kind of associated item should be searched for, and having
to specify `has_self` isn't relevant there.

New methods:
- Predicates `AssocItem::is_fn` and `AssocItem::is_method`.
- `AssocItem::as_tag` which converts `AssocItem::kind` to `AssocTag`.

Removed `find_by_name_and_kinds`, which is unused.

`AssocItem::descr` can now distinguish between methods and associated
functions, which slightly improves some error messages.
2025-04-14 16:13:04 +10:00
Nicholas Nethercote e6dc2e9be0 Use Symbol in LateContext::get_associated_type.
To avoid unnecessary interning.
2025-04-14 16:12:21 +10:00
Jacob Pratt 984931915a Rollup merge of #139662 - nnethercote:tweak-DefPathData, r=compiler-errors
Tweak `DefPathData`

Some improvements in and around `DefPathData`, following on from #137977.

r? `@spastorino`
2025-04-11 21:21:01 +02:00
Alex Macleod ac4c69f423 implicit_return: better handling of asynchronous code (#14446)
Blocks created by desugaring will not contain an explicit `return`. Do
not suggest to add it when the user has no control over the desugared
code.

Also, ensure that in a `xxx.await` expression, the suggested `return` is
emitted before the whole expression, not before the `await` keyword.

Fix #14411

changelog: [`implicit_return`]: fix proposed `return` position in the
presence of asynchronous code
2025-04-11 13:39:03 +00:00
Nicholas Nethercote 595c8f9c8c Introduce DefPathData::AnonAssocTy.
PR #137977 changed `DefPathData::TypeNs` to contain `Option<Symbol>` to
account for RPITIT assoc types being anonymous. This commit changes it
back to `Symbol` and gives anonymous assoc types their own variant. It
makes things a bit nicer overall.
2025-04-11 19:08:14 +10:00
Stuart Cook 65105f1324 Rollup merge of #138682 - Alexendoo:extra-symbols, r=fee1-dead
Allow drivers to supply a list of extra symbols to intern

Allows adding new symbols as `const`s in external drivers, desirable in Clippy so we can use them in patterns to replace code like https://github.com/rust-lang/rust/blob/75530e9f72a1990ed2305e16fd51d02f47048f12/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs#L66

The Clippy change adds a couple symbols as a demo, the exact `clippy_utils` API and replacing other usages can be done on the Clippy side to minimise sync conflicts

---

try-job: aarch64-gnu
2025-04-11 13:31:44 +10:00
Alex Macleod 94ec23934c Allow drivers to supply a list of extra symbols to intern 2025-04-10 13:39:23 +00:00
Nicholas Nethercote 328b4fa9fe Rename some name variables as ident.
It bugs me when variables of type `Ident` are called `name`. It leads to
silly things like `name.name`. `Ident` variables should be called
`ident`, and `name` should be used for variables of type `Symbol`.

This commit improves things by by doing `s/name/ident/` on a bunch of
`Ident` variables. Not all of them, but a decent chunk.
2025-04-10 09:30:55 +10:00
Samuel Tardieu e463309f4a add manual_abs_diff lint (#14482)
changelog: [`manual_abs_diff`]: Initial implementation

Hey, first time writing a new lint for clippy, hope I got it right. I
think it's pretty self-explanatory!
Added a few `fixme` test cases, where the lint can be improved to catch
more (probably rare) patterns, but opening a PR with this initial
implementation to make sure I'm on the right track, and that this lint
is acceptable at all.

😁
2025-04-09 10:29:48 +00:00
Stuart Cook 76d5a26fb2 Rollup merge of #139035 - nnethercote:PatKind-Missing, r=oli-obk
Add new `PatKind::Missing` variants

To avoid some ugly uses of `kw::Empty` when handling "missing" patterns, e.g. in bare fn tys. Helps with #137978. Details in the individual commits.

r? ``@oli-obk``
2025-04-07 22:29:17 +10:00
Philipp Krones c97bd7463c Bump Clippy version -> 0.1.88 2025-04-03 21:32:37 +02:00