Commit Graph

56881 Commits

Author SHA1 Message Date
Matthias Krüger c67006e139 Rollup merge of #156797 - ariagivens:suggest-quotes, r=JonathanBrouwer
Suggest adding quotation marks to identifiers in attributes

When the user provides an identifier when a literal was expected in an attribute value, suggest adding quotation marks to the identifier to make it a string literal.

For instance:
```
error: attribute value must be a literal
  --> $DIR/crate-type-non-crate.rs:9:16
   |
LL | #[crate_type = lib]
   |                ^^^ help: try adding quotation marks: `"lib"`
```
2026-05-28 07:53:36 +02:00
Matthias Krüger ac7ba99209 Rollup merge of #156403 - SpriteOvO:type-info-refactor-variant, r=oli-obk
Add `TypeId` methods `variants` `fields` `field` for `type_info`

Tracking issue rust-lang/rust#146922

- Adds `fn TypeId::variants` returns the number of variants, for struct and union and primitive types, it's always 1.
- Adds `fn TypeId::fields` returns the number of fields.
- Adds `fn TypeId::field` returns a field representing type `FieldId`.
- Adds a new type `FieldId`, which is a wrapper of `FieldRepresentingType`'s `TypeId`.

For methods `{fields,field}`, if indexing out of bounds, a compile-time error will be raised.

Regarding the removal of `Type` items, this will be done in a later PR in one go.

r? @oli-obk
2026-05-28 07:53:35 +02:00
Asuna b513e539c3 FieldId wraps FRT TypeId instead of the actual field TypeId 2026-05-27 22:25:09 +00:00
Guillaume Gomez e8d970b08a Rollup merge of #156988 - RalfJung:validate-uninhabited, r=oli-obk
interpret/validity: properly treat zero-variant enums so that we do not have to check layout.is_uninhabited

I am very happy to finally remove the last of these somewhat ad-hoc checks. :)

r? @oli-obk
2026-05-27 20:45:15 +02:00
Guillaume Gomez 0846622465 Rollup merge of #156973 - Darksonn:unwind-tables-module, r=nnethercote
Add uwtable annotation to modules when required

When unwind tables are enabled with `-Cforce-unwind-tables=y`, Rust will annotate all functions with the `uwtable` annotation. However, this annotation is missing on modules, which leads to incorrect unwind tables being generated by LLVM for constructors (such as `asan.module_ctor`).

This was discovered because it leads to a crash in Linux when KASAN and dynamic shadow call stack are both enabled. In this scenario, the kernel uses the unwind tables to locate the `paciasp` and `autiasp` instructions in each function and patches the machine code at boot to use the shadow call stack instructions instead. However, LLVM's AArch64PointerAuth pass emits DWARF info for `paciasp` whenever `-g` is passed, but only emits DWARF info for `autiasp` when the `uwtable` attribute is present. Since the `uwtable` annotation is missing for modules, the relevant directives are generated for only the `autiasp` instruction in `asan.module_ctor`, and not for the `paciasp` instruction. This causes the kernel's dynamic SCS logic to patch the prolouge of `asan.module_ctor`, but not the epilogue. This leads to a crash as the shadow call stack becomes unbalanced.

The fact that LLVM doesn't use the same condition for whether to emit DWARF information for both instructions may be a separate bug in LLVM.

Relevant issue: https://github.com/llvm/llvm-project/issues/188234

AI assistance was used to determine the root cause of this crash from the observed symptoms, and to write the tests. Also thanks to @samitolvanen and @maurer for debugging this issue.

Similar to this previous PR of mine: rust-lang/rust#130824
2026-05-27 20:45:14 +02:00
Guillaume Gomez 3e15f828f6 Rollup merge of #156955 - P8L1:fix-reborrow-promotion-consteval, r=RalfJung
Fix const-eval of shared generic reborrows

`Rvalue::Reborrow` const-eval now handles shared generic reborrows produced by `CoerceShared`. Those reborrows intentionally copy from the source ADT into a distinct same-layout target ADT, so the interpreter uses the transmute-capable copy path for `Mutability::Not`.

Promotion is intentionally kept conservative: promotion candidates whose validated temporary graph contains `Rvalue::Reborrow` are rejected, so generic/user-defined reborrows are not promoted.

Fixes rust-lang/rust#156313.
cc @aapoalas
Tracking: rust-lang/rust#145612
@rustbot label F-reborrow
2026-05-27 20:45:13 +02:00
Guillaume Gomez 66ce7b0106 Rollup merge of #156845 - onehr:clarify-cyclic-type-149842, r=JohnTitor
Clarify "infinite size" in cyclic-type diagnostic refers to the type name

