3050 Commits

Author SHA1 Message Date
James Barford-Evans
df74b1fe51 Remove ConstExt from ./compiler 2026-10-13 07:02:00 +01:00
Ralf Jung
0e50382a02 const-check: clarify when and how we can rely on non-UB assumptions 2026-10-10 15:20:35 +02:00
Ralf Jung
e3941d67fb const-eval: ICE when we hit a non-const fn 2026-10-09 15:44:27 +02:00
Jonathan Brouwer
1cf13b7953 Rollup merge of #163855 - estebank:const-context-spans, r=oli-obk
Include enclosing item's context on const errors

On const errors, when they occur on an item that might be relevant, like in an associated const, render the line of the enclosing item in the error:

```
error[E0080]: evaluation panicked: not yet implemented
  --> $DIR/ice-normalize-inherent-assoc-const.rs:10:28
   |
LL | impl Foo {
LL |     const ASSOC_C: usize = todo!();
   |                            ^^^^^^^ evaluation of `Foo::ASSOC_C` failed here
```
```
error[E0080]: writing to ALLOC$ID which is read-only
  --> $DIR/issue-100313.rs:18:5
   |
LL | const _: () = {
LL |     let x = T::<{ &true }>;
LL |     x.set_false();
   |     ^^^^^^^^^^^^^ evaluation of `_` failed inside this call
   |
note: inside `T::<&true>::set_false`
  --> $DIR/issue-100313.rs:11:13
   |
LL | impl<const B: &'static bool> T<B> {
LL |     const fn set_false(&self) {
LL |         unsafe {
LL |             *(B as *const bool as *mut bool) = false;
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the failure occurred here
```
2026-10-08 21:49:57 +02:00
Esteban Küber
8186e2c2c5 Include enclosing item's context on const errors 2026-10-08 10:13:45 +00:00
Jonathan Brouwer
6b354e2160 Rollup merge of #163935 - tmiasko:start-location, r=beetrees
Use BasicBlock::start_location and Location::START

Construct special MIR locations concisely.
2026-10-08 08:55:40 +02:00
Josh Triplett
ec45ecffee Move loop_hint_attrs from Terminator into TerminatorKind::Goto
Only the `Goto` variant uses `loop_hint_attrs`, so other variants
shouldn't pay the cost. This shrinks `Terminator` and thus
`BasicBlockData` by 8 bytes, and also simplifies many users of
`Terminator`.

Every byte saved from `BasicBlockData` makes a big difference in
max-rss. For aws-sdk-ec2 full check, this saves 34.1 MiB (~0.62% of its
peak RSS)

Add a `TerminatorKind::goto` helper function for convenient construction
with a target and no hints. With that helper available, most of this
commit is simple, straightforward, mechanical translations of
construction or pattern matching. The only notable changes are:

- `compiler/rustc_codegen_ssa/src/mir/block.rs` actually uses the moved hints.
- `compiler/rustc_middle/src/mir/mod.rs` updates the size assertions.
- `compiler/rustc_mir_build/src/builder/cfg.rs` adds/updates helpers.
- `compiler/rustc_mir_build/src/builder/expr/into.rs` has the one place
  that creates a `Goto` with non-empty hints.
2026-10-07 10:40:47 -07:00
tmiasko
6545abe319 Use BasicBlock::start_location and Location::START 2026-10-07 11:45:59 +00:00
Esteban Küber
8cb6fcaa8f Another useless into 2026-10-04 00:12:30 +00:00
Jonathan Brouwer
df410a2ac9 Rollup merge of #163663 - yara-blue:reflection-ice-typeid-info, r=oli-obk
reflection: fix ICE when TypeId::info called on ADT

We are refactoring from a large enum where the fields of the variants contain all the reflection info to a flat enum containing only the type kind (struct/bool/array etc). While we removed the fields of Struct, Enum and Union we forgot to take out the const eval code writing into those fields. That gave an ICE. This fixes that.
2026-10-03 12:22:27 +02:00
Jonathan Brouwer
99f6df7fc7 Rollup merge of #163574 - tgross35:intrinsics-abort-rename, r=clarfonthey
intrinsics: Rename `abort` to `abort_immediate`

The semantics of `intrinsics::abort()` are closer to what we have unstably as `abort_immediate()` than to `process::abort()` or `libc::abort()`. Rename it to make more clear that the intrinsic is more of an intentional crash with platform-specific behavior than what `libc::abort()` tries to be (i.e. raising `SIGABRT`).

If desired, a new intrinsic like `abort_gracefully` could be introduced that performs platform-specific behavior. This would more cleanly unblock https://github.com/rust-lang/rust/pull/149780.

