Commit Graph

11266 Commits

Author SHA1 Message Date
Jonathan Brouwer 1e793cdad3 Remove AttributeDuplicates from BUILTIN_ATTRIBUTES 2026-04-13 20:51:24 +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
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
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
Waffle Lapkin 6a4eefde2d ty::Alias refactor: fix clippy 2026-04-07 10:08:12 +02:00
Philipp Krones dc57fd7f53 Merge commit '88f787d193fb1f0491b001288e82b5574c080606' into clippy-subtree-update 2026-04-04 14:39:31 +02:00
Edvin Bryntesson 39f52ee1e2 deduplicate unused expect lints 2026-04-03 11:08:11 +02:00
Edvin Bryntesson d0594c1ad7 bless tests and tidy
also removes E0452 and splits
`tests/rustdoc-ui/lints/renamed-lint-still-applies` into 2 tests

this is because of delayed warn lint being lost on compiler aborting on
error
2026-04-03 11:08:11 +02:00
Edvin Bryntesson f04b718655 integrate parsed lint attrs into clippy 2026-04-03 11:08:10 +02:00
CoCo-Japan-pan 232d064efd Lower impl restriction to HIR 2026-04-01 12:01:40 +09:00
may 697ae4ac10 apply review suggestions and move Cow sym to rustc 2026-03-31 21:32:31 +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
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
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
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
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
Philipp Krones 86390a3c03 Merge commit '256c21c543ca422b3ab8810a0d081d722408e896' into clippy-subtree-update 2026-03-21 14:13:09 +01: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
Esteban Küber e389568d92 fix clippy test 2026-03-14 20:43:57 +00:00
bjorn3 62bd45d7be Move env/file_depinfo from ParseSess to Session 2026-03-12 15:35:27 +00:00
Asuna 47ee2e2570 Add macro matcher for guard fragment specifier 2026-03-12 02:18:34 +00:00
randomicon00 47f87537a3 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.

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.
2026-03-11 20:31:34 -04:00
Jonathan Brouwer 1d0d647b4c Rollup merge of #153641 - nnethercote:mv-Spanned, r=JonathanBrouwer
Move `Spanned`.

It's defined in `rustc_span::source_map` which doesn't make any sense because it has nothing to do with source maps. This commit moves it to the crate root, a more sensible spot for something this basic.

r? @JonathanBrouwer
2026-03-10 22:46:56 +01:00
Nicholas Nethercote f599afe624 Move Spanned.
It's defined in `rustc_span::source_map` which doesn't make any sense
because it has nothing to do with source maps. This commit moves it to
the crate root, a more sensible spot for something this basic.
2026-03-11 06:25:23 +11:00
Guillaume Gomez ab867a90e1 Remove usage of TyCtxt::node_span_lint in clippy 2026-03-09 22:50:10 +01:00
Josh Stone c260a1fb50 Update cfg(bootstrap) 2026-03-07 10:42:02 -08:00
bors 1fc8c3bd9a Auto merge of #153507 - JonathanBrouwer:rollup-ki59UTE, r=JonathanBrouwer
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#153466 (`rust-analyzer` subtree update)
 - rust-lang/rust#151280 (Fix incorrect trailing comma suggested in no_accessible_fields)
 - rust-lang/rust#152593 (Box in `ValTreeKind::Branch(Box<[I::Const]>)` changed to `List`)
 - rust-lang/rust#153174 (std: add wasm64 to sync::Once and thread_parking atomics cfg guards)
 - rust-lang/rust#153485 (libcore float tests: replace macro shadowing by const-compatible macro)
 - rust-lang/rust#153495 (Fix ICE in `offset_of!` error recovery)
 - rust-lang/rust#152040 (Do not emit ConstEvaluatable goals if type-const)
 - rust-lang/rust#152741 (Suppress invalid suggestions in destructuring assignment)
 - rust-lang/rust#153189 (refactor: move `check_align` to `parse_alignment`)
 - rust-lang/rust#153230 (Roll rustfmt reviewers for in-tree rustfmt)
 - rust-lang/rust#153445 (Consider try blocks as block-like for overflowed expr)
 - rust-lang/rust#153452 (Cleanup unused diagnostic emission methods)
 - rust-lang/rust#153476 (bootstrap.py: fix typo "parallle")
 - rust-lang/rust#153483 (Preserve parentheses around `Fn` trait bounds in pretty printer)
