Commit Graph

24932 Commits

Author SHA1 Message Date
Jason Newcomb 0776e01ff4 fix(needless_maybe_sized): don't lint in proc-macro-generated code (#15629)
Fixes https://github.com/rust-lang/rust-clippy/issues/13360

changelog: [`needless_maybe_sized`]: don't lint in proc-macro-generated
code
2026-02-23 01:09:15 +00:00
Jason Newcomb 38321c83e6 Add unnecessary_trailing_comma lint (#16530)
This matches `cargo fmt` behavior but for `format!(...)` -style macro
calls.

To make this PR easier to review, it moves all linting of the clippy
code to rust-lang/rust-clippy#16533

Suggest removing an unnecessary trailing comma before the closing
parenthesis in single-line format-like macro invocations (e.g. println!,
format!, write!). The lint currently only runs on format-like macros
because it relies on format-argument parsing; arbitrary user macros are
not supported to avoid incorrect suggestions.

- Lint is in the `style` group (allow-by-default)
- Single-line only: multi-line macro invocations are not linted
- Machine-applicable fix: removes the trailing comma

```rust
// catches this
debug!("Foo={}", 1,);

// suggests this
debug!("Foo={}", 1);
```

Closes rust-lang/rust-clippy#13965

changelog: [`unnecessary_trailing_comma`]: new lint to remove trailing
commas in a single-line format macro usage
2026-02-23 00:59:34 +00:00
Jason Newcomb f2713876d3 Remove no-rustfix marker for tests with valid suggestions (#16609)
changelog: none
2026-02-23 00:55:42 +00: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 f2a134b403 remove no-rustfix marker for tests 2026-02-22 22:13:14 +04:00
mikhailofff 34d0b12346 correct join_absolute_paths for a double backslash 2026-02-22 22:12:09 +04:00
llogiq ea45686b61 Add MSRV-based tests to duration_suboptimal_units lint (#16526)
Noticed because of rust-lang/rust-clippy#16525

changelog: none
2026-02-22 14:57:18 +00: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 9a1cabf77e Fix panic/assert message detection in edition 2015/2018 (#16473)
changelog: fix FP: [`assertions_on_result_states`],
[`missing_assert_message`] on edition 2015 and 2018

Fixes https://github.com/rust-lang/rust-clippy/issues/13490
2026-02-22 14:20:10 +00:00
llogiq 6211fa92e8 The path from a type to itself is Self (#16362)
changelog: [`redundant_closure_for_method_calls`]: fix ICE when
computing the path from a type to itself

Fixes rust-lang/rust-clippy#16360
2026-02-22 14:18:59 +00:00
llogiq a57ca61784 clippy_dev: Parsing revamp part 4/N (#15978)
Based on rust-lang/rust-clippy#15947

Simple change in this one. Lints are parsed into a map indexed by name
in order to detect overlapping lint names. The panic message when a
duplicate name is parsed is unhelpful right now. That will be fixed in a
future PR along with improving all the other parsing errors.

changelog: none
2026-02-22 14:17:50 +00:00
llogiq b36f285f62 allow deprecated(since = "CURRENT_RUSTC_VERSION") (#16557)
Motivated by https://github.com/rust-lang/rust/pull/149978 and
https://github.com/rust-lang/rust/pull/152488.

changelog: none
2026-02-22 14:13: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
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
llogiq b3188b8a9f Remove no-rustfix marker for tests with no lint suggestions (#16608)
Letting the marker in place may make a future suggestion be ignored
while it is invalid – the test would pass nevertheless.

changelog: none
2026-02-22 11:58:09 +00:00
Samuel Tardieu b12ef56efd Remove no-rustfix marker for tests with valid suggestions 2026-02-22 12:30:39 +01: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 94337ce1d8 DRY: make all span_lint_* use span_lint{_hir,}_and_then (#16587)
This removes code duplication. Also, this limits the number of places to
update when rustc lint code interface is modified to two places.

changelog: none
2026-02-21 22:21:38 +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 2f6e9e4d55 Add Sugg::strip_paren() 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
llogiq 2acc3e3e9a Add brackets around unsafe or labeled block used in else (#16603)
Fixes rust-lang/rust-clippy#16602

----

changelog: [`manual_let_else`]: use brackets around unsafe or labeled
block used in `else`
2026-02-21 17:57:01 +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
Samuel Tardieu d197fc85b3 result-map-unit-fn: use "a" before Result (#16593)
changelog: [`result-map-unit-fn`]: use "a" before `Result`
2026-02-20 09:14:41 +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 e63814d6d1 Rustup (#16588)
r? @ghost

changelog: none
2026-02-19 17:13:44 +00:00
Philipp Krones 650809e8a2 Bump nightly version -> 2026-02-19 2026-02-19 15:39:12 +01:00
Philipp Krones e96a83b4b7 Merge remote-tracking branch 'upstream/master' into rustup 2026-02-19 15:38:57 +01:00
Samuel Tardieu 3b2b250db5 DRY: make all span_lint_* use span_lint{_hir,}_and_then
This removes code duplication. Also, this limits the number of places to
update when rustc lint code interface is modified to two places.
2026-02-19 12:19:01 +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
llogiq 52a32d6125 Fix stale metadata output comment in compile-test (#16583)
This fixes a stale doc comment in `tests/compile-test.rs`.

`DiagnosticCollector` currently writes `util/gh-pages/index.html`, but
the
comment still referenced `util/gh-pages/lints.json`.

The drift came from b522e7a94 ("Generate lint list in HTML directly
instead
of JS"), which changed the output from JSON to HTML while leaving this
comment
unchanged.

changelog: none
2026-02-18 22:51:56 +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
Stuart Cook 899fa02b83 Rollup merge of #152758 - cjgillot:noinit-box, r=RalfJung
Remove ShallowInitBox.

All uses of this were removed by https://github.com/rust-lang/rust/pull/148190
Split from https://github.com/rust-lang/rust/pull/147862

r? @RalfJung
2026-02-18 17:29:44 +11:00
Yuri Astrakhan 1994230db1 fix(str_to_string): false positive non-str types 2026-02-17 14:44:13 -05:00
Yuri Astrakhan f72e055625 Add unnecessary_trailing_comma lint
Suggest removing an unnecessary trailing comma before the closing
parenthesis in single-line format-like macro invocations (e.g.
println!, format!, write!). The lint currently only runs on
format-like macros because it relies on format-argument parsing;
arbitrary user macros are not supported to avoid incorrect
suggestions.

- Lint is in the `style` group (allow-by-default)
- Single-line only: multi-line macro invocations are not linted
- Machine-applicable fix: removes the trailing comma
2026-02-17 14:30:43 -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