Commit Graph

25113 Commits

Author SHA1 Message Date
Philipp Krones 994d5b4ac8 Bump nightly version -> 2026-04-02 2026-04-02 13:49:57 +02:00
Philipp Krones 1d55118849 Merge remote-tracking branch 'upstream/master' into rustup 2026-04-02 13:31:08 +02:00
Jonathan Brouwer 4efda7afee Rollup merge of #154074 - dianne:dbg-temp-scopes, r=Mark-Simulacrum
don't drop arguments' temporaries in `dbg!`

Fixes rust-lang/rust#153850

Credit to @theemathas for help with macro engineering ^^

r? libs
2026-03-29 21:39:26 +02:00
dianne e689235a7e update diagnostic for variables moved by dbg! 2026-03-29 09:48:41 -07:00
dianne 7d9ab57a4f don't drop arguments' temporaries in dbg! 2026-03-29 06:38:38 -07:00
llogiq c07baa4cc9 Add manual_option_zip lint (a.and_then(|x| b.map(|y| (x, y)))) (#16600)
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/16600)*

changelog: [`manual_option_zip`]: new lint that detects `a.and_then(|a|
b.map(|b| (a, b)))` and suggests using `a.zip(b)` instead

This PR introduces a new lint `manual_option_zip` that identifies cases
where `Option::and_then` is followed by `Option::map` in the provided
closure to construct a tuple that could be more concisely shaped using
`Option::zip`.

The lint detects the pattern:
```rust
a.and_then(|x| b.map(|y| (x, y)))
```

And suggests replacing it with:
```rust
a.zip(b)
```

Closes rust-lang/rust-clippy#16599
2026-03-28 21:58:47 +00:00
Samuel Tardieu e4683d27a9 impl manual_noop_waker lint (#16687)
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/16687)*

Fixes rust-lang/rust-clippy#16639

### Description

This PR introduces a new lint manual\_noop\_waker that detects manual,
empty implementations of the std::task::Wake trait. These can be
replaced with std::task::Waker::noop(), which is more performant (avoids
Arc allocation) and cleaner.

### Example

```rust
struct MyWaker;
impl Wake for MyWaker {
    fn wake(self: Arc<Self>) {}
    fn wake_by_ref(self: &Arc<Self>) {}
}
````
Can be replaced with:

```rust
let waker = Waker::noop();

````

* \[x\] I've followed the [contribution
guidelines](https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md)

*   \[x\] I've added UI tests for the new lint

*   \[x\] I've run `cargo dev update_lints`

