Commit Graph

17985 Commits

Author SHA1 Message Date
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
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 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
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
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
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
b1yd 92194469a0 fix issue-144595 2026-05-26 21:35:25 +08:00
Jonathan Brouwer d9b3fefbb1 Rollup merge of #156927 - zedddie:gsoc-batch-1-meow, r=Kivooeo
Reorganize `tests/ui/issues` [1/N]

Part of [GSoC'26 project](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Reorganizing.20tests.2Fui.2Fissues)

r? Kivooeo
@Teapot4195
2026-05-26 13:42:20 +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
aerooneqq 40a782103b Remove method call generation in delegation 2026-05-26 08:06:36 +03: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
Jonathan Brouwer 9ff5ee2532 Rollup merge of #156764 - mladedav:dm/private-public, r=Zalathar
tests: fix pub-priv-dep test expectation

Related to private dependencies rust-lang/rust#44663

The test had wrongly configured dependency privacy. The ascii graph shows that both dependencies should be private. Furthermore, the way this test existed was effectively identical to `shared_direct_private.rs`.
2026-05-25 20:54:06 +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
zedddie 480b44c8e1 bless batch 2026-05-25 18:08:12 +02:00
zedddie a25ec1a018 move batch 2026-05-25 17:55:04 +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 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
Dnreikronos ccac0d9744 Suppress garbled suggestions from strict provenance lints in macros 2026-05-24 12:58:07 -03:00
Jacob Pratt 794b44de55 Rollup merge of #156843 - onehr:fix-redundant-captures-143216, r=cjgillot
Make impl_trait_redundant_captures suggestion remove adjacent +

Closes rust-lang/rust#143216

The `impl_trait_redundant_captures` lint's machine-applicable suggestion only
spanned the `use<...>` syntax itself, leaving the adjacent `+` joiner behind.
Applying the suggestion produced uncompilable code, e.g.
`impl Sized + use<>` becoming `impl Sized + ` (stray trailing `+`).

This extends the removal span to also cover one adjacent `+`, preserving
valid syntax in the three bound-list positions covered by the regression test:

- `impl Sized + use<>` becomes `impl Sized`
- `impl use<> + Sized` becomes `impl Sized`
- `impl Sized + use<> + Send` becomes `impl Sized + Send`

A `//@ run-rustfix` UI test exercises all three positions, so the
rustfix-applied output is actually compiled — covering the gap the
existing `redundant.rs` test left (which only checks lint firing, not
suggestion correctness).

Tested:
- ./x test tests/ui/impl-trait/precise-capturing/redundant-machine-applicable.rs --bless
- ./x test tidy
2026-05-24 16:39:43 +02:00
Jacob Pratt 445a129436 Rollup merge of #156833 - onehr:ice-test-142913, r=TaKO8Ki
Add regression test for const parameter default ICE

Closes rust-lang/rust#142913

This adds a UI regression test for a fixed ICE where a const generic parameter
type mentioned an earlier lifetime and also had a default value.

The reproducer is the minimized version posted in the issue.

Tested:
- ./x test tests/ui/const-generics/generic_const_parameter_types/region-parameter-out-of-range-ice-142913.rs --force-rerun
- ./x test tidy --bless
2026-05-24 16:39:42 +02:00
Jacob Pratt 81eb844071 Rollup merge of #156824 - CoCo-Japan-pan:mut-restriction-parse, r=Urgau,jhpratt
Parse `mut` restrictions

This PR is part of the progress implementing `mut` restrictions proposed in [RFC 3323](https://rust-lang.github.io/rfcs/3323-restrictions.html), and linked to a [GSoC proposal](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Implementing.20impl.20and.20mut.20restrictions/with/592352432).
This PR focuses solely on the parsing of `mut` restrictions.
The keyword order is `pub(...) mut(...) unsafe field`.
The new syntax is guared by `#[feature(mut_restriction)]` feature gate.
Tracking Issue: rust-lang/rust#105077

r? @Urgau
cc @jhpratt
2026-05-24 16:39:41 +02:00
xizheyin bbd3554304 Do not suggest compatible variants crossing macro contexts 2026-05-24 20:41:45 +08:00
xizheyin 74760ffec4 Add suggest-compatible-variants-macro-issue-142359 2026-05-24 20:41:29 +08:00
bors a06c1ca53a Auto merge of #156839 - qaijuang:fix-single-use-lifetimes-impl-bounds, r=mu001999
[single_use_lifetimes]: Account for lifetime bounds

This PR makes `single_use_lifetimes` account for bounds on lifetime parameters, so a lifetime such as `'b` in `<'a, 'b: 'a>` is not treated as single-use just because its bound is stored separately from ordinary lifetime uses.

Fixes rust-lang/rust#153836
2026-05-24 09:47:31 +00:00
Haoran Wang 3e247a8ff4 Add regression test for const parameter default ICE 2026-05-24 17:14:33 +08:00
CoCo-Japan-pan 572a2e4177 Bless UI test for input-stats.rs 2026-05-24 17:34:01 +09:00
CoCo-Japan-pan d3bb7198e7 Add stringify! tests 2026-05-24 17:34:01 +09:00
CoCo-Japan-pan cb3173473c Add UI tests 2026-05-24 17:34:01 +09:00
Qai Juang ccb9e9e84a account for lifetime bounds in single_use_lifetimes 2026-05-24 04:15:17 -04:00
Jonathan Brouwer eb68b36521 Rollup merge of #156828 - P8L1:share-trait-core-bootstrap, r=SimonSapin
Add unstable Share trait

Tracking issue: rust-lang/rust#156756

This adds an initial unstable `Share` trait for clone-as-alias types, as part of the 2026 ergonomic ref-counting project goal.

```rust
pub trait Share: Clone {
    fn share(&self) -> Self {
        Clone::clone(self)
    }
}
```

This PR adds a separate unstable feature gate:

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

and places the trait next to `Clone` in `core::clone`.

Implemented initial impls:

- `impl<T: ?Sized> Share for &T`
- `impl<T: ?Sized, A: Allocator + Clone> Share for Rc<T, A>`
- `impl<T: ?Sized, A: Allocator + Clone> Share for Arc<T, A>`
- `impl<T> Share for std::sync::mpsc::Sender<T>`
- `impl<T> Share for std::sync::mpsc::SyncSender<T>`

The PR deliberately does not add `Share` to the prelude.

r? @nikomatsakis
@rustbot label F-ergonomic_clones
2026-05-24 08:27:21 +02:00
Jonathan Brouwer e938cd8409 Rollup merge of #156827 - SpecificProtagonist:float_literal_f32_fallback-suggestion, r=Kivooeo
float_literal_f32_fallback: Don't suggest invalid code

When a float literal ended with a dot, `float_literal_f32_fallback` should not include it in its suggestion, as that would result in invalid syntax ([playgound](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=de47274bf2b07070b79a97ce6744ffcbO)):

```
2 |     let _: f32 = From::from(0.);
  |                             ^^ help: explicitly specify the type as `f32`: `0._f32`
```

Relevant tracking issue: rust-lang/rust#154024
2026-05-24 08:27:20 +02:00
Jonathan Brouwer f38e177068 Rollup merge of #156784 - ikow:fix/reborrow-early-return, r=dingxiangfei2009
Fix reborrow_info early return skipping field validation

`reborrow_info` validates that all data fields of a struct implementing `Reborrow` are either `Copy` or themselves `Reborrow`. When iterating the fields, finding a `Reborrow` field returned `Ok(())` immediately, so any remaining fields were never validated. This let a struct with a non-`Copy`, non-`Reborrow` second field implement `Reborrow`.

Changing the early `return Ok(())` to `continue` makes the loop validate every field.

Tracking issue: rust-lang/rust#145612
2026-05-24 08:27:19 +02:00
bors dd8b2d6162 Auto merge of #155598 - makai410:partial-ord, r=nnethercote
Implement fast path for `derive(PartialOrd)` when deriving `Ord`



Closes: https://github.com/rust-lang/rust/issues/155537

Unfortunately, this PR shares the same issue with https://github.com/rust-lang/rust/issues/124794, which doesn't work when `derive(PartialOrd)` is before `derive(Ord)`.
2026-05-24 00:06:21 +00:00
Pieter-Louis Schoeman 2f953da599 Remove unnecessary Share feature gate plumbing 2026-05-23 17:33:22 +02:00
Makai 766428b312 Avoid regression in derive(PartialOrd) for single fieldless variant enums 2026-05-23 20:32:20 +08:00
Haoran Wang b6eb265902 Keep redundant-capture suggestions syntactically valid
The lint suggestion now removes the `+` joiner adjacent to a redundant
`use<...>` clause, so applying the suggestion does not leave a dangling
`+` that fails to parse.

The existing `tests/ui/impl-trait/precise-capturing/redundant.stderr`
baseline emits the same diagnostic with the expanded suggestion span and
is blessed along with the new `run-rustfix` test.

Tested:
- ./x test tests/ui/impl-trait/precise-capturing/redundant.rs --force-rerun
- ./x test tests/ui/impl-trait/precise-capturing/redundant-machine-applicable.rs --force-rerun
- ./x test tidy
2026-05-23 19:14:47 +08:00
Sappho de Nooij 8604f001a9 Fix suggestion of unused variables with raw identifier in struct pattern
This commit fixes a broken suggestion that occurs when a struct pattern contains an unused
variable written with a raw identifier.
2026-05-23 09:33:09 +02:00