2026-03-06 19:09:12 +00:00
Guillaume Gomez ae25efb4ac Fix panic by setting the span before it is actually needed 2026-03-06 16:38:53 +01:00
Guillaume Gomez dbb159a432 Remove usage of LintContext::span_lint in clippy 2026-03-05 23:53:53 +01:00
Philipp Krones b4d2445432 Merge commit 'e645f93552c3926a0bb481a777df120b7bce986f' 2026-03-05 17:18:20 +01:00
Jonathan Brouwer 86e6165d72 Rollup merge of #153319 - DanielEScherzer:ie-dots, r=jhpratt
Comments and docs: add missing periods to "ie."

"i.e." is short for the Latin "id est" and thus both letters should be followed by periods.
2026-03-03 13:08:45 +01:00
Jonathan Brouwer a2b29fbb12 Rollup merge of #152943 - CoCo-Japan-pan:impl-restriction-parse, r=Urgau,jhpratt
Parse `impl` restrictions

This PR implements the parsing logic for `impl` restrictions (e.g., `pub impl(crate) trait Foo {}`) as proposed in [RFC 3323](https://rust-lang.github.io/rfcs/3323-restrictions.html).
As the first step of the RFC implementation, this PR focuses strictly on the parsing phase. The new syntax is guarded by the `#![feature(impl_restriction)]` feature gate.
This implementation basically follows the pattern used in rust-lang/rust#141754.

r? @jhpratt
2026-03-03 13:08:43 +01:00
Jonathan Brouwer 3b4e355a0a Rollup merge of #153227 - kpreid:struct-missing-field, r=estebank
Don’t report missing fields in struct exprs with syntax errors.

@Noratrieb [told me](https://internals.rust-lang.org/t/custom-cargo-command-to-show-only-errors-avoid-setting-rustflags-every-time/24032/7?u=kpreid) that “it is a bug if this recovery causes follow-up errors that would not be there if the user fixed the first error.” So, here’s a contribution to hide a follow-up error that annoyed me recently.

Specifically, if the user writes a struct literal with a syntax error, such as

```rust
StructName { foo: 1 bar: 2 }
```

the compiler will no longer report that the field `bar` is missing in addition to the syntax error.

This is my first time attempting any change to the parser or AST; please let me know if there is a better way to do what I’ve done here. ~~The part I’m least happy with is the blast radius of adding another field to `hir::ExprKind::Struct`, but this seems to be in line with the style of the rest of the code. (If this were my own code, I would consider changing `hir::ExprKind::Struct` to a nested struct, the same way it is in `ast::ExprKind`.)~~ The additional information is now stored as an additional variant of `ast::StructRest` / `hir::StructTailExpr`.

**Note to reviewers:** I recommend reviewing each commit separately, and in the case of the first one with indentation changes ignored.
2026-03-03 07:14:12 +01:00
Daniel Scherzer 611ff0992d Comments and docs: add missing periods to "ie."
"i.e." is short for the Latin "id est" and thus both letters should be followed
by periods.
2026-03-02 18:11:13 -08:00
Jonathan Brouwer af041c658f Rollup merge of #153015 - joboet:atomic_alias_generic, r=jhpratt
core: make atomic primitives type aliases of `Atomic<T>`

Tracking issue: https://github.com/rust-lang/rust/issues/130539

This makes `AtomicI32` and friends type aliases of `Atomic<T>` by encoding their alignment requirements via the use of an internal `Storage` associated type. This is also used to encode that `AtomicBool` store a `u8` internally.

Modulo the `Send`/`Sync` implementations, this PR does not move any trait implementations, methods or associated functions – I'll leave that for another PR.
2026-03-02 20:10:34 +01:00
joboet 9f97c53f1c bless UI tests referencing atomic primitives 2026-03-02 00:23:24 +01:00
joboet 1380fa6021 update references to Atomic in diagnostics
... and remove some unused diagnostic items.
2026-03-02 00:23:23 +01:00