See also discussion at the tracking issue for `immediate_abort` https://github.com/rust-lang/rust/issues/154601.
2026-10-02 22:39:48 +02:00
Yara
da0baa24c4 reflection: fix ICE when TypeId::info called on ADT
We are refactoring from a large enum where the fields of the variants
contain all the reflection info to a flat enum containing only the type
kind (struct/bool/array etc). While we removed the fields of Struct,
Enum and Union we forgot to take out the const eval code writing into
those fields. That gave an ICE. This fixes that.
2026-10-02 22:32:46 +02:00
Trevor Gross
e9b0eeb99d intrinsics: Rename abort to abort_immediate
The semantics of `intrinsics::abort()` are closer to what we have
unstably as `abort_immediate()` than to `process::abort()` or
`libc::abort()`. Rename it to make more clear that the intrinsic is more
of an intentional crash with platform-specific behavior than what
`libc::abort()` tries to be (i.e. raising `SIGABRT`).
2026-10-02 18:56:41 +00:00
Jonathan Brouwer
3951fd6816 Rollup merge of #163603 - yara-blue:reflection-reorder, r=oli-obk
Reorganise reflection intrinsics

Trivial refactor moving some things around.

We got a fair amount of intrinsics for reflection now with more on the way. At this point it's worth it to reorganize things a little. This prefixes them with `type_id_` (`TypeId` is the entry point for _nearly_ all of reflection) and moves their declaration into its own module (`core::intrinsics::reflection`).

Possible contentious is the move of the `type_id` intrinsic which has existed for a while and was previously at `core::intrinsics::type_id`. It is still unstable and as far as I am aware intrinsics should really not be relied upon by users.

I've decided to leave the `field_representing_field` (name, offset, actual_type_of) where they are since those where not created for reflection and will be changed in the future (see: https://github.com/rust-lang/rust/issues/162127).

r? oli-obk
2026-10-02 16:08:13 +02:00
Jacob Pratt
d08006516a Rollup merge of #163621 - tgross35:const-abort-immediate, r=RalfJung,bushrat011899
core: Unstably constify `abort_immediate`

For const-only code there isn't much of a reason to use this over `panic!()`, but having `abort_immediate` const will make it possible to reuse more code meant for runtime at comptime. The semantics are well-defined so this is pretty straightforward.

Tracking issue: https://github.com/rust-lang/rust/issues/154601
2026-10-02 01:07:13 -04:00
Trevor Gross
b923d1e13a ctfe: Constify the abort intrinsic
This is a well-defined operation that we want to make use of in
std/core, such as with `abort_immediate`.
2026-10-01 14:47:03 -05:00
Mark Rousskov
4c11abbbd2 Step cfg(bootstrap) 2026-09-29 22:18:54 +00:00
Yara
6cc4b6f5b0 reflection: prefix reflection intrinsics with type_id 2026-09-29 17:09:19 +02:00
Jonathan Brouwer
d20a388a88 Rollup merge of #163378 - RalfJung:is_some_and_none_or, r=mejrs
use is_some_and / is_none_or in a few more places

IMO that makes the code more readable.

Clippy also lints this by default these days, but we don't run that lint on the compiler it seems.
2026-09-27 18:58:14 +02:00
Ralf Jung
3b2363d3ce use is_some_and / is_none_or in a few more places 2026-09-26 17:09:13 +02:00
tye-exe
8d8674117b Update expect messages in rust_const_eval
* Update expect messages

In rustc_const_eval/src/interpret/eval_context.rs
* Simplify exception messages
2026-09-26 08:26:50 +00:00
mejrs
693bf504c7 Update deprecated rustc_hir imports 2026-09-23 14:27:49 +02:00
James Barford-Evans
af2f1f375c use ConstExt for methods that do not yet exist in rustc_type_ir 2026-09-22 13:04:44 +01:00
Nicholas Nethercote
30b8dfc353 Remove G generic param from Diag<'_, G>
It encodes the `emit` behaviour, one of:
- `BugAbort`: Abort as a bug.
- `FatalAbort`: Abort as a fatal error.
- `ErrorGuaranteed`: Return an `ErrorGuaranteed` (the default).
- `()`: return `()`.

This is useful but `Diag` is very widely used and it's arguably not
useful enough to be worth the generic parameter. This commit removes it.

Benefits:
- Many fewer generic parameters, including many functions where the
  genericity is entirely uninteresting. This includes every
  `Diagnostic::into_diag` and `Subdiagnostic::add_to_diag`. Removes the
  need for the comment about `<G>` on `trait Diagnostic`.
- No `PhantomData` in `Diag`.
- Makes bootstrapping a bit faster.

The downside is there is no longer a single `emit` method.
- Getting a `!` return type requires calling `emit_bug` or `emit_fatal`.
  This only affects a few call sites.
