Commit Graph

11104 Commits

Author SHA1 Message Date
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
llogiq dcb8800b2d useless_conversion: also fire inside compiler desugarings (#16594)
Using `e.span.from_expansion()` alone prevented the lint from firing
within compiler-desugared expressions, e.g. `async fn`, `for` loops, or
`?`.

changelog: [`useless_conversion`]: also fire inside compiler desugarings

close rust-lang/rust-clippy#16590
2026-02-22 13:02:19 +00:00
Samuel Tardieu 394afbe88f Remove no-rustfix marker for tests with no lint suggestions 2026-02-22 12:30:39 +01: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
Samuel Tardieu 296fe3a74a Make unchecked_time_subtraction to better handle Duration literals (#16528)
Closes rust-lang/rust-clippy#16499

changelog: [`unchecked_time_subtraction`] extend to better handle
`Duration` literals
2026-02-21 18:14:14 +00:00
linshuy2 ef1ee71666 Enhance unchecked_time_subtraction to better handle Duration literals 2026-02-21 18:04:19 +00: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
Jason Newcomb 349e809e6f Handle Result<T, !> and ControlFlow<!, T> as T wrt #[must_use] (#16353)
There is a proposal to change the behaviour of rustc's `must_use` lint
to consider `Result<T, U>` and `ControlFlow<U, T>` as `T` when `U` is
uninhabited. See <https://github.com/rust-lang/rust/pull/148214>.

This might make the user adding extra `#[must_use]` attributes to
functions returning `Result<T, !>` or `ControlFlow<!, T>`, which would
trigger the `double_must_use` lint in Clippy without the current change.

changelog: [`double_muse_use`, `drop_non_drop`,
`let_underscore_must_use`]: consider `Result<T, U>` and `ControlFlow<U,
T>` as `T` wrt the `#[must_use]` attribute if `U` is uninhabited.
2026-02-21 17:57:22 +00:00
kawkoi b84fc43413 allow unwrap types 2026-02-21 21:52:58 +05:30
Samuel Tardieu 5137bb3ceb Handle Result<T, !> and ControlFlow<!, T> as T wrt #[must_use]
There is a proposal to change the behaviour of rustc's `must_use` lint
to consider `Result<T, U>` and `ControlFlow<U, T>` as `T` when `U` is
uninhabited. See <https://github.com/rust-lang/rust/pull/148214>.

This might make the user adding extra `#[must_use]` attributes to
functions returning `Result<T, !>` or `ControlFlow<!, T>`, which would
trigger the `double_must_use` lint in Clippy without the current change.
2026-02-21 15:48:33 +01:00
mikhailofff 92fb0f7899 make unnecessary_fold commutative 2026-02-21 18:37:47 +04:00
Samuel Tardieu 5991fd9f76 Add brackets around unsafe or labeled block used in else 2026-02-21 11:10:18 +01: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
Jason Newcomb 70647514ff Add new disallowed_fields lint (#16218)
Fixes https://github.com/rust-lang/rust-clippy/issues/9278.

This is something that we need for `cg_gcc` (cc @antoyo). It's almost
the same as https://github.com/rust-lang/rust-clippy/pull/6674 (which I
used as base).

changelog: Add new `disallowed_fields` lint

r? @samueltardieu
2026-02-20 13:19:36 +00:00
lapla d65fe0bb7c useless_conversion: also fire inside compiler desugarings 2026-02-20 12:11:37 +09:00
Daniel Scherzer e3d2a3153e result-map-unit-fn: use "a" before Result
Rather than "an"
2026-02-19 15:26:16 -08:00
Philipp Krones e96a83b4b7 Merge remote-tracking branch 'upstream/master' into rustup 2026-02-19 15:38:57 +01: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
Samuel Tardieu a25baf60ec fix(str_to_string): false positive non-str types (#16571)
Fix rust-lang/rust-clippy#16569 bug introduced in
rust-lang/rust-clippy#16512

changelog: [`str_to_string`]: fix false positive

r? @samueltardieu
2026-02-19 07:30:24 +00:00
Daniel Szoke (via Pi Coding Agent) b0c4cbaa69 Fix stale metadata output comment in compile-test
DiagnosticCollector currently writes util/gh-pages/index.html, but the

doc comment still said util/gh-pages/lints.json.

The drift came from the switch to HTML generation in b522e7a94

("Generate lint list in HTML directly instead of JS"), which changed

the output file from lints.json to index.html but left this comment

unchanged.
2026-02-18 14:54:55 +00:00
Yuri Astrakhan 1994230db1 fix(str_to_string): false positive non-str types 2026-02-17 14:44:13 -05:00
Esteban Küber b8e86e69ef Unify wording of resolve error
Remove "failed to resolve" and use the same format we use in other resolution errors "cannot find `name`".

```
error[E0433]: cannot find `nonexistent` in `existent`
  --> $DIR/custom_attr_multisegment_error.rs:5:13
   |
LL | #[existent::nonexistent]
   |             ^^^^^^^^^^^ could not find `nonexistent` in `existent`
```
2026-02-17 16:51:44 +00:00
Samuel Tardieu e299e18e54 Remove env macro use from ui tests. (#16580)
`env` requires that the test machine has the variable defined.

changelog: none
2026-02-17 12:38:57 +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
Jason Newcomb bd21958f8b Remove env macro use from ui tests. 2026-02-17 07:16:24 -05:00
Ralf Jung 32d32b6891 adjust clippy to fix some of the issues 2026-02-16 17:27:40 +01:00
linshuy2 5be3049e9c Apply collapsible_match to Clippy itself 2026-02-15 00:27:19 +00:00
linshuy2 904a750f44 Extend collapsible_match to cover if-elses 2026-02-15 00:23:27 +00:00
Samuel Tardieu 18a4108bf2 Fix the compile-test tests when setting Cargo's build.build-dir setting to a path that's distinct from target-dir (#16568)
Fixes rust-lang/rust-clippy#16567.

Fix the compile-test tests when Cargo's `build.build-dir` is set to a
path that's distinct from `target-dir`. Right now, the uitest harness
assumes that `clippy-driver` (a final build artifact) is located in the
parent directory of `compile_test-…` (an intermediate artifact or,
rather, a dependency's final artifact), and that doesn't hold when
`build-dir` is configured independently from `target-dir`, like so (in
~/.cargo/config.toml):

```toml
[build]
build-dir = "{cargo-cache-home}/build-artifacts/{workspace-path-hash}"
```

changelog: none
2026-02-14 22:07:22 +00:00
dswij ad7979b35d Assume that any external function might return a type alias (#16415)
We might not have the declaration around if `extern crate` is used, or
if rust-src is not installed for the standard library. Better err on the
safe side rather than having a behavior depending on what happens to be
available at compile time.

Fixes rust-lang/rust-clippy#14625

changelog: [`unnecessary_cast`]: do not warn on casts of external
function return type
2026-02-14 16:01:27 +00:00
Jacob Adam 2737b26c2e Fix the compile-test tests when setting Cargo's build.build-dir setting to a path that's distinct from target-dir. 2026-02-14 12:15:30 +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
Jason Newcomb a9a368ad42 Do not lint main function in must_use_candidates (#16552)
Marking the `main` function as `#[must_use]` is nonsensical, as it is
not really supposed to be called anyway.

changelog: [`must_use_candidates`]: No longer lints `main` functions
with return values
2026-02-11 17:39:23 +00:00
Philipp Krones 5d3552749d Fix outdated doc comments (#16536)
Replace the links to more recent materials in the docs.

changelog: none
2026-02-11 14:44:37 +00:00
mikhailofff b20572ec56 change to github permalinks 2026-02-11 18:24:05 +04:00
Philipp Krones 5dac025910 Do not lint main function in must_use_candidates
Marking the `main` function as `#[must_use]` is nonsensical, as it is not really
supposed to be called anyway.
2026-02-11 13:39:24 +01:00
Guillaume Gomez cb68b21cb3 Extend disallowed_fields lint on variant fields 2026-02-09 18:51:44 +01:00
Keith-Cancel 9bf9a12381 Allow provisional mgca syntax of type const <IDENT> = <EXPR> to be reconized.
Revert, but without type const.

Update symbol for feature err, then update suggestion output, and lastly update tests that change because of those.

Update these new tests with the correct syntax, and few existing tests with the new outputs the merge with main added.

Fix for tidyfmt and some errors when manually resolving a merge conflicts.

Update these tests to use update error messages and type const syntax.

Update comments and error message to use new syntax instead of old type_const attribute.

Remove the type_const attribute

update some more tests to use the new syntax.

Update these test cases.

update feature gate test

Change gate logic for `mgca_type_const_syntax` to work also if `min_generic_const_args` is enabled.

Create a new feature gate that checks for the feature before expansion.

Make rustfmt handle the `type const` syntax correctly.

Add a convience method to check if a RhsKind is type const.

Rename `Const` discriminant to `Body` for `ConstItemRhsKind`

Give the `TraitItemKind` flag an enum instead of a simple bool to better describe what the flag is for.

Update formatting for these match statements.

Update clippy test to use type const syntax.

Update test to use type const syntax.

update rustfmt to match ast items.

Update clippy to match ast and hir items.

Few more test cases that used old attribute, instead of 'type const'

Update to match the output from the feature gate checks.

tidyfmt adjustments.

Update the is_type_const, so I can constrain record!(..) in encoder.rs

Update conditional compilation test.

Move the feature gate to after expansion to allow for cfg(...) to work.

Update some more tests to use the new syntax.

Update type const tests in associated-const-bindings to use new syntax.

Don't check based off the attribute, but the item here.

Update some tests outside of the const_generics folder that were using #[type_const]

update the tests in associated consts that use #[type_const] to use type const

Update these mgca tests with the type const syntax.

Add a flag to TraitItemKind for detecting type const for now. Maybe later change ItemConstRhs to have optional consts but that touches a lot more lines of code.

Don't need into for these now that it's a query.

Add is_type_const query to handle foreign def ids.

update this test to use type const syntax.

Fix logic here, we only want to lower if there is expression in this case.

Update built-in macros to use ConstItemRhsKind

Update more instance of the old ConstItemRhs.

Rename ConstItemKind to ConstItemRhsKind, I noticed there is a typed called ConstantItemKind, so add the Rhs to the name to avoid confusion.

Update lower to use ConstItemKind

Add an other helper method to check if the rhs kinda has an expr.

Update item parse to use ConstItemKind enum.

Felt the field name could a be little clear when editing a few other things.

Change the ConstItem struct see know if we have a type const or regular const.

Make sure this syntax is properly feature gated.
2026-02-09 07:59:24 -08:00
mikhailofff 7c95f57bc9 fix outdated doc comments 2026-02-08 11:25:51 +04:00
dswij 15e0ce9d69 Fix cmp_owned FP when to_string comes from macro input (#16468)
Closes rust-lang/rust-clippy#16458

changelog: [`cmp_owned`] fix FP when `to_string` comes from macro input
2026-02-07 14:39:27 +00:00
linshuy2 91de07da54 Extend iter_kv_map to cover flat_map and filter_map 2026-02-05 22:40:58 +00:00
Yuri Astrakhan 691e226369 fix: handle false negative for str_to_string
Replace `ToString::to_string` with `ToOwned::to_owned` when the function is passed as is:

```rust
fn issue16511(x: Option<&str>) -> String {
    // Replace with ToOwned::to_owned
    x.map(ToString::to_string)
}
```
2026-02-05 00:57:13 -05:00
lapla d0c6a64ff8 Fix redundant_iter_cloned false positive with move closures and coroutines 2026-02-03 20:27:54 +09:00
Jason Newcomb 1826ec0715 Extend question_mark to cover else if (#16455)
Closes rust-lang/rust-clippy#16429

changelog: [`question_mark`] enhance to cover `else if`
2026-02-03 01:07:28 +00: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
llogiq 301aae6ac8 fix: allow_attributes false negative on attributes with whitespace (#16497)
The [`allow_attributes`] lint false-negatived (failed to trigger) on
attributes that contained internal whitespace, such as `#[ allow (
dead_code ) ]`.

This happened because `clippy_utils::is_from_proc_macro` relied on
strict string matching (e.g., expecting exactly `#[allow`), which fails
if there are spaces.

#### Solution:
I have updated `clippy_utils::is_from_proc_macro` to support flexible
whitespace matching.
1. Added `Pat::Attr(Symbol)`.
2. Updated `span_matches_pat` to strip `#[` and trim validation
whitespace before checking the name.

Verified with a new test case in `tests/ui/allow_attributes.rs`.

Fixes rust-lang/rust-clippy#16491

----

changelog: [`allow_attributes`]: correctly detect attributes with
internal whitespace
2026-02-02 08:06:54 +00:00