Clippy subtree update#154809
Conversation
Detects `a.and_then(|x| b.map(|y| (x, y)))` and suggests `a.zip(b)`.
Co-authored-by: Ada Alakbarova <58857108+ada4a@users.noreply.github.com>
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. 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.
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>
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>
Detects manual implementations of the newly implemented [`BinaryHeap::pop_if()`](rust-lang#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()`
…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 (3b1b0ef 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.
…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 rust-lang#153103
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
…nathanBrouwer Rollup of 13 pull requests Successful merges: - rust-lang#154241 (`rust-analyzer` subtree update) - rust-lang#153686 (`std`: include `dlmalloc` for all non-wasi Wasm targets) - rust-lang#154105 (bootstrap: Pass `--features=rustc` to rustc_transmute) - rust-lang#153069 ([BPF] add target feature allows-misaligned-mem-access) - rust-lang#154085 (Parenthesize or-patterns in prefix pattern positions in pretty printer) - rust-lang#154191 (refactor RangeFromIter overflow-checks impl) - rust-lang#154207 (Refactor query loading) - rust-lang#153540 (drop derive helpers during attribute parsing) - rust-lang#154140 (Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.) - rust-lang#154161 (On E0277 tweak help when single type impls traits) - rust-lang#154218 (interpret/validity: remove unreachable error kind) - rust-lang#154225 (diagnostics: avoid ICE in confusable_method_name for associated functions) - rust-lang#154228 (Improve inline assembly error messages)
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%
…ng#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%
…ust-lang#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
…ulacrum don't drop arguments' temporaries in `dbg!` Fixes rust-lang#153850 Credit to @theemathas for help with macro engineering ^^ r? libs
--- *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: none
rustc doesn't keep around proc macro helper attributes in the HIR. So it is no longer possible to lint this. In a LateLintPass the necessary information isn't around anymore, in an EarlyPassLint derive attributes are already expanded and dropped and it is not possible to relate an impl with the type it is implemented on. Doing that with `ast::Path`s is brittle.
r? @ghost changelog: none
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
|
|
@bors r+ p=1 rollup=never |
|
Scheduling: Make sure this runs next after the current rollup (was: p=1). @bors p=5 |
This comment has been minimized.
This comment has been minimized.
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing c92036b (parent) -> f92020a (this PR) Test differencesNo test diffs found Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard f92020a676251cf985cbe5134a1fd976b5207ab6 --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (f92020a): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary 0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 488.313s -> 492.059s (0.77%) |
r? Manishearth
2 days late due to some sync difficulties.