Closes rust-lang/rust#149842

The `TypeError::CyclicTy` diagnostic currently emits
"cyclic type of infinite size". As discussed in the issue, "infinite
size" reads as the in-memory `size_of::<T>()` of values, when it
actually refers to the textual representation of the type name (an
iso-recursive occurs-check failure).

This rewords the message so the qualifier "infinite-size" clearly
modifies the *name*, matching the direction `@fmease`, `@BoxyUwU`,
and the issue author converged on:

```
- cyclic type of infinite size
+ recursive type with infinite-size name
```

Nine existing UI `.stderr` baselines and two `//~ NOTE` annotations
are updated to track the new wording. No semantics change.

Tested:
- ./x test tests/ui/const-generics/occurs-check/ tests/ui/closures/ tests/ui/unboxed-closures/ tests/ui/typeck/ tests/ui/coroutine/ --force-rerun
- ./x test tidy
2026-05-27 20:45:12 +02:00
Guillaume Gomez dc05df7ebe Rollup merge of #157022 - RalfJung:inline-intrinsics-v2, r=oli-obk
MIR inlining: allow backends to opt-in to inlining intrinsics

This is the same as https://github.com/rust-lang/rust/pull/156398. Github stopped processing updates on that other branch.

r? @oli-obk
2026-05-27 20:45:10 +02:00
Guillaume Gomez 1159cb541c Rollup merge of #156970 - qaijuang:async_closure_coverage, r=Zalathar
coverage: Use original HIR info for synthetic by-move coroutine bodies

> This is a copy of #156952(because my git was acting weird)

Synthetic by-move coroutine bodies created for async closures don't have useful HIR of their own. Coverage was falling back to the parent async closure for HIR info, which means the executed `AsyncFnOnce` body could inherit hole spans from the wrong body and report the user-written closure body as uncovered.

This PR uses the synthetic body's coroutine type to recover the original coroutine body def-id, then extracts HIR info from that body instead. That keeps the coverage spans tied to the body the synthetic MIR was cloned from.

Fixes rust-lang/rust#151135.

r? Zalathar
2026-05-27 20:45:09 +02:00
Pieter-Louis Schoeman 56f5c38840 Fix const-eval of shared generic reborrows 2026-05-27 18:17:14 +02:00
Ralf Jung 59428e76e8 MIR inlining: allow backends to opt-in to inlining intrinsics 2026-05-27 13:59:25 +02:00
bors 77a4fb62f7 Auto merge of #155678 - aerooneqq:single-owners-query-exp, r=oli-obk
Merge several HIR-level queries into one