changelog: `[manual_noop_waker]`: Added a lint to detect manual no-op
Wake implementations.
2026-03-28 17:49:00 +00:00
Jaroslaw Roszyk 26740ea4ab impl manual_noop_waker lint 2026-03-28 15:17:02 +01:00
Jason Newcomb fee9100776 Issue #16110: similar_names not triggered by example (#16300)
*Please write a short comment explaining your change (or "none" for
internal only changes)*
Fixes rust-lang/rust-clippy#16110
changelog: [`similar_names`] : Changed the lint docs to reflect its
actual behavior
2026-03-28 00:33:40 +00:00
alt440 453a482373 Ran cargo dev fmt 2026-03-27 20:13:15 -04:00
alt440 ee7896e041 similar_names not triggered by example 2026-03-27 20:13:13 -04:00
alt440 837e8917a6 Revert "similar_names not triggered by example"
This reverts commit e82f527e21415da49f30473d4562adb967f867e4.
2026-03-27 20:10:48 -04:00
alt440 111b8dc87e Revert "Correct dogfood tests"
This reverts commit 74578256f1f009de382589b87fa356906c18a61b.
2026-03-27 20:10:46 -04:00
alt440 c5b3fcf243 Revert "Executed cargo fmt"
This reverts commit 9b9de0f218d504a5682649ea3745ea8887698656.
2026-03-27 20:09:44 -04:00
alt440 df8f576cdf Executed cargo fmt 2026-03-27 20:09:44 -04:00
alt440 44435734ff Correct dogfood tests 2026-03-27 20:09:42 -04:00
alt440 ea5bc07c19 similar_names not triggered by example 2026-03-27 20:07:42 -04:00
Jason Newcomb 75813d35fd Preserve parentheses in suggestion in presence of cascaded casts (#16483)
changelog: [`unnecessary_cast`]: preserve parentheses in presence of
cascaded casts

Fixes rust-lang/rust-clippy#16475
2026-03-27 23:19:50 +00:00
Jason Newcomb e43491b0df chore(deps): update rust crate tar to v0.4.45 (#16771)
Fix
[RUSTSEC-2026-0068](https://rustsec.org/advisories/RUSTSEC-2026-0068.html):
tar-rs incorrectly ignores PAX size headers if header size is nonzero
Fix
[RUSTSEC-2026-0067](https://rustsec.org/advisories/RUSTSEC-2026-0067.html):
`unpack_in` can chmod arbitrary directories by following symlinks

cc: @clubby789

changelog: none
2026-03-27 17:57:00 +00:00
xtqqczze a7a0fc3cc7 chore(deps): update rust crate tar to v0.4.45 2026-03-27 13:32:41 +00:00
Daria Sukhonina 6e68667da9 Use tcx.local_parent() more often 2026-03-27 15:36:29 +03:00
Daria Sukhonina b0c02926e5 Add typeck_root_def_id_local 2026-03-27 15:36:28 +03:00
Jason Newcomb 0a29aac07d fix(explicit_counter_loop): suggest .take(n) for for _ in 0..n co… (#16658)
When a loop variable is unused (`for _ in 0..n`) and the counter is
being
incremented, Clippy previously suggested the generic zip-based rewrite.
This PR adds a more idiomatic `.take(n)` suggestion for the common case
where the range is half-open and starts at zero:
```rust
// before
for _ in 0..MAX {
    base += 1;
}

// suggested
for base in (100..).take(MAX)
```

Non-zero starts (`5..MAX`) and inclusive ranges (`0..=MAX`) are
explicitly excluded and fall through to the existing zip suggestion.
Both cases are covered by new UI tests.

changelog: [`explicit_counter_loop`]: suggest `(init..).take(n)` when
loop variable is unused and range is `0..n`

fixes rust-lang/rust-clippy#16642
2026-03-27 11:14:04 +00:00
zayutaha daad0fb356 fix(explicit_counter_loop): suggest .take(n) for for _ in 0..n counter loops
fix(explicit_counter_loop): suggest `.take(n)` for `for _ in 0..n` counter loops
2026-03-26 18:41:03 +05:30
Jonathan Brouwer ddfb974bf9 Rollup merge of #153702 - SpriteOvO:guard-matcher, r=davidtwco
Add macro matcher for `guard` fragment specifier

Tracking issue #153104

This PR implements a new `guard` macro matcher to match `if-let` guards (specifically [`MatchArmGuard`](https://github.com/rust-lang/reference/blob/50a1075e879be75aeec436252c84eef0fad489f4/src/expressions/match-expr.md#match-guards)). In the upcoming PR, we can use this new matcher in the `matches!` and `assert_matches!` macros to support their use with `if-let` guards. (see #152313)

The original `Expr` used to represent a guard has been wrapped in a new `Guard` type, allowing us to carry the span information of the leading `if` keyword. However, it might be even better to include the `if` keyword in the `Guard` type as well? I've left a FIXME comment in the code.
2026-03-25 19:52:50 +01:00
dswij f7649efff7 iter_kv_map: handle identity map for map and flat_map (#16743)
fixes: rust-lang/rust-clippy#16742

properly select post operation for identity map according to map method
kind

changelog: [`iter_kv_map`]: handle identity map for `map` and `flat_map`
2026-03-24 22:06:09 +00:00
Ada Alakbarova 42139286fa manual_pop_if: lint more cases, even if we do not provide a suggestion (#16683)
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/16683)*

Extend the lint to detect the case where the popped value is used, but
in such cases just emit the lint with no suggestion.

changelog: [`manual_pop_if`]: in case the popped value is used, just
emit the lint with no suggestion.
changelog: [`manual_pop_if`]: also cover `.pop().unwrap_unchecked()`
2026-03-24 20:39:04 +00:00
dswij f923257054 Fix collapsible_if FP when the inner if contains cfg (#16757)
Closes rust-lang/rust-clippy#16715

changelog: [`collapsible_if`] fix FP when the inner if contains cfg
2026-03-24 14:58:56 +00:00
Jason Newcomb 96c1c7a9db perf: reduce matching_root_macro_call usage (23b -> 22.24b) (#16756)
`matching_root_macro_call` was taking up lots of instructions. This PR
reduces its usage and thus, the number of instructions.

Profiled in `wasmi`. 23,010,846,019 icount -> 22,245,910,522 icount
**-3.324%** performance improvement!

3 Lints were affected:
    - `repeat_vec_with_capacity`: 783,874,512 -> 24,488,225
    - `string_patterns`: Not measured in benchmark.
- `filter_map`: Weirdly went from 22,000,078 to 22,017,509. But this
doesn't make sense so it's completely anecdotal. (In no world would
changing a function call with a boolean check make *anything* more
expensive.

changelog:[`repeat_vec_with_capacity`]: Optimize by 96.876%
2026-03-24 08:36:32 +00:00
Jason Newcomb 807dea0552 Fix collapsible_match FP when the pat binding is moved or mutated (#16708)
Closes rust-lang/rust-clippy#16705

changelog: [`collapsible_match`] fix FP when the pat binding is moved or
mutated
2026-03-24 06:13:34 +00:00
linshuy2 fef8a7130e fix: collapsible_if FP when the inner if contains cfg 2026-03-24 04:48:31 +00:00
Alejandra Gonzalez 6eda8b053b perf: reduce matching_root_macro_call usage
`matching_root_macro_call` was taking up lots of instructions.
This PR reduces its usage and thus, the number of instructions.

Profiled in `wasmi`. 23,010,846,019 icount -> 22,245,910,522 icount
**-3.324%** performance improvement!

3 Lints were affected:
    - `repeat_vec_with_capacity`: 783,874,512 -> 24,488,225
    - `string_patterns`: Not measured in benchmark.
    - `filter_map`: Weirdly went from 22,000,078 to 22,017,509. But this
doesn't make sense so it's completely anecdotal. (In no world would changing
a function call with a boolean check make *anything* more expensive.

changelog:[`repeat_vec_with_capacity`]: Optimize by 96.876%
2026-03-24 00:15:36 +01:00
Samuel Tardieu b8ce22d75c perf: manual_is_ascii_check, remove 822 million instructions (#16755)
Turns out that `manual_is_ascii_check` was taking up 820 million
instructions of `wasmi`'s 23 billion. Now... it doesn't. It now takes 23
million, still too much, but not as noticeable.

Profiled in `wasmi`. 23,821,891,527 icount -> 23,010,885,185 icount,
3.3% performance improvement.

changelog:[`manual_is_ascii_check`]: Optimize by 97.125%
2026-03-23 22:08:57 +00:00
Alejandra Gonzalez 6101edd915 perf: manual_is_ascii_check, remove 797 million instructions
Turns out that `manual_is_ascii_check` was taking up 820 million instructions
of `wasmi`'s 23 billion. Now... it doesn't. It now takes 23 million, still too much, but not
as noticeable.

Profiled in `wasmi`. 23,821,891,527 icount -> 23,035,885,185 icount

changelog:[`manual_is_ascii_check`]: Optimize by 97.125%
2026-03-23 21:35:25 +01:00
bors f77c9803b5 Auto merge of #154253 - JonathanBrouwer:rollup-LLZUsz2, r=JonathanBrouwer
Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#154241 (`rust-analyzer` subtree update)
 - rust-lang/rust#153686 (`std`: include `dlmalloc` for all non-wasi Wasm targets)
 - rust-lang/rust#154105 (bootstrap: Pass `--features=rustc` to rustc_transmute)
 - rust-lang/rust#153069 ([BPF] add target feature allows-misaligned-mem-access)
 - rust-lang/rust#154085 (Parenthesize or-patterns in prefix pattern positions in pretty printer)
 - rust-lang/rust#154191 (refactor RangeFromIter overflow-checks impl)
 - rust-lang/rust#154207 (Refactor query loading)
 - rust-lang/rust#153540 (drop derive helpers during attribute parsing)
 - rust-lang/rust#154140 (Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.)
 - rust-lang/rust#154161 (On E0277 tweak help when single type impls traits)
 - rust-lang/rust#154218 (interpret/validity: remove unreachable error kind)
 - rust-lang/rust#154225 (diagnostics: avoid ICE in confusable_method_name for associated functions)
 - rust-lang/rust#154228 (Improve inline assembly error messages)
2026-03-23 15:46:13 +00:00
Paolo Borelli 79db6154d3 manual_pop_if: lint more cases, even if we do not provide a suggestion
Extend the lint to detect the case where the popped value is used, but
in such cases just emit the lint with no suggestion.
Also detect the pop().unwrap_unchecked() case.

changelog: none
2026-03-23 16:13:36 +01:00
Jonathan Brouwer 55a87b989a Rollup merge of #153582 - mehdiakiki:simplify-find-attr-hir-id, r=JonathanBrouwer
Simplify find_attr! for HirId usage

Add a `HasAttrs<'tcx, Tcx>` trait to `rustc_hir` that allows `find_attr!` to accept `DefId`, `LocalDefId`, `OwnerId`, and `HirId` directly, instead of requiring callers to manually fetch the attribute slice first.

Before:
  `find_attr!(tcx.hir_attrs(hir_id), SomeAttr)`

After:
  `find_attr!(tcx, hir_id, SomeAttr)`

The trait is defined in `rustc_hir` with a generic `Tcx` parameter to avoid a dependency cycle (`rustc_hir` cannot depend on `rustc_middle`). The four concrete impls for `TyCtxt` are in `rustc_middle`.

Fixes https://github.com/rust-lang/rust/issues/153103
2026-03-23 12:14:56 +01:00
Jonathan Brouwer 4521a3fb44 Rollup merge of #154085 - aytey:fix-at-or-pattern-parens, r=chenyukang
Parenthesize or-patterns in prefix pattern positions in pretty printer

The AST pretty printer was dropping parentheses around or-patterns when they appeared inside `@` bindings, `&` references, or `box` patterns. For example:

- `v @ (1 | 2 | 3)` was printed as `v @ 1 | 2 | 3`
- `&(1 | 2 | 3)` was printed as `&1 | 2 | 3`
- `box (1 | 2 | 3)` was printed as `box 1 | 2 | 3`

Since `|` has the lowest precedence among pattern operators, all of these are parsed incorrectly without parentheses — e.g. `v @ 1 | 2 | 3` becomes `(v @ 1) | 2 | 3`, binding `v` only to the first alternative.

This caused E0408 ("variable not bound in all patterns") when the expanded output was fed back to the compiler, affecting crates like html5ever and wgpu-core that use macros expanding to or-patterns after `@`.

The fix adds a `print_pat_paren_if_or` helper that wraps `PatKind::Or` subpatterns in parentheses, and uses it in the `@`, `&`, and `box` printing arms. This is similar in spirit to the existing `FixupContext` parenthesization approach used for expression printing.

## Example

**before** (`rustc 1.96.0-nightly (3b1b0ef4d 2026-03-11)`):

```rust
#![feature(prelude_import)]
#![no_std]
#![feature(box_patterns)]
extern crate std;
#[prelude_import]
use ::std::prelude::rust_2015::*;

//@ pretty-compare-only
//@ pretty-mode:expanded
//@ pp-exact:or-pattern-paren.pp

macro_rules! or_pat { ($($name:pat),+) => { $($name)|+ } }

fn check_at(x: Option<i32>) {
    match x {
        Some(v @ 1 | 2 | 3) =>

            {
            ::std::io::_print(format_args!("{0}\n", v));
        }
        _ => {}
    }
}
fn check_ref(x: &i32) { match x { &1 | 2 | 3 => {} _ => {} } }
fn check_box(x: Box<i32>) { match x { box 1 | 2 | 3 => {} _ => {} } }
fn main() { check_at(Some(2)); check_ref(&1); check_box(Box::new(1)); }
```

**after** (this branch):

```rust
#![feature(prelude_import)]
#![no_std]
#![feature(box_patterns)]
extern crate std;
#[prelude_import]
use ::std::prelude::rust_2015::*;

//@ pretty-compare-only
//@ pretty-mode:expanded
//@ pp-exact:or-pattern-paren.pp

macro_rules! or_pat { ($($name:pat),+) => { $($name)|+ } }

fn check_at(x: Option<i32>) {
    match x {
        Some(v @ (1 | 2 | 3)) =>

            {
            ::std::io::_print(format_args!("{0}\n", v));
        }
        _ => {}
    }
}
fn check_ref(x: &i32) { match x { &(1 | 2 | 3) => {} _ => {} } }
fn check_box(x: Box<i32>) { match x { box (1 | 2 | 3) => {} _ => {} } }
fn main() { check_at(Some(2)); check_ref(&1); check_box(Box::new(1)); }
```

Notice `v @ 1 | 2 | 3` becomes `v @ (1 | 2 | 3)`, `&1 | 2 | 3` becomes `&(1 | 2 | 3)`, and `box 1 | 2 | 3` becomes `box (1 | 2 | 3)`. Without parens, the or-pattern binds incorrectly — only the first alternative gets the `@`/`&`/`box`, causing E0408.
2026-03-23 12:00:59 +01:00
Samuel Tardieu dfb718b2e2 Preserve parentheses in suggestion in presence of cascaded casts 2026-03-22 17:27:08 +01:00
Samuel Tardieu 7e148fc8d0 Factor out lint emission 2026-03-22 17:27:07 +01:00
Samuel Tardieu ac86fd103d Add BinaryHeap::pop_if() to manual_pop_if (#16734)
Detects manual implementations of the newly implemented
[`BinaryHeap::pop_if()`](https://github.com/rust-lang/rust/issues/151828)
in `manual_pop_if`.

I wasn't sure about how best to handle checking for the nightly feature.
Could we let people compiling with nightly know that the feature is
available even if they don't have it enabled?

changelog: [`manual_pop_if`]: detect manual implementations of
`BinaryHeap::pop_if()`
2026-03-22 15:49:42 +00:00
Max Heller 9bf6fafdbf Add BinaryHeap::pop_if() to manual_pop_if 2026-03-22 11:22:16 -04:00
Zihan fe4fa8b186 iter_kv_map: handle identity map for map and flat_map
properly select post operation for identity map according to map method kind

changelog: [`iter_kv_map`]: handle identity map for `map` and `flat_map`

Signed-off-by: Zihan <zihanli0822@gmail.com>
2026-03-22 16:26:32 +08:00
Philipp Krones 86390a3c03 Merge commit '256c21c543ca422b3ab8810a0d081d722408e896' into clippy-subtree-update 2026-03-21 14:13:09 +01:00
Philipp Krones 256c21c543 Rustup (#16740)
r? @ghost

changelog: none
2026-03-21 12:45:54 +00:00
Philipp Krones e191c9429e Bump nightly version -> 2026-03-21 2026-03-21 13:40:35 +01:00
Philipp Krones 1e283ba0ce Merge remote-tracking branch 'upstream/master' into rustup 2026-03-21 13:40:20 +01:00
Philipp Krones b98de10e9c Update bytes dependency in clippy_test_deps to avoid CVE warning (#16667)
Pull-requests get a warning because of

[RUSTSEC-2026-0007](https://rustsec.org/advisories/RUSTSEC-2026-0007.html).
Bumping `bytes` will silence the warning.

changelog: none

r? flip1995
2026-03-20 17:32:03 +00:00
Andrew V. Teylu f049a64100 Update Clippy test expectations for or-pattern parenthesization
The pretty printer now correctly parenthesizes or-patterns inside
`box` patterns, which changes the Clippy `unnested_or_patterns` lint
suggestion from `box box (0 | 2 | 4)` to `box (box (0 | 2 | 4))`.
The new output is more correct — the old suggestion was itself missing
parens and would have been parsed as `box (box 0) | 2 | 4`.

Signed-off-by: Andrew V. Teylu <andrew.teylu@vector.com>
2026-03-19 13:38:26 +00:00
Stuart Cook 525c8ac943 Rollup merge of #153778 - bjorn3:driver_cleanups, r=TaKO8Ki
Couple of driver interface improvements

* Pass Session to `make_codegen_backend` callback. This simplifies some code in miri.
* Move env/file_depinfo from ParseSess to Session. There is no reason it has to be in ParseSess rather than Session.
* Rename hash_untracked_state to track_state to indicate that it isn't just used for hashing state, but also for adding env vars and files to be tracked through the dep info file.
2026-03-18 15:07:31 +11:00