- Getting an `ErrorGuaranteed` return type requires calling `emit_err`.
  This affects a lot of call sites. (It arguably makes call sites more
  self-documenting.)
- Using the wrong `emit_*` on a diagnostic causes a runtime abort, which
  previously couldn't occur. Seems unlikely, but it's not impossible.
- Note: If no particular return type is needed, `emit` can be used for
  any diagnostic. (Bug/fatal diagnostics will still trigger abort.)
2026-09-21 09:57:42 +10:00
Jonathan Brouwer
a6a54687e5 Rollup merge of #161873 - mejrs:bug, r=tiif
move bug and span_bug macros to rustc_span

This allows them to be used without depending on rustc_middle.

This is done by using a rustc_interface callback so that, if the callback is set, a internal compiler error diagnostic is printed through that. After that the panic is initiated.

r? @jdonszelmann @bjorn3
2026-09-15 23:26:55 +02:00
mejrs
6aaabbb863 compiler: fix bug and span_bug imports 2026-09-15 16:20:18 +02:00
cclfmht
2cfd6c5a7d Update docs for intern_const_alloc_for_constprop 2026-09-15 21:35:07 +08:00
cclfmht
e98eee9156 GVN: Fix the check on provenance before interning
We only checked the provenance for a part of the allocation that will be
interned. Fixed by adding a method under `InterpCx` to check the whole
allocation.
2026-09-15 21:30:25 +08:00
Jonathan Brouwer
727e08088f Rollup merge of #162409 - RalfJung:intrinsic-const-stab, r=oli-obk
Fix gap in const stability checks around intrinsics

@N1ark managed to find a gap in our const stability checks around intrinsics. This PR fixes that gap.

Sadly the standard library already relies on the gap, so for now I added a `rustc_allow_const_fn_unstable` but that attribute usually needs some process to be approved.

Also fixes https://github.com/rust-lang/rust/issues/150961 by properly supporting & testing `rustc_do_not_const_check` on intrinsics.
2026-09-14 19:23:26 +02:00
Jonathan Brouwer
305d36bc80 Rollup merge of #162630 - nnethercote:simplify-Diag-G, r=oli-obk
Simplify the `G` in `Diag<'a, G>`

The `EmissionGuarantee` trait isn't necessary, and just complicates things. Details in individual commits.

r? @oli-obk
2026-09-14 15:16:02 +02:00
Nicholas Nethercote
09bf6de39e Remove EmissionGuarantee
It's a trait that is used to give `Diag::emit` different return types
depending on the `G` in `Diag<'_, G>`. It works, but it's overkill.
There are only four different `G` types in practice (`BugAbort`,
`FatalAbort`, `ErrorGuaranteed`, and `()`) and having inherent `emit`
methods for each of those four concrete `Diag<'_, G>` types is good
enough.

This commit makes that change. This removes `EmissionGuarantee`
trait bounds from many places, which is nice.
2026-09-12 11:21:03 +10:00
khyperia
06e076ee7e yeet braces from DefKind::Const 2026-09-11 17:08:12 +02:00
Jonathan Brouwer
8b9c125b70 Rollup merge of #161734 - RalfJung:c-variadic-types, r=oli-obk
miri: enforce proper types for c-variadic arguments in shims