Now four queries (`local_def_id_to_hir_id`, `opt_hir_owner_nodes`, `opt_ast_lowering_delayed_lints`, `in_scope_traits_map`) were replaced with regular methods which acts like getters. 
An `hir_owner` query was added that returns a `ProjectedMaybeOwner` that contains all those fields. `hir_attr_map` remains a separate query as adding attributes to `ProjectedMaybeOwner` led to [perf regressions](https://github.com/rust-lang/rust/pull/155678#issuecomment-4304597871). 
There is a similar issue with `in_scopes_trait_map`, but according to the comments from https://github.com/rust-lang/rustc-perf/pull/2436 it is a rare case.
Most of the changes in incremental tests are renames from `opt_hir_owner_nodes` -> `hir_owner`, but there are few cases when new dirty queries were added.

r? @petrochenkov
r? @oli-obk
2026-05-27 11:45:44 +00:00
Alice Ryhl 90fe8cc66f Adjust UWTableKind comment ref to llvm type 2026-05-27 09:27:35 +00:00
Jonathan Brouwer 694ce93540 Rollup merge of #156975 - mejrs:move_check_cfg, r=GuillaumeGomez,JonathanBrouwer
Move check_cfg out of diagnostic attr module

r? @GuillaumeGomez
2026-05-27 08:14:29 +02:00
Jonathan Brouwer 1bc84618a1 Rollup merge of #156972 - lcnr:field_projections-fixme, r=Nadrieril
add field_projections fixme

haven't looked at the code in detail, but I can't see a way in which this is the correct behavior. I think ideally `try_evaluate_added_goals` just doens't return the certainty as afaik it only does so because `evaluate_added_goals_and_make_canonical_response` uses it internally

r? @Nadrieril @BennoLossin
2026-05-27 08:14:29 +02:00
Jonathan Brouwer 241bbc18fc Rollup merge of #156942 - GuillaumeGomez:rm-skip_arg-attrs, r=JonathanBrouwer
Remove unneeded `#[skip_arg]` attributes

@mejrs talked with me about the `Diagnostic` rework that happened recently and suggested that the `skip_arg` might be unneeded. This PR removes all of them, except one. I'll run a perf check to see if it's actually worth keeping around or if we can just remove this attribute altogether (or eventually do the same thing in the proc-macro directly).

cc @JonathanBrouwer

r? ghost
2026-05-27 08:14:28 +02:00
Jonathan Brouwer aa9d13374b Rollup merge of #156814 - cezarbbb:fix-issue-156714, r=jieyouxu
Extend macOS deployment target mismatch filter to cover dylib and new ld formats

The `deployment_mismatch` filter in `report_linker_output` only matched the old ld64 format for object files. With linker-messages promoted to warn-by-default in rust-lang/rust#153968, unfiltered deployment target warnings from dylibs and the new Apple linker (ld_prime) now surface as noise for users who never set `MACOSX_DEPLOYMENT_TARGET`.

Fixes rust-lang/rust#156714.

At present, the filter works only covered the specific format:

`ld: warning: object file (...) was built for newer 'macOS' version (...) than being linked (...)`

This was fine because linker-messages was `Allow-by-default` — nobody saw the other formats anyway. Then rust-lang/rust#153968 promoted it to Warn, and the gaps became visible.

Broadens the filter to cover all known ld deployment target version mismatch formats:

`ld: warning: object file (...)` — old ld64, already handled
`ld: warning: dylib (...)` — old ld64, was missing
All Apple platforms (`iOS`, `tvOS`, `watchOS`, `xrOS`, etc.), not just `macOS`
`ld: building for <platform>-A.B, but linking with dylib '...' which was built for newer version C.D` — new linker (ld_prime, Xcode 15+), the exact format from rust-lang/rust#156714

All matched messages are downgraded to `linker_info` (Allow-by-default), consistent with the existing behavior for the object file case.
2026-05-27 08:14:26 +02:00
Jonathan Brouwer 806a5186d4 Rollup merge of #156545 - bb1yd:issue-144595, r=mejrs
fix issue-144595

I close the previous PR because it's too messy

relevant issue:rust-lang/rust#144595

I fix this issue by calling `look_ahead` to check if the user write a name field in the tuple struct, then try to recover after calling `parse_ty`
2026-05-27 08:14:26 +02:00
Jonathan Brouwer b0760d1d8e Rollup merge of #156933 - madsravn:wrong-order-more, r=estebank
rustc_parse_format: improve the error diagnostic for `+` sign flag

Added a new parser diagnostic in rustc_parse_format that detects when the `+` sign flag is used without a preceding colon in a format string (e.g., `{+}`) and provides a helpful error message and suggestion to use `{:+}` instead.

r? estebank
2026-05-27 08:14:25 +02:00
Jonathan Brouwer 495657cc2a Rollup merge of #156796 - Kokoro2336:fix/match-str-sugg, r=estebank
Fix missing suggestion when matching `String` with `&str`

Fixes rust-lang/rust#156404

Add suggestion when matching `String` with `&str`
2026-05-27 08:14:24 +02:00
cezarbbb 52bedb4c05 Suppress macOS deployment target linker warnings from ld_prime 2026-05-27 11:32:09 +08:00
Ralf Jung e724fa6620 interpret/validity: properly treat zero-variant enums so that we do not have to check layout.is_uninhabited 2026-05-26 20:05:49 +02:00
mejrs a2b21900b4 Move check_cfg out of diagnostic attr module 2026-05-26 17:16:20 +02:00
lcnr f7c35686aa add field_projections fixme 2026-05-26 16:39:09 +02:00
Alice Ryhl f46fade899 Emit uwtable annotation for modules 2026-05-26 14:32:05 +00:00
qaijuang cf3249c0cc coverage: Use original HIR info for synthetic by-move coroutine bodies 2026-05-26 10:01:36 -04:00
b1yd 92194469a0 fix issue-144595 2026-05-26 21:35:25 +08:00
Jonathan Brouwer bd59ff8d66 Rollup merge of #156872 - cjgillot:skip_move_check_fns, r=oli-obk
Drop skip_move_check_fns query.

Looking at the header of the impl block for each method can be just as fast.
2026-05-26 13:42:18 +02:00
Jonathan Brouwer dc3bdafaaf Rollup merge of #156752 - 42triangles:fix-dyn-trait-descr, r=oli-obk
fix E0371 description

This changes the `impl`s to be `impl {Trait} for dyn {Trait}` instead of just `impl {Trait} for {Trait}` in the description of E0371.

(While this was not part of "Crafting errors like rustc" workshop at RustWeek by @jdonszelmann and @estebank, I found this while going through all errors Rust emits to pick a favourite)
2026-05-26 13:42:16 +02:00
Jonathan Brouwer 903a08c0b0 Rollup merge of #156161 - mejrs:this_formatargs, r=oli-obk
rustc_on_unimplemented: introduce format specifiers

...as printing options for the annotated item.

See also the test and dev guide prose. This only affects rustc_on_unimplemented, not (yet) the other diagnostic attributes. I plan to do that in some later PR.

```rust
#![feature(rustc_attrs)]

#[rustc_on_unimplemented(
    message = "normal: {This}, path: {This:path},  resolved: {This:resolved}"
)]
pub trait Trait<'lifetime, const CONST_GENERIC: usize, A, B> where A: Send {}
```
will do:
```
normal: Trait, path: Trait<'lifetime, CONST_GENERIC, A, B>,  resolved: Trait<'_, 6, u8, _>
```
2026-05-26 13:42:16 +02:00
Jonathan Brouwer f09612e237 Rollup merge of #156541 - aerooneqq:delegation-no-method-call, r=petrochenkov
delegation: remove method call generation

This PR removes method call generation from delegations, now we always generate default call. Part of rust-lang/rust#118212.

We reuse methods probing engine for finding needed adjustments, thus extending number of supported cases. In this PR adjustments are applied to trait methods (was supported before) ~and static functions (new feature)~. Free functions can be supported later.

Finally this PR solves issues from parent generics propagation from rust-lang/rust#155906.

r? @petrochenkov
2026-05-26 13:42:15 +02:00
Guillaume Gomez 9e96efac62 Remove unneeded #[skip_arg] attributes 2026-05-26 12:26:05 +02:00
aerooneqq fc6b395690 Make all fields of ProjectedOwnerInfo private 2026-05-26 08:35:55 +03:00
aerooneqq 6f0dc940a4 inspect -> is_some 2026-05-26 08:27:28 +03:00
aerooneqq 40a782103b Remove method call generation in delegation 2026-05-26 08:06:36 +03:00
bors b7e97a98f2 Auto merge of #156549 - GuillaumeGomez:ci-gcc-core, r=Kobzol
Add CI check when building sysroot with GCC backend and running libcore tests with it



Fixes https://github.com/rust-lang/rustc_codegen_gcc/issues/882.

Is it what you had in mind @Kobzol?

r? @Kobzol
2026-05-26 04:49:37 +00:00
Mads Ravn 900e061dce Removing Suggestion from ParseError and fixed tests accordingly 2026-05-25 21:34:36 +02:00
Mads Ravn 8495129357 Adding sign flag formatting error message 2026-05-25 21:23:46 +02:00
Kokoro2336 a09204ad18 fix: missing suggestion for string match.
chore: update .fixed.

fix: suggestion.

Revert irrelevant changes.
2026-05-26 02:01:52 +08:00
Hanna Kruppe f8f740baf0 convert lossy_provenance_casts to late lint 2026-05-25 13:57:41 +02:00
Hanna Kruppe 4539a75716 convert fuzzy_provenance_casts to late lint 2026-05-25 13:57:41 +02:00
bors 783eb8c868 Auto merge of #156861 - Dnreikronos:fix/strict-provenance-macro-suggestions, r=mu001999
Suppress garbled suggestions from strict provenance lints in macros

The strict provenance lints (`lossy_provenance_casts`, `fuzzy_provenance_casts`) build suggestions using span arithmetic (`shrink_to_lo()`, `shrink_to_hi()`, `.to()`). When the cast sits inside a macro, those span operations produce broken output like `$e as ).addr()` because the spans don't map cleanly back to source text.

The fix wraps suggestion fields in `Option` and checks `can_be_used_for_suggestions()` before constructing them. The lint itself still fires, you just don't get the garbled suggestion. Same approach already used in `op.rs` and `static_mut_refs.rs` in this crate.

### What changed

- `errors.rs`: `sugg` fields in `LossyProvenanceInt2Ptr` and `LossyProvenancePtr2Int` are now `Option<...>`
- `cast.rs`: suggestion construction in both `lossy_provenance_ptr2int_lint` and `fuzzy_provenance_int2ptr_lint` is guarded behind `can_be_used_for_suggestions()`
- New regression test confirms both lints fire on casts inside macros, with no suggestion block in output

Fixes rust-lang/rust#156850
2026-05-25 06:13:22 +00:00
bors 423e3d2529 Auto merge of #156893 - JonathanBrouwer:rollup-KrnXZ2W, r=JonathanBrouwer
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#142611 (Do not suggest compatible variants inside macro)
 - rust-lang/rust#156692 (compiletest: Prepare all simple `//@ needs-*` conditions in advance)
 - rust-lang/rust#156847 (Fix suggestion of unused variables with raw identifier in struct pattern)
 - rust-lang/rust#156876 (Remove useless -Zunpretty=identified option)
 - rust-lang/rust#156884 (Revert "Allow `global_asm!` in statement positions")
2026-05-24 19:34:37 +00:00
Jonathan Brouwer 5de5cc7565 Rollup merge of #156884 - folkertdev:revert-global-asm-inner-item, r=workingjubilee
Revert "Allow `global_asm!` in statement positions"

This reverts commit 450cdb5501.

Based on discussion in [#t-lang > insta-stable &#96;global_asm!&#96; as inner items](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/insta-stable.20.60global_asm.21.60.20as.20inner.20items/with/597411711), https://github.com/rust-lang/rust/pull/156582 should not have been merged without FCP.

We've also since found a bug in the implementation (or really, an assumption in the existing code that the PR invalidates), so to re-land this

- new behavior should be behind a feature gate
- the fix in https://github.com/rust-lang/rust/pull/156855#issuecomment-4529335602 should be included (and reviewed by someone familiar with `rustc_resolve`)

Then we keep it unstable for a bit, and see if the fuzzer finds anything else. Nothing here is particularly controversial I think, but we need to do our due diligence.

r? @ghost
2026-05-24 21:28:54 +02:00
Jonathan Brouwer 9722e30c7c Rollup merge of #156876 - fallofpheonix:fix-unpretty-identified, r=bjorn3
Remove useless -Zunpretty=identified option

The `-Zunpretty=identified` option (without `expanded`) is effectively useless because `NodeId`s are unassigned prior to macro expansion, leading them to just be `NodeId::MAX_AS_U32`.

This commit removes the `Identified` variant from `PpSourceMode` and removes `-Zunpretty=identified` from the command-line options. Users should use `-Zunpretty=expanded,identified` instead (which is retained) if they want to inspect `NodeId`s.

Fixes rust-lang/rust#10671
2026-05-24 21:28:53 +02:00
Jonathan Brouwer 8a34a4e505 Rollup merge of #156847 - sappho3:fix-suggestion-unused-variables-struct-pattern, r=JonathanBrouwer
Fix suggestion of unused variables with raw identifier in struct pattern

This MR fixes a broken lint suggestion that occurs when a struct pattern contains an unused variable written with a raw identifier.

In the following fragment, `r#move` is an unused variable. The compiler suggested to change it to `move: _` which doesn’t compile since move is a keyword. This change makes it so that the suggestion becomes `r#move: _`

```rust
struct Foo {
    r#move: u32
}

fn bar(foo: Foo) -> u32 {
    match foo {
         Foo { r#move } => 0
    }
}
```

r? JonathanBrouwer
2026-05-24 21:28:53 +02:00
Jonathan Brouwer 0db96fd0e5 Rollup merge of #142611 - xizheyin:142359, r=jieyouxu
Do not suggest compatible variants inside macro

Fixes rust-lang/rust#142359

r? compiler
2026-05-24 21:28:51 +02:00
Folkert de Vries 00ada0feb1 Revert "Allow global_asm! in statement positions"
This reverts commit 450cdb5501.
2026-05-24 18:59:08 +02:00
bors 609b8c5cef Auto merge of #156881 - jhpratt:rollup-Z5cqxkd, r=jhpratt
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#156824 (Parse `mut` restrictions)
 - rust-lang/rust#156810 (Fix doc typo in Vec::into_array and convert Arc/Box/Rc::into_arry to -> Result)
 - rust-lang/rust#156833 (Add regression test for const parameter default ICE)
 - rust-lang/rust#156843 (Make impl_trait_redundant_captures suggestion remove adjacent +)
2026-05-24 16:18:27 +00:00
Dnreikronos ccac0d9744 Suppress garbled suggestions from strict provenance lints in macros 2026-05-24 12:58:07 -03:00