Commit Graph

2177 Commits

Author SHA1 Message Date
Linshu Yang a255ac1d82 fix: map_with_unused_argument_over_ranges wrongly unmangled macros 2026-03-23 02:07:09 +00:00
Philipp Krones 1e283ba0ce Merge remote-tracking branch 'upstream/master' into rustup 2026-03-21 13:40:20 +01:00
Teodoro Freund c455f7ce52 Refactors to unnecessary_{option,result}_map_or_else:
- When checking if a function is an identity function, try to use existing functionalities.
- Some cases are no longer supported, but they were buggy
2026-03-15 09:20:27 +00:00
Nicholas Nethercote f599afe624 Move Spanned.
It's defined in `rustc_span::source_map` which doesn't make any sense
because it has nothing to do with source maps. This commit moves it to
the crate root, a more sensible spot for something this basic.
2026-03-11 06:25:23 +11:00
Alejandra González bc2a571167 Do not materialize snippets when it is not needed to (#16666)
It is not necessary to materialize snippets into `String` objects just
to check if they contain comments for example.

changelog: none

r? @blyxyas
(for perf measurements)
2026-03-09 10:58:41 +00:00
Samuel Tardieu 1ecc9d7e04 Fix ICE in match_same_arms
The wrong `TypeckResults` was used in the fallback equality function
passed by the `match_same_arms` and `filter_map` lints. Previously,
those fallback functions had no way of using the proper `TypeckResults`.
Those (one per expression being compared) are now passed to the
registered fallback function.
2026-03-07 20:13:56 +01:00
Samuel Tardieu f22848a09d Changelog for Clippy 1.94 (#16653)
Violets are red,
Roses are blue,
Winter feels endless…
But warm days are coming soon too.

----

Chimmi from @OwenFeik is the winner at
https://github.com/rust-lang/rust-clippy/pull/16413

<img width="3072" height="3565" alt="image"
src="https://github.com/user-attachments/assets/3c6ecc36-747d-40df-b2f5-bc141dc0b227"
/>

Sounds like an already professional balancer

----

Cats for the next release can be nominated in the comments

changelog: none

r? flip1995
2026-03-06 07:17:28 +00:00
Samuel Tardieu b5f63104b2 Do not materialize snippets when it is not needed to
It is not necessary to materialize snippets into `String` objects just
to check if they contain comments for example.
2026-03-05 23:19:49 +01:00
Philipp Krones b4d2445432 Merge commit 'e645f93552c3926a0bb481a777df120b7bce986f' 2026-03-05 17:18:20 +01:00
Philipp Krones eb386eca43 Merge remote-tracking branch 'upstream/master' into rustup 2026-03-05 16:59:08 +01:00
Aliaksei Semianiuk 9a224202e4 Changelog for Clippy 1.94 2026-03-05 16:54:05 +01:00
Samuel Tardieu 00a00ebaee clippy_dev: Sort lint and lint pass declarations (parsing revamp part 5/N) (#15979)
Based on rust-lang/rust-clippy#15978

This will prevent some pointless merge conflict when multiple people add
lints to the same lint pass (e.g. methods).

changelog: None
2026-03-05 15:03:04 +00:00
Alejandra González 3120b98d6c Optimize allow_unwrap_types evaluation to eliminate performance regression (#16652)
Fixes https://github.com/rust-lang/rust-clippy/pull/16605

This PR addresses the 6.2% compilation performance regression introduced
by the original `allow_unwrap_types` implementation (which natively
allocated AST strings on every `unwrap` call via `bumpalo`).

The implementation has been refactored to pre-resolve types securely
without a performance penalty:

**Pre-Resolution Cache via `LateLintPass`**: Instead of executing
`ty.to_string()` and `lookup_path_str` inside the immediate
`unwrap_expect_used` hot check for every method call encountered,
`allow-unwrap-types` configuration strings are now parsed exactly *once*
per crate compilation during the `LateLintPass::check_crate` hook in
`clippy_lints/src/methods/mod.rs`.
**`DefId` Native Storage**: The parsed `DefId` representations are
stored in-memory using highly efficient caching maps directly on the
main `Methods` struct:
- `unwrap_allowed_ids: FxHashSet<DefId>`: Allows instant O(1) lookups
for standard types.
- `unwrap_allowed_aliases: Vec<DefId>`: Tracks type aliases requiring
signature substitution checking later.
**Execution Relief**: Inside `unwrap_expect_used::check()`, string
manipulation is completely removed and `ty::Adt` checking uses
lightning-fast `.contains(&adt.did())` operations to categorically avoid
regression allocation loops. This implementation strongly parallels the
pre-resolution type-routing logic in
`clippy_config::types::create_disallowed_map` without altering the core
`clippy.toml` config requirements.

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

-
[Beta-nomination](https://github.com/rust-lang/rust-clippy/pull/16652#issuecomment-3976671413)
by [samueltardieu](https://github.com/samueltardieu)

*Managed by `@rustbot`—see
[help](https://forge.rust-lang.org/triagebot/note.html) for details*

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
changelog: none
2026-03-03 23:45:14 +00:00
Jason Newcomb e16c838439 clippy_dev: Sort all lint and lint pass declarations. 2026-03-03 14:40:35 -05:00
Jason Newcomb 1f2be4e71b clippy_dev: Parse and format lint pass macros. 2026-03-03 14:40:35 -05:00
kawkoi 7ac8be4a48 optimize allow unwrap types 2026-03-03 20:34:21 +05:30
Ada Alakbarova c91298aaa0 refactor(clippy_utils::mir::visit_local_usage): use const generics
encodes the direct relationship between the lengths of `locals` and the
returned list, making the code more type-safe
2026-02-25 22:07:46 +01:00
mu001999 6d483b6b76 Remove redundant self usages 2026-02-25 22:51:53 +08:00
Philipp Krones 088022c7d4 Merge commit 'df995ede1b3e61f0e87081d9548e6cd2a3ec9095' into clippy-subtree-update 2026-02-24 12:00:51 +01:00
Samuel Tardieu 0492671fc8 Fix join_absolute_paths to work correctly depending on the platform (#16610)
Fixes rust-lang/rust-clippy#16607.

changelog: [`join_absolute_paths`]: remove both backslashes for calls to
`Path::join`.
2026-02-22 18:30:27 +00:00
mikhailofff 34d0b12346 correct join_absolute_paths for a double backslash 2026-02-22 22:12:09 +04:00
llogiq 739f462498 Enhance manual_is_variant_and to cover filter chaining is_some (#16521)
Closes rust-lang/rust-clippy#16518

changelog: [`manual_is_variant_and`] extend to cover `filter` chaining
`is_some`
2026-02-22 14:56:40 +00:00
llogiq ad08bd62dd Enhance collapsible_match to cover if-elses (#16560)
Closes rust-lang/rust-clippy#16558

changelog: [`collapsible_match`] extend to cover if-elses
2026-02-22 13:07:10 +00:00
Nicholas Nethercote 180e4a7155 Remove impl IntoQueryParam<P> for &'a P.
`IntoQueryParam` is a trait that lets query callers be a bit sloppy with
the passed-in key.
- Types similar to `DefId` will be auto-converted to `DefId`. Likewise
  for `LocalDefId`.
- Reference types will be auto-derefed.

The auto-conversion is genuinely useful; the auto-derefing much less so.
In practice it's only used for passing `&DefId` to queries that accept
`DefId`, which is an anti-pattern because `DefId` is marked with
`#[rustc_pass_by_value]`.

This commit removes the auto-deref impl and makes the necessary sigil
adjustments. (I generally avoid using `*` to deref manually at call
sites, preferring to deref via `&` in patterns or via `*` in match
expressions. Mostly because that way a single deref often covers
multiple call sites.)
2026-02-22 17:58:54 +11:00
Samuel Tardieu d074e48dcb feat(clone_on_ref_ptr): don't add a & to the receiver if it's a reference (#15742)
Fixes https://github.com/rust-lang/rust-clippy/issues/15741

changelog: [clone_on_ref_ptr]: don't add a `&` to the receiver if it's a
reference
2026-02-21 22:47:41 +00:00
llogiq 819373451c Add allow-unwrap-types configuration for unwrap_used and expect_used (#16605)
rust-lang/rust-clippy#16535

This PR introduces a new configuration option, `allow-unwrap-types`,
which accepts a list of type paths (e.g., `["std::sync::LockResult"]`).
When configured, calling `.unwrap()` or `.expect()` on values of these
types will no longer trigger the `unwrap_used` or `expect_used` lints.

This is particularly useful for reducing noisy lints on patterns where
unwrapping is widely considered acceptable or expected by design, such
as obtaining a `std::sync::LockResult` from `Mutex::lock()`.

**Changes Made**
Introduced the `allow_unwrap_types: Vec<String>` field in
`clippy_config`.
Updated the `unwrap_expect_used` lint to check the underlying evaluated
expression `ty` against the configured allowed types.
Handled robust type alias resolution so that aliases like
`std::sync::LockResult` accurately map to their underlying `Adt` types
during lint evaluation.
Added UI tests in `tests/ui-toml/unwrap_used_allowed/` to verify both
allowed and disallowed cases.

----

changelog: [`unwrap_used`], [`expect_used`]: Add `allow-unwrap-types`
configuration to allow unwrapping specified types.
2026-02-21 21:59:26 +00:00
Ada Alakbarova b0a25d208f feat(clone_on_ref_ptr): don't add a & to the receiver if it's a reference 2026-02-21 22:35:51 +01:00
llogiq 9de20be009 Make unnecessary_fold commutative (#16604)
To be honest, the changes are confusing.

First of all, it has already been stated that it would be wrong if we
extended the lint to cover both sides.

https://github.com/rust-lang/rust-clippy/blob/18e5b2db4a3f9de20aa472d5c46a855e3a31d5c4/tests/ui/unnecessary_fold.rs#L91-L95

Secondly, there is some monstrous expression in the
`get_triggered_expr_span` function, and I think it could be rewritten
more cleanly.

Anyway, even if it has to be implemented, I'm glad to rewrite it more
thoroughly.

Fixes rust-lang/rust-clippy#16581.

----

changelog: [`unnecessary_fold`]: match against an accumulator on both
sides.
2026-02-21 18:01:43 +00:00
kawkoi b84fc43413 allow unwrap types 2026-02-21 21:52:58 +05:30
mikhailofff 92fb0f7899 make unnecessary_fold commutative 2026-02-21 18:37:47 +04:00
bors bd73fa0d17 Auto merge of #152624 - camsteffen:symbols-audit, r=petrochenkov
Audit Symbols

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152624)*

Remove unused symbols and hoist some symbols to Clippy.
2026-02-21 06:44:20 +00:00
dswij 18e5b2db4a Fix unnecessary_min_or_max for usize (#16575)
Fixes: rust-lang/rust-clippy#16555

changelog: [unnecessary_min_or_max]: Fix false negatives for
usize::{MIN,MAX} by handling usize bit width correctly during constant
evaluation, enabling the lint to trigger on cases like n.min(0) /
n.max(usize::MAX).
2026-02-20 15:53:19 +00:00
Jana Dönszelmann 87b3f55b16 fix src/tools 2026-02-20 10:35:52 +01:00
Cameron Steffen 17a6d61dc9 Audit Symbols 2026-02-19 19:27:33 -06:00
Taym Haddadi 4916d95381 Fix unnecessary_min_or_max for usize
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
2026-02-19 09:24:28 +01:00
Esteban Küber 5fef4429d1 Make all multipart suggestions verbose
The ShowAlways style of suggestions is usually easier to understand than the inline style.
2026-02-18 18:33:35 +00:00
Jason Newcomb 24cccf9f29 Fix redundant_iter_cloned false positive with move closures and coroutines (#16494)
Fixes rust-lang/rust-clippy#16428

changelog: [`redundant_iter_cloned`]: fix false positive with move
closures and coroutines
2026-02-17 12:36:20 +00:00
linshuy2 5be3049e9c Apply collapsible_match to Clippy itself 2026-02-15 00:27:19 +00:00
dswij 0f4f81df13 Make iter_kv_map to cover flat_map and filter_map (#16519)
Closes rust-lang/rust-clippy#16515

changelog: [`iter_kv_map`] extend to cover `flat_map` and `filter_map`
2026-02-13 14:49:42 +00:00
Philipp Krones c8fd55b457 Merge commit 'a62c6af53676bb15a40488ce2d632de558f001de' into clippy-subtree-update 2026-02-12 14:50:58 +01:00
Philipp Krones c9841a63af Merge remote-tracking branch 'upstream/master' into rustup 2026-02-11 20:02:28 +01:00
Yuri Astrakhan 236dac8d0e fix: remove unnecessary trailing commas in format strings
This PR makes the new comma-removing lint PR less noisy, allowing it focus only on the new functionality
2026-02-07 14:02:33 -05:00
linshuy2 8a31b2f698 Apply manual_is_variant_and to Clippy itself 2026-02-05 23:34:41 +00:00
linshuy2 2753bf0954 Extend manual_is_variant_and to cover filter chaining is_some 2026-02-05 23:21:24 +00:00
linshuy2 91de07da54 Extend iter_kv_map to cover flat_map and filter_map 2026-02-05 22:40:58 +00:00
lapla d0c6a64ff8 Fix redundant_iter_cloned false positive with move closures and coroutines 2026-02-03 20:27:54 +09:00
dswij b3d81e3009 str_split: reduce suggestion diff (#16418)
Now, only `call_span` is replaced, so the receiver is not a part of the
diff. This also removes the need to create a snippet for the receiver.

changelog: [`str_split`]: reduce suggestion diff
2026-02-02 15:24:38 +00:00
linshuy2 631120b803 fix: unwrap_used and expect_used FN when using fully qualified syntax 2026-01-31 17:59:50 +00:00
Frank King cdee2fbff5 refactor: add an enum DerefAdjustKind in favor of Option<OverloadedDeref> 2026-01-31 16:25:32 +08:00
Jason Newcomb 1b33602298 Make manual_is_variant_and to cover manual is_none_or (#16424)
Closes rust-lang/rust-clippy#16419

changelog: [`manual_is_variant_and`] enhance to cover manual
`is_none_or`
2026-01-25 23:04:35 +00:00