This adds proper type checks for c-variadic argument handling in Miri shims. So far we would have ICEd for many type mismatches since the innards of the interpreter generally assume that things are well-typed. The checks we are using are the same as for [`next_arg`](https://doc.rust-lang.org/nightly/std/ffi/struct.VaList.html#method.next_arg).

This uncovered some interesting points:
-  We should accept `&mut` as equivalent to `*mut`. We don't allow `&mut` as a type in `next_arg` but we do allow it for c-variadic calls, so this change also affects a bit more code in const-eval (if the caller passes an `&mut` and the callee expects a `*mut`). Even CFI is okay with treating `&mut` and `*mut` as equivalent so this should be fine. Cc @folkertdev
- Some places in the standard library futex handling used types for their variadic arguments that are not quite correct according to these rules. I fixed those. Cc @m-ou-se
- One variadic function takes pointers to `libc::timespec`. A program with a libc dependency has two copies of libc (one in the sysroot, and the normal dependency). When Miri looks up the expected argument type, it picks one of them, leading to Miri seeing a type mismatch when there is a call using the other copy. C generally considers two copies of the same type to be identical, so I implemented logic that does the same: two `repr(C)` types are "identical" if the names of the types, and the names and types of all fields, are identical. I then also used that logic for the normal ABI checks, where it will also help since we had similar trouble there in the past (that we had to find other work-arounds for).
2026-09-09 15:01:28 +02:00
Ralf Jung
4f967c1c1a avoid suggesting adding an attribute that's already there 2026-09-08 09:43:46 +02:00
Ralf Jung
472fc3bc80 fallback body of indirectly-stable intrinsics needs to be const-stability-checked 2026-09-08 09:43:46 +02:00
Yara
ed8f8b6025 reflection: replace TypeKind::Array field with methods 2026-09-07 21:23:19 +02:00
Yara
2edd31488a reflection: replace TypeKind::Slice's field with TypeId::element_ty 2026-09-07 20:58:18 +02:00
Jonathan Brouwer
706214d854 Rollup merge of #162294 - yara-blue:reflection-refactor-ptrs, r=oli-obk
Reflection refactor ptrs

Tracking issue rust-lang/rust#146922

Part of the [Refactoring to many methods](https://rust-lang.zulipchat.com/#narrow/channel/572285-goals.2Freflection/topic/Refactoring.20to.20many.20methods/with/592226560) reflection subgoal. See that for the full context. In short for various reasons we are moving from an enum `TypeKind` where the variants hold the types information to one that just tells you the type kind. Separate methods on `TypeId` provide a way to get to the data that used to be in the variant.

Since function pointers have a lot of fields it felt better to keep the `FnPtr` struct we have now then add an intrinsic for each field.

r? @oli-obk
2026-09-07 17:08:09 +02:00
bors
f207aa3913 Auto merge of #162333 - Zalathar:rollup-DdpfsFl, r=Zalathar
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#162324 (miri subtree update)
 - rust-lang/rust#162170 (bootstrap: use target's LLVM libdir when cross-compiling)
 - rust-lang/rust#158312 (Adds support for AArch64 SVE to inline assembly)
 - rust-lang/rust#159792 (A more readable debug map for IndexMaps)
 - rust-lang/rust#160745 (make closures act like MaybeDangling)
 - rust-lang/rust#161263 (break rustc_expand-rustc_middle dependency)
 - rust-lang/rust#161895 (std::sys::pal::sgx: fix mismatched alloc/free alignment)
 - rust-lang/rust#161940 (Promote `wasm32-wasip3` to a tier 2 target)
 - rust-lang/rust#161397 (coverage: Tidy tests and add some new ones)
 - rust-lang/rust#161616 (Report precondition violation for `<usize as SliceIndex>::get_unchecked` in const-eval)
 - rust-lang/rust#162248 (Add regression test for unsized const parameter default ICE)
 - rust-lang/rust#162250 (Fix hashing of span end columns in incremental compilation)
 - rust-lang/rust#162265 (cargotest: add lockfiles)
 - rust-lang/rust#162318 (bootstrap: Fix broken path for `./x doc compiler/rustc --open`)
2026-09-05 17:04:57 +00:00
Yara
06fa642f23 reflection: remove field from TypeKind::FnPtr 2026-09-04 19:28:09 +02:00
Yara
98d68aa8ce reflection: adds TypeId::function_ptr returning FnPtr 2026-09-04 19:27:24 +02:00
Yara
f4cdf28df5 reflection: remove field from TypeKind::Reference 2026-09-04 19:26:30 +02:00
Yara
e46de86eee reflection: make points_to and points_mutably support references 2026-09-04 19:26:30 +02:00
Yara
9c36788af1 reflection: remove field from TypeKind::Pointer variant 2026-09-04 19:26:30 +02:00
Yara
f123df5b07 reflection: adds TypeId::points_to and TypeId::is_mutable_pointer 2026-09-04 19:26:30 +02:00
Ralf Jung
e7c3734a6a make closure-like types act like MaybeDangling 2026-09-04 16:35:10 +02:00
khyperia
b61efecae3 type system const items via direct rhs 2026-09-04 08:01:45 +02:00
Ralf Jung
158f6f9da4 share identical-c-type logic with regular ABI checks 2026-09-03 14:17:36 +02:00
Ralf Jung
51dfc2b349 miri: enforce proper types for c-variadic arguments in shims 2026-09-03 14:10:40 +02:00
Jonathan Brouwer
8e3d555214 Rollup merge of #159103 - aapoalas:reborrow/fix-borrowed-place, r=oli-obk
fix(reborrow): recursive implementation

If Reborrow finds '&'a mut T' fields where 'a is the Reborrowed type's first lifetime parameter (currently the only lifetime that is allowed to reborrow) then it inserts a Deref and borrow of the T, and likewise if it finds a 'T: Reborrow' field then the field type is recursed into.

This makes Reborrow always produce the correct borrow checking logic at the cost of most probably being inconsiderately expensive. The thinking is that performance will be a followup consideration.

r? @oli-obk
2026-08-28 10:15:37 +02:00