Commit Graph

25199 Commits

Author SHA1 Message Date
Philipp Krones 7a697630f4 Bump Clippy version -> 0.1.97 2026-04-16 19:13:51 +02:00
Philipp Krones a6fceda49e Bump nightly version -> 2026-04-16 2026-04-16 19:13:43 +02:00
Philipp Krones 205fab6b0f Merge remote-tracking branch 'upstream/master' into rustup 2026-04-16 19:13:25 +02:00
Samuel Tardieu 121f867042 Do not trigger let_and_return on let else (#16829)
changelog: [`let_and_return_on`]: do not trigger on `let else` construct

Fixes rust-lang/rust-clippy#16820
2026-04-16 15:37:47 +00:00
Philipp Krones a333abf7c5 Changelog for Clippy 1.95 (#16842)
Violets are red,
Roses are blue,
This month brings rain,
and sunshine peeks through.

----

Alexa from @bestman8

<img width="1080" height="1616" alt="image"
src="https://github.com/user-attachments/assets/eb86a6d2-427c-441c-ad03-1c0ace63128d"
/>

<br/>
<br/>
and
<br/>
<br/>
Ichigo from @oupson

<img width="1637" height="2214" alt="image"
src="https://github.com/user-attachments/assets/c8610a1b-6bce-453d-aefb-0c906ca6940c"
/>

are the winners at https://github.com/rust-lang/rust-clippy/pull/16653

P.S. Since there was no voting, picked the one with more hearts

----

Cats for the next release can be nominated in the comments🙏

changelog: none

r? flip1995
2026-04-16 13:39:33 +00:00
Jason Newcomb 5ba0e3a6b4 Parenthesize AssocOp::Cast in suggestion when replacement operator is < to avoid parse error (#16848)
Fix int_plus_one suggestion causing parse error when LHS is an
`AssocOp::Cast`

When int_plus_one rewrites an expression like `x as usize + 1 <= y`, it
  suggests `x as usize < y`. This doesn't compile because the parser
  interprets `usize<y>` as the start of generic arguments rather than a
  lt comparison.

The fix parenthesizes the LHS if it's an `AssocOp::Cast` and the
replacement
  operator is `<`: `(x as usize) < y`.

  ---
changelog: [int_plus_one]: Parenthesize `AssocOp::Cast` in suggestion
when replacement operator is < to avoid parse error
2026-04-16 01:17:26 +00:00
Samuel Tardieu c0adb72b3a Extend byte_char_slices to cover arrays (#16770)
Closes rust-lang/rust-clippy#16759

changelog: [`byte_char_slices`] enhance to cover arrays
2026-04-15 16:21:17 +00:00
linshuy2 d0c0f3a308 Enhance byte_char_slices to cover arrays 2026-04-15 18:16:03 +02:00
linshuy2 8d2de2185b Apply byte_char_slices to Clippy itself 2026-04-15 18:15:35 +02:00
zvkemp 69958674d5 conditionally wrap LHS of int_plus_one error to avoid parser ambiguity 2026-04-15 08:35:42 -04:00
dswij effe235710 Fix expect_fun_call suggests wrongly for string slicing (#16752)
Closes rust-lang/rust-clippy#16747

changelog: [`expect_fun_call`] fix wrong suggestions for string slicing
2026-04-14 16:59:51 +00:00
Samuel Tardieu ded01180f7 Add MSRV check for manual_noop_waker (#16850)
Fixes rust-lang/rust-clippy#16849

changelog: [`manual_noop_waker`]: Add MSRV check
2026-04-14 11:44:53 +00:00
bors f4b9b8d4f7 Auto merge of #155209 - JonathanBrouwer:attr_cleanup2, r=jdonszelmann
Post-attribute ports cleanup pt. 1 (again)

This is a re-implementation of most (but not all) of https://github.com/rust-lang/rust/pull/154808

The code is the same as in that PR, other than a few changes, I'll leave comments where I changed things.
I did re-implement most of the commits rather than cherry-picking, so it's probably good to check the entire diff regardless

r? @jdonszelmann
2026-04-14 08:59:40 +00:00
lapla 4c4c8c75a1 Add MSRV check for manual_noop_waker 2026-04-14 12:46:51 +09:00
bors 01dfd311b7 Auto merge of #136006 - oli-obk:push-tzonluoyuwkq, r=wesleywiser
Start using pattern types in libcore



cc rust-lang/rust#135996

Replaces the innards of `NonNull` with `*const T is !null`.

This does affect LLVM's optimizations, as now reading the field preserves the metadata that the field is not null, and transmuting to another type (e.g. just a raw pointer), will also preserve that information for optimizations. This can cause LLVM opts to do more work, but it's not guaranteed to produce better machine code.

Once we also remove all uses of rustc_layout_scalar_range_start from rustc itself, we can remove the support for that attribute entirely and handle all such needs via pattern types
2026-04-13 21:54:46 +00:00
Jonathan Brouwer 1e793cdad3 Remove AttributeDuplicates from BUILTIN_ATTRIBUTES 2026-04-13 20:51:24 +02:00
bors 2c5e3d3c5c Auto merge of #155253 - JonathanBrouwer:rollup-lERdTAB, r=JonathanBrouwer
Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#155162 (relnotes for 1.95)
 - rust-lang/rust#140763 (Change codegen of LLVM intrinsics to be name-based, and add llvm linkage support for `bf16(xN)` and `i1xN`)
 - rust-lang/rust#153604 (Fix thread::available_parallelism on WASI targets with threads)
 - rust-lang/rust#154193 (Implement EII for statics)
 - rust-lang/rust#154389 (Add more robust handling of nested query cycles)
 - rust-lang/rust#154435 (resolve: Some import resolution cleanups)
 - rust-lang/rust#155236 (Normalize individual predicate of `InstantiatedPredicates` inside `predicates_for_generics`)
 - rust-lang/rust#155243 (cg_ssa: transmute between scalable vectors)
 - rust-lang/rust#153941 (tests/debuginfo/basic-stepping.rs: Explain why all lines are not steppable)
 - rust-lang/rust#154587 (Add --verbose-run-make-subprocess-output flag to suppress verbose run-make output for passing tests)
 - rust-lang/rust#154624 (Make `DerefPure` dyn-incompatible)
 - rust-lang/rust#154929 (Add `const Default` impls for `LazyCell` and `LazyLock`)
 - rust-lang/rust#154944 (Small refactor of `arena_cache` query values)
 - rust-lang/rust#155055 (UI automation)
 - rust-lang/rust#155062 (Move tests from `tests/ui/issues/` to appropriate directories)
 - rust-lang/rust#155131 (Stabilize feature `uint_bit_width`)
 - rust-lang/rust#155147 (Stabilize feature `int_lowest_highest_one`)
 - rust-lang/rust#155174 (Improve emission of `UnknownDiagnosticAttribute` lint)
 - rust-lang/rust#155194 (Fix manpage version replacement and use verbose version)
2026-04-13 18:32:47 +00:00
Jonathan Brouwer b23bc0bbd0 Rollup merge of #154193 - JonathanBrouwer:external-static, r=jdonszelmann
Implement EII for statics

This PR implements EII for statics. I've tried to mirror the implementation for functions in a few places, this causes some duplicate code but I'm also not really sure whether there's a clean way to merge the implementations.

This does not implement defaults for static EIIs yet, I will do that in a followup PR
2026-04-13 20:19:56 +02:00
Samuel Tardieu 7f0774a151 Fix wrong suggestion for println_empty_string with non-parenthesis delimiters (#16846)
Fixes rust-lang/rust-clippy#16843

changelog: [`println_empty_string`]: fix wrong suggestion with
non-parenthesis delimiters
2026-04-13 15:59:32 +00:00
Oli Scherer fe2553fe58 Use !null pattern type in libcore 2026-04-13 17:23:03 +02:00
Jonathan Brouwer 0e4b612119 Rollup merge of #155003 - malezjaa:update-thinvec, r=davidtwco
update thin-vec

With thin-vec v0.2.15 released, copy-pasted implementation of ExtractIf can be removed.
2026-04-13 14:02:35 +02:00
lapla 7f096cff9d Fix wrong suggestion for println_empty_string with non-parenthesis delimiters 2026-04-12 20:47:54 +09:00
dswij ea2b4d224f Fix unused_async FP for stubs with args (#16832)
Closes rust-lang/rust-clippy#16825

changelog: [`unused_async`] fix FP for stubs with args
2026-04-12 10:26:20 +00:00
Aliaksei Semianiuk 787dd491fa Changelog for Clippy 1.95 2026-04-11 17:27:11 +05:00
Samuel Tardieu 33a3b2223f Do not trigger let_and_return on let else 2026-04-11 13:53:28 +02:00
Ada Alakbarova 08fa871dcc Even more fixes for handling of macros (#16443)
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/16443)*

Continuation rust-lang/rust-clippy#16337

Even more fixes for handling macros

changelog: [`manual_rotate`] fix wrongly unmangled macros
changelog: [`map_with_unused_argument_over_ranges`] fix wrongly
unmangled macros
changelog: [`needless_bool`] fix wrongly unmangled macros
changelog: [`manual_is_power_of_two`] fix wrongly unmangled macros
changelog: [`manual_div_ceil`] fix wrongly unmangled macros
changelog: [`implicit_saturating_sub`] fix wrongly unmangled macros
changelog: [`range_minus_one`] fix wrongly unmangled macros
changelog: [`range_plus_one`] fix wrongly unmangled macros
changelog: [`manual_swap`] fix wrongly unmangled macros
changelog: [`let_and_return`] fix wrongly unmangled macros
2026-04-11 10:53:58 +00:00
Ada Alakbarova d588ba3068 Extend manual_filter to cover and_then (#16456)
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/16456)*

Closes rust-lang/rust-clippy#14440

Implemented as enhancement to `manual_filter`

changelog: [`manual_filter`] enhance to cover `and_then`
2026-04-11 09:34:11 +00:00
Jonathan Brouwer f1482364b6 Add eii_impls argument to StaticItem 2026-04-11 10:17:07 +02:00
Jacob Pratt fb16ce7254 Rollup merge of #154661 - CoCo-Japan-pan:impl-restriction-check, r=jhpratt,Urgau
Semantic checks of `impl` restrictions

This PR implements semantic checks for `impl` restrictions proposed in the [Restrictions RFC](https://rust-lang.github.io/rfcs/3323-restrictions.html) (Tracking Issue rust-lang/rust#105077), and linked to a [GSOC idea/proposal](https://github.com/rust-lang/google-summer-of-code/tree/142433eb3b104b2f32bae0b9dfafb78a0a2ac579?tab=readme-ov-file#implementing-impl-and-mut-restrictions).

It lowers the resolved paths of `impl` restrictions from the AST to HIR and into `TraitDef`, and integrates the checks into the coherence phase by extending `check_impl`. As parsing (rust-lang/rust#152943) and path resolution (rust-lang/rust#153556) have already been implemented, this PR provides a working implementation of `impl` restrictions.

r? @Urgau
cc @jhpratt
2026-04-11 01:49:12 -04:00
bors c482441c1c Auto merge of #155115 - JonathanBrouwer:rollup-RePrRPQ, r=JonathanBrouwer
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#152901 (Introduce a `#[diagnostic::on_unknown]` attribute)
 - rust-lang/rust#155078 (Reject dangling attributes in where clauses)
 - rust-lang/rust#154449 (Invert dependency between `rustc_errors` and `rustc_abi`.)
 - rust-lang/rust#154646 (Add suggestion to `.to_owned()` used on `Cow` when borrowing)
 - rust-lang/rust#154993 (compiletest: pass -Zunstable-options for unpretty and no-codegen paths)
 - rust-lang/rust#155097 (Make `rustc_attr_parsing::SharedContext::emit_lint` take a `MultiSpan` instead of a `Span`)
2026-04-10 18:19:03 +00:00
Jonathan Brouwer 32213c6635 Rollup merge of #154646 - m4rch3n1ng:144792-cow-diag, r=davidtwco
Add suggestion to `.to_owned()` used on `Cow` when borrowing

fixes rust-lang/rust#144792
supersedes rust-lang/rust#144925 with the review comments addressed

the tests suggested from @Kivooeo from https://github.com/rust-lang/rust/pull/144925#discussion_r2252703007 didn't work entirely, because these tests failed due to error `[E0308]` mismatched types, which actually already provides a suggestion, that actually makes the code compile:

```
$ cargo check
error[E0308]: mismatched types
 --> src/main.rs:3:5
  |
1 | fn test_cow_suggestion() -> String {
  |                             ------ expected `std::string::String` because of return type
2 |     let os_string = std::ffi::OsString::from("test");
3 |     os_string.to_string_lossy().to_owned()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `Cow<'_, str>`
  |
  = note: expected struct `std::string::String`
               found enum `std::borrow::Cow<'_, str>`
help: try using a conversion method
  |
3 |     os_string.to_string_lossy().to_owned().to_string()
  |                                           ++++++++++++
```

now this suggestion is of course not good or efficient code, but via clippy with `-Wclippy::nursery` lint group you can actually get to the correct code, so i don't think this is too much of an issue:

<details>
<summary>the clippy suggestions</summary>

```
$ cargo clippy -- -Wclippy::nursery
warning: this `to_owned` call clones the `Cow<'_, str>` itself and does not cause its contents to become owned
 --> src/main.rs:3:5
  |
3 |     os_string.to_string_lossy().to_owned().to_string()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/beta/index.html#suspicious_to_owned
  = note: `#[warn(clippy::suspicious_to_owned)]` on by default
help: depending on intent, either make the `Cow` an `Owned` variant
  |
3 |     os_string.to_string_lossy().into_owned().to_string()
  |                                 ++
help: or clone the `Cow` itself
  |
3 -     os_string.to_string_lossy().to_owned().to_string()
3 +     os_string.to_string_lossy().clone().to_string()
  |
$ # apply first suggestion
$ cargo c -- -Wclippy::nursery
warning: redundant clone
 --> src/main.rs:3:45
  |
3 |     os_string.to_string_lossy().into_owned().to_string()
  |                                             ^^^^^^^^^^^^ help: remove this
  |
note: this value is dropped without further use
 --> src/main.rs:3:5
  |
3 |     os_string.to_string_lossy().into_owned().to_string()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/beta/index.html#redundant_clone
  = note: `-W clippy::redundant-clone` implied by `-W clippy::nursery`
  = help: to override `-W clippy::nursery` add `#[allow(clippy::redundant_clone)]`
```

</details>

the actual error that we are looking for is error `[E0515]`, cannot return value referencing local variable, which was only present in the original issue due to automatic type inference assuming you want to return a cloned `Cow<'_, str>`, which is of course not possible. this is why i took the original test functions and turned them into closures, where it's less obvious that it's trying to return the wrong type.

r? davidtwco

(because you reviewed the last attempt)
(also, let me know if i should squash this down to one commit and add myself as the co-contributor)
2026-04-10 18:38:14 +02:00
Jana Dönszelmann b305aeef7a fixup rustdoc,clippy,rustfmt 2026-04-10 15:10:04 +02:00
Jonathan Brouwer 1ddb9f2d13 Revert #152369 because of multiple regressions
The regressions are documented in the PR comments.
This reverts commit 2972b5e, reversing changes made to f908263.
2026-04-09 18:53:59 +02:00
linshuy2 878feaa4dd fix: unused_async FP for stubs with args 2026-04-09 15:36:06 +00:00
Jason Newcomb 46a80c238f fn_to_numeric_cast_any: Do not warn cast to raw pointer (#14109)
Fixes #12638

changelog: [`fn_to_numeric_cast_any`]: Fix false positive on a cast to
raw pointer
2026-04-09 15:20:47 +00:00
Jacob Pratt 624a067ea8 Rollup merge of #155007 - josetorrs:rename-is-impl-trait, r=WaffleLapkin,Kivooeo
renaming method is_impl_trait to is_opaque

Completing one of the tasks mentioned in this issue: https://github.com/rust-lang/rust/issues/154941

r? @WaffleLapkin
2026-04-08 23:04:00 -04:00
Jose 84f3530926 fixing clippy reference 2026-04-08 16:58:59 -04:00
bors 810f8e4a40 Auto merge of #153838 - oli-obk:use-tree-span, r=davidtwco
Use fine grained component-wise span tracking in use trees

This often produces nicer spans and even doesn't need a Span field anymore (not that I expect the unused field to affect any perf, but still neat).
2026-04-08 20:09:27 +00:00
malezjaa cf6aa22df5 update thin-vec 2026-04-08 21:09:07 +02:00
Oli Scherer 78438c0135 Use fine grained component-wise span tracking in use trees 2026-04-08 12:37:25 +02:00
linshuy2 3351369d43 Enhance manual_filter to cover and_then 2026-04-07 22:58:06 +00:00
Jason Newcomb f5f3c2f30a Truncate constants to target type in comparison (#16782)
changelog: [`bad_bit_mask`]: truncate constant to target type before
warning about impossible equality

Fixes rust-lang/rust-clippy#16781
2026-04-07 19:34:09 +00:00
Waffle Lapkin 6a4eefde2d ty::Alias refactor: fix clippy 2026-04-07 10:08:12 +02:00
Samuel Tardieu c4e5a77b76 unneeded_wildcard_pattern.rs: fix typo (rathter -> rather) (#16818)
changelog: none
2026-04-07 07:33:22 +00:00
Daniel Scherzer c40e988d19 unneeded_wildcard_pattern.rs: fix typo (rathter -> rather) 2026-04-06 16:45:50 -07:00
Ada Alakbarova 49a2f386f9 Unneeded wildcard improvement (#16733)
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/16733)*

changelog: [`unneeded_wildcard_pattern`]: add support for struct
constructs.

Closes [#16638](https://github.com/rust-lang/rust-clippy/issues/16638)

The existing lint only looks at tuples and tuplestructs. This change
adds support for standard structs, looking for cases
where one or more `_` immediately preceed a `..`. The preceeding `_`
members may be omitted, as they will be collected by the `..` operator.
2026-04-06 15:04:13 +00:00
jim df2f81b8e7 add struct support to unneeded_wildcard_pattern lint
Apply suggestions from code review

Co-authored-by: Ada Alakbarova <58857108+ada4a@users.noreply.github.com>
2026-04-05 14:26:56 -04:00
Samuel Tardieu 389a32a4c3 perf: disable nonminimal_bool by default (#16761)
After performance concers on the `nonminimal_bool` lint, we [performed a
crater run](https://github.com/rust-lang/rust/issues/153883)

This crater run revealed that in 19120 suggestions taken from 1.3
million crates, only about 36% had resulted in multi-terminal
suggestions (suggestions that were not only a single boolean).

This suggests that most cases of this lint firing, the expression that
triggered was pretty simple. And thus, we should not take such a huge
toll for a lint that isn't that useful.

In the future, a rewrite of that `bool_expr` function could be very
useful to alleviate the performance toll. Because clearly running the
Quine McCluskey algorithm on all those boolean operations is not ideal.

---

## Performance report:

`cargo clippy` -> 5,077,447,157 icount
`cargo check` -> 3,629,576,891 icount

So the Clippy that `rustup` delivers is about 1.4b instructions more
than `cargo check`.

`NonminimalBool` lint pass -> 318,169,034

$$\frac{nonminimal\\_bool}{clippy-check}*100 = 21.97496844$$

So, the `NonminimalBool` lint pass is about 22% of all Clippy-exclusive
instruction count.

---

After this change, we can now compare the Clippy BUILT FROM MASTER, NOT
DELIVERED BY RUSTUP, with the Clippy from this PR.

`master/target/release/cargo-clippy` -> 5,296,838,955 (Slower than
Rustup)
`pr/target/release/cargo-clippy` -> 4,977,035,941.

So, $master - PR = 319803014$, which is the exact icount of
`Nonminimal_bool` and about 22% of Clippy's whole execution time.

Profiled on `syn-2.0.71`, with Callgrind.

changelog:[`nonminimal_bool`]: Move to `pedantic`.
changelog:[`overly_complex_bool_expr`]: Move to `pedantic`.
2026-04-05 11:54:26 +00:00
llogiq ab9cb427b8 Rework expr_use_ctxt into an iterator over successive use sites. (#16784)
This is going to be used as part of more thoroughly checking whether we
can change the type of an expression. e.g. `range_plus_one` suggests
changing `Range` to `RangeInclusive`.

changelog: none
2026-04-05 06:02:51 +00:00
llogiq 1e0b66ef7e fix: unnecessary type cast causing a compile error (#16796)
In some cases, removing a cast that looks unnecessary can
still change type inference, even when the cast is to the
expected same type.

The lint now handles casts that flow through
intermediate expressions (e.g. calls, blocks, let
bindings, loops...). It also treats placeholder
generics (e.g. `::<_>`) as inference sensitive.

Added regression tests with similar behavior
as the original bug, some edge cases and
tests to check if false negative cases
weren't created.

Closes rust-lang/rust-clippy#16449

changelog: [`unnecessary_cast`]: fixed a suggestion to remove a cast
that can cause a compilation error if followed.
2026-04-04 20:12:58 +00:00