From 56e17cb31996979b26bb2f25164dfe00365f8aa1 Mon Sep 17 00:00:00 2001 From: sjwang05 <63834813+sjwang05@users.noreply.github.com> Date: Sun, 9 Aug 2026 21:24:13 -0700 Subject: [PATCH 01/12] equate the assumption's trait ref with the goal's directly when considering object bounds --- .../src/solve/assembly/mod.rs | 41 ++++++++++++++- .../src/solve/assembly/structural_traits.rs | 5 +- ...assoc-type-static-lifetime-object-bound.rs | 27 ++++++++++ ...c-type-static-lifetime-object-bound.stderr | 10 ++++ .../next-solver/gat-static-in-trait-object.rs | 24 +++++++++ .../gat-static-in-trait-object.stderr | 51 +++++++++++++++++++ ...supertrait-static-lifetime-object-bound.rs | 20 ++++++++ ...rtrait-static-lifetime-object-bound.stderr | 18 +++++++ 8 files changed, 192 insertions(+), 4 deletions(-) create mode 100644 tests/ui/traits/next-solver/assoc-type-static-lifetime-object-bound.rs create mode 100644 tests/ui/traits/next-solver/assoc-type-static-lifetime-object-bound.stderr create mode 100644 tests/ui/traits/next-solver/gat-static-in-trait-object.rs create mode 100644 tests/ui/traits/next-solver/gat-static-in-trait-object.stderr create mode 100644 tests/ui/traits/next-solver/supertrait-static-lifetime-object-bound.rs create mode 100644 tests/ui/traits/next-solver/supertrait-static-lifetime-object-bound.stderr diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index 040f98de7bcfd..a7a3d5baa50c5 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -85,7 +85,15 @@ where goal: Goal, assumption: I::Clause, ) -> Result, NoSolutionOrRerunNonErased> { - Self::probe_and_match_goal_against_assumption(ecx, source, goal, assumption, |ecx| { + // We inline much of `probe_and_match_goal_against_assumption` and + // `TraitPredicate::match_assumption` here, as we never encounter + // `Sized` or `MetaSized` goals here, and we need to equate `goal` + // and `assumption`'s trait refs directly inside this function in + // order to prevent unsoundness (see below). + + Self::fast_reject_assumption(ecx, goal, assumption)?; + + ecx.probe_trait_candidate(source).enter(|ecx| { let cx = ecx.cx(); let ty::Dynamic(bounds, _) = goal.predicate.self_ty().kind() else { panic!("expected object type in `probe_and_consider_object_bound_candidate`"); @@ -106,6 +114,37 @@ where } }); + // If we need to prove `dyn for<'x> Trait<'x> + '?temp: Trait<'static>` with + // + // ```rs + // trait Trait<'a>: 'a {} + // ``` + // + // we have the goal's trait ref as `Trait<'static>` and a theoretical impl + // resembling: + // + // ```rs + // impl<'s, 'hr> Trait<'hr> for dyn for<'x> Trait<'x> + 's + // where + // dyn for<'a> Trait<'a> + 's: 'hr + // {} + // ``` + // + // where 'hr is our bound var. The where-clause elaborates to `'s: 'hr`; + // in this case we have 's := '?temp. Instantiating the binder gives us + // 'hr := '?infer, and our goal has 'hr := 'static, so we need to equate + // the instantiated trait ref to the goal in order to get '?infer := 'static, + // since what we want is the constraint `'?temp: 'static`. + // + // If we instead passed the binder to predicates_for_object_candidate and let + // it instantiate the binder itself, we would lose '?infer := 'static, since + // predicates_for_object_candidate has no way of equating the trait ref with + // the goal. We would simply have 'hr := '?infer, giving us the constraint + // `?temp: '?infer`, which is satisfiable for any lifetime, leading to + // unsoundness: trait-system-refactor-initiative#295. + let trait_ref = ecx.instantiate_binder_with_infer(trait_ref); + ecx.eq(goal.param_env, goal.predicate.trait_ref(cx), trait_ref)?; + match structural_traits::predicates_for_object_candidate( ecx, goal.param_env, diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index ae78d68865de3..63938c8c60f64 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -8,7 +8,7 @@ use rustc_type_ir::lang_items::{SolverProjectionLangItem, SolverTraitLangItem}; use rustc_type_ir::solve::SizedTraitKind; use rustc_type_ir::solve::inspect::ProbeKind; use rustc_type_ir::{ - self as ty, Binder, FallibleTypeFolder, Interner, Movability, Mutability, Region, TypeFoldable, + self as ty, FallibleTypeFolder, Interner, Movability, Mutability, Region, TypeFoldable, TypeSuperFoldable, Unnormalized, Upcast as _, elaborate, }; use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic}; @@ -889,7 +889,7 @@ pub(in crate::solve) fn const_conditions_for_destruct( pub(in crate::solve) fn predicates_for_object_candidate( ecx: &mut EvalCtxt<'_, D>, param_env: I::ParamEnv, - trait_ref: Binder>, + trait_ref: ty::TraitRef, object_bounds: I::BoundExistentialPredicates, ) -> Result>, Ambiguous> where @@ -897,7 +897,6 @@ where I: Interner, { let cx = ecx.cx(); - let trait_ref = ecx.instantiate_binder_with_infer(trait_ref); let mut requirements = vec![]; // Elaborating all supertrait outlives obligations here is not soundness critical, // since if we just used the unelaborated set, then the transitive supertraits would diff --git a/tests/ui/traits/next-solver/assoc-type-static-lifetime-object-bound.rs b/tests/ui/traits/next-solver/assoc-type-static-lifetime-object-bound.rs new file mode 100644 index 0000000000000..f5ca8c10636a5 --- /dev/null +++ b/tests/ui/traits/next-solver/assoc-type-static-lifetime-object-bound.rs @@ -0,0 +1,27 @@ +//! regression test for https://github.com/rust-lang/trait-system-refactor-initiative/issues/295 + +//@ compile-flags: -Znext-solver + +#![forbid(unsafe_code)] + +trait Tr<'a> { + type A: 'a; +} + +fn f>(a: >::A) -> Box { + Box::new(a) +} + +fn launder<'b>(r: &'b u8) -> &'static u8 { + *f:: Tr<'a, A = &'b u8>>(r).downcast_ref::<&'static u8>().unwrap() + //~^ ERROR lifetime may not live long enough +} + +fn main() { + let p; + { + let x = Box::new(42u8); + p = launder(&x); + } + println!("{}", *p); +} diff --git a/tests/ui/traits/next-solver/assoc-type-static-lifetime-object-bound.stderr b/tests/ui/traits/next-solver/assoc-type-static-lifetime-object-bound.stderr new file mode 100644 index 0000000000000..009091845f85d --- /dev/null +++ b/tests/ui/traits/next-solver/assoc-type-static-lifetime-object-bound.stderr @@ -0,0 +1,10 @@ +error: lifetime may not live long enough + --> $DIR/assoc-type-static-lifetime-object-bound.rs:16:6 + | +LL | fn launder<'b>(r: &'b u8) -> &'static u8 { + | -- lifetime `'b` defined here +LL | *f:: Tr<'a, A = &'b u8>>(r).downcast_ref::<&'static u8>().unwrap() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static` + +error: aborting due to 1 previous error + diff --git a/tests/ui/traits/next-solver/gat-static-in-trait-object.rs b/tests/ui/traits/next-solver/gat-static-in-trait-object.rs new file mode 100644 index 0000000000000..80f3838dc08b6 --- /dev/null +++ b/tests/ui/traits/next-solver/gat-static-in-trait-object.rs @@ -0,0 +1,24 @@ +//! regression test from https://github.com/rust-lang/rust/pull/160831/changes#r3852248101 +//! once we allow GATs in object types, we want to make sure this isn't unsound. + +//@ compile-flags: -Znext-solver + +use std::any::Any; + +trait Trait { + type Assoc<'a>: 'a; +} + +fn tr(x: T::Assoc<'static>) -> Box { Box::new(x) } + +fn foo<'s>(x: &'s str) -> Box +where + dyn for<'hr> Trait = &'s str>: Trait = &'s str>, + //~^ ERROR the trait `Trait` is not dyn compatible + //~| ERROR the trait `Trait` is not dyn compatible +{ + tr:: Trait = &'s str>>(x) + //~^ ERROR the trait `Trait` is not dyn compatible +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/gat-static-in-trait-object.stderr b/tests/ui/traits/next-solver/gat-static-in-trait-object.stderr new file mode 100644 index 0000000000000..ed27a81cc0be5 --- /dev/null +++ b/tests/ui/traits/next-solver/gat-static-in-trait-object.stderr @@ -0,0 +1,51 @@ +error[E0038]: the trait `Trait` is not dyn compatible + --> $DIR/gat-static-in-trait-object.rs:16:47 + | +LL | dyn for<'hr> Trait = &'s str>: Trait = &'s str>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Trait` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/gat-static-in-trait-object.rs:9:10 + | +LL | trait Trait { + | ----- this trait is not dyn compatible... +LL | type Assoc<'a>: 'a; + | ^^^^^ ...because it contains generic associated type `Assoc` + = help: consider moving `Assoc` to another trait + +error[E0038]: the trait `Trait` is not dyn compatible + --> $DIR/gat-static-in-trait-object.rs:16:53 + | +LL | dyn for<'hr> Trait = &'s str>: Trait = &'s str>, + | ^^^^^^^^^^^^^^^^^^^^^^^^ `Trait` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/gat-static-in-trait-object.rs:9:10 + | +LL | trait Trait { + | ----- this trait is not dyn compatible... +LL | type Assoc<'a>: 'a; + | ^^^^^ ...because it contains generic associated type `Assoc` + = help: consider moving `Assoc` to another trait + +error[E0038]: the trait `Trait` is not dyn compatible + --> $DIR/gat-static-in-trait-object.rs:20:14 + | +LL | tr:: Trait = &'s str>>(x) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Trait` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/gat-static-in-trait-object.rs:9:10 + | +LL | trait Trait { + | ----- this trait is not dyn compatible... +LL | type Assoc<'a>: 'a; + | ^^^^^ ...because it contains generic associated type `Assoc` + = help: consider moving `Assoc` to another trait + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/traits/next-solver/supertrait-static-lifetime-object-bound.rs b/tests/ui/traits/next-solver/supertrait-static-lifetime-object-bound.rs new file mode 100644 index 0000000000000..b52b1c6cfcbb7 --- /dev/null +++ b/tests/ui/traits/next-solver/supertrait-static-lifetime-object-bound.rs @@ -0,0 +1,20 @@ +//! regression test for https://github.com/rust-lang/trait-system-refactor-initiative/issues/295 + +//@ compile-flags: -Znext-solver + +#![forbid(unsafe_code)] + +trait Trait<'a>: 'a {} + +fn g<'s>(s: &'s String) -> &'static String +where + dyn for<'x> Trait<'x> + 's: Trait<'static>, +{ + s +} + +fn main() { + let r = g(&String::from("freed")); + //~^ ERROR temporary value dropped while borrowed + println!("{r}"); +} diff --git a/tests/ui/traits/next-solver/supertrait-static-lifetime-object-bound.stderr b/tests/ui/traits/next-solver/supertrait-static-lifetime-object-bound.stderr new file mode 100644 index 0000000000000..9463785a7da15 --- /dev/null +++ b/tests/ui/traits/next-solver/supertrait-static-lifetime-object-bound.stderr @@ -0,0 +1,18 @@ +error[E0716]: temporary value dropped while borrowed + --> $DIR/supertrait-static-lifetime-object-bound.rs:17:16 + | +LL | let r = g(&String::from("freed")); + | ---^^^^^^^^^^^^^^^^^^^^^-- temporary value is freed at the end of this statement + | | | + | | creates a temporary value which is freed while still in use + | argument requires that borrow lasts for `'static` + | +note: requirement that the value outlives `'static` introduced here + --> $DIR/supertrait-static-lifetime-object-bound.rs:11:33 + | +LL | dyn for<'x> Trait<'x> + 's: Trait<'static>, + | ^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0716`. From 2c09a80e4fdf2ed01b3c64126b585f1fb542e76a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 8 Sep 2026 13:30:06 +0200 Subject: [PATCH 02/12] Merge commit 'db693f7dbcfab9af2a89b703096f692417e2f756' into sync_cg_clif-2026-09-08 --- .github/workflows/freebsd.yml | 3 - Cargo.lock | 77 +++++++++--------- Cargo.toml | 24 +++--- Readme.md | 3 +- build_system/build_sysroot.rs | 1 - example/mini_core_hello_world.rs | 1 - ...0027-stdlib-128bit-atomic-operations.patch | 81 ++++++------------- rust-toolchain.toml | 2 +- scripts/test_rustc_tests.sh | 3 + src/constant.rs | 44 +--------- src/debuginfo/unwind.rs | 2 +- src/lib.rs | 2 + 12 files changed, 85 insertions(+), 158 deletions(-) diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml index f344113aa7fdf..e0b2bd34631f9 100644 --- a/.github/workflows/freebsd.yml +++ b/.github/workflows/freebsd.yml @@ -34,8 +34,5 @@ jobs: # Disabling incr comp reduces cache size and incr comp doesn't save # as much on CI anyway. export CARGO_BUILD_INCREMENTAL=false - # FIXME(rust-lang/rust#134863) necessary to avoid error when - # dlopening proc macros during compilation of cg_clif. - export LD_STATIC_TLS_EXTRA=4096 # Skip rand as it fails on FreeBSD due to rust-random/rand#1355 ./y.sh test --skip-test test.rust-random/rand diff --git a/Cargo.lock b/Cargo.lock index 88ea75a6b0299..80bbbfe4e9bc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,27 +43,27 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cranelift-assembler-x64" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a25c5b1bb1d86ae68dca1826a1b668b9951056c42e0eef89e35942c7001eb481" +checksum = "a4a59ddc4abd9c5560f4742864b2cd8c19e73c7263f0c866b2c45c2d31587adc" dependencies = [ "cranelift-assembler-x64-meta", ] [[package]] name = "cranelift-assembler-x64-meta" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b052a1fd94b4565697c56f9d358723c7c354feef42a6569081225c1bed6e86" +checksum = "8a8c361cd22fd0fdd8e61af6bfd86ad9c0c62f78b2b1caa2b9e4e97cd8f605fe" dependencies = [ "cranelift-srcgen", ] [[package]] name = "cranelift-bforest" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a599e8ffa6a1a118d2dce4809073ad2f2534b1ae1c6d55697b6b8a324446c971" +checksum = "b86c34ae183cf2410318f899648fe1ef6ab9148486e7b938d7b4d814e61dafc9" dependencies = [ "cranelift-entity", "wasmtime-internal-core", @@ -71,18 +71,18 @@ dependencies = [ [[package]] name = "cranelift-bitset" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e1ae13182fadc731b1387287b4c6d257b9191fbb7c980ebb2d74c2db74b743e" +checksum = "415f1a12668869e16ac3b66a729fb8cce8bbe6e50e68d1fa0142acd0c9c05f0c" dependencies = [ "wasmtime-internal-core", ] [[package]] name = "cranelift-codegen" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce9c62e5e11d12f4a8f5f939f29899f32002d38193b47491e2539705a1d447e" +checksum = "73eecedc85ffca4f34dbe197c6545c8ade6579a61352457936f53c3bffa6353b" dependencies = [ "bumpalo", "cranelift-assembler-x64", @@ -107,9 +107,9 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c29d6b53cfd758dc1a269310fc92199056db03943b9b774b4911cd615e02ad7" +checksum = "66834005198c3e9e3d89cd69cf1541419402ab75250afbeaa3128db6d5254025" dependencies = [ "cranelift-assembler-x64-meta", "cranelift-codegen-shared", @@ -119,24 +119,24 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd8cfe23f3349bfa62e06a450cd94cf5f84fbe78556f4df3276534c4b93d834" +checksum = "7e6efaf74077091a2ff41317cc8eb2779264dae4b8a16d955835f3fcda338f52" [[package]] name = "cranelift-control" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f991b4712f21d9502758f7e6cb11746ca2e6186b06c42995eaf31b1e50a9c498" +checksum = "a4258d4ed6ad4e698fe1fec4277b1fcbea6f2a17cb5ec3f04bddfb38ca83d93e" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e24f9c233a43730e22cf42ab0c03f41265e147eca97b3362be01e0da359d7a5" +checksum = "4f016b6f87b1a46a3f5df59b82d88bb352bf2fa6d7868875dfc4d6b65de5242d" dependencies = [ "cranelift-bitset", "wasmtime-internal-core", @@ -144,9 +144,9 @@ dependencies = [ [[package]] name = "cranelift-frontend" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61325401051d35ddbf8e2b5d5b5dec8dd54688c9054046b62e76146e61c88a99" +checksum = "b16f2b149dae6ea3886bee931445196d86d8e71b66f7c3b21abe434f77189be8" dependencies = [ "cranelift-codegen", "hashbrown 0.17.0", @@ -157,15 +157,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f71d642812aa70284750719efbd2cc5ad7e7c5e6c43c026b5b0686ce8a6052" +checksum = "f00258ff3d37f52ed731df679205e66175c728846dbde186ee20e93973d12ee7" [[package]] name = "cranelift-jit" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92a0f9300c8a5738553a440fe4f25b85f574d5c41b946880dabd47c809f87997" +checksum = "fa063cc98af51fb9090cd40b674503e21bdfa705d2bff75ebf98b79ffc0f598d" dependencies = [ "anyhow", "cranelift-codegen", @@ -184,9 +184,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f723983af35e690c4e2fc160df5d8895bb4a419a54d693367163d781bd830cc" +checksum = "bff0025f1ff6a0470cbd2a61b125f8501311ea9e6c46ed5bb2110ee6710c6a76" dependencies = [ "anyhow", "cranelift-codegen", @@ -195,9 +195,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5c50cffac70c30cc5d0b1d8d287e7712dc76b1181c43697de63d27f38236ddd" +checksum = "4f31eb7e08f31e5bc9c167c35718b0325efa3d4e234e2e9342316e01b18a4b51" dependencies = [ "cranelift-codegen", "libc", @@ -206,9 +206,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "430e18f4886ba98f6a7dbb82c86df19f28f27cac417611e5dcc427a7a8decac9" +checksum = "7ca0d86955529d5b9041c4c07745f6ffa42c32326e9f467a834e2b7bd9a9d156" dependencies = [ "anyhow", "cranelift-codegen", @@ -221,9 +221,9 @@ dependencies = [ [[package]] name = "cranelift-srcgen" -version = "0.134.0" +version = "0.135.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5972dc0a5df7ba6f11e8e1654287c40ea1704ca6ce3b76ef54fa58445ee4ad" +checksum = "2e0b67d313f510520f40c1496c3446af0d6b30219d1ba9a4c09c77ec288a561b" [[package]] name = "crc32fast" @@ -379,9 +379,9 @@ dependencies = [ [[package]] name = "regalloc2" -version = "0.15.1" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de2c52737737f8609e94f975dee22854a2d5c125772d4b1cf292120f4d45c186" +checksum = "757712e8e61590d6d4f5d563483755538b5aa13467837a3b41cd9832509a7f85" dependencies = [ "allocator-api2", "bumpalo", @@ -493,9 +493,9 @@ checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "wasmtime-internal-core" -version = "47.0.0" +version = "48.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852f3326264aea590131a422e3ecb33fae3b6695fd67e2e202e2799cd8d27629" +checksum = "2c01c81d781512e17b38c3a76ca9aa2564bc3f9fd8ff6ffc77ba3e1c290d488a" dependencies = [ "hashbrown 0.17.0", "libm", @@ -503,11 +503,10 @@ dependencies = [ [[package]] name = "wasmtime-internal-jit-icache-coherence" -version = "47.0.0" +version = "48.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e537f59b5ab127ca2d421ecbd8728d70bd6cdc9891cec193fb1f594c3309836c" +checksum = "2a09abde04346919af1136a28f344e200685509e28815aef4c39dc08977cc1d8" dependencies = [ - "cfg-if", "libc", "wasmtime-internal-core", "windows-sys 0.61.2", diff --git a/Cargo.toml b/Cargo.toml index cb595332bac61..ca03be20cd100 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.134.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } -cranelift-frontend = { version = "0.134.0" } -cranelift-module = { version = "0.134.0" } -cranelift-native = { version = "0.134.0" } -cranelift-jit = { version = "0.134.0", optional = true } -cranelift-object = { version = "0.134.0", default-features = false } +cranelift-codegen = { version = "0.135.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } +cranelift-frontend = { version = "0.135.0" } +cranelift-module = { version = "0.135.0" } +cranelift-native = { version = "0.135.0" } +cranelift-jit = { version = "0.135.0", optional = true } +cranelift-object = { version = "0.135.0", default-features = false } target-lexicon = "0.13" gimli = { version = "0.33", default-features = false, features = ["write"] } object = { version = "0.39.1", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } @@ -24,12 +24,12 @@ smallvec = "1.8.1" # Uncomment to use an unreleased version of cranelift #[patch.crates-io] -#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-47.0.0" } -#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-47.0.0" } -#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-47.0.0" } -#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-47.0.0" } -#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-47.0.0" } -#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-47.0.0" } +#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-48.0.0" } +#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-48.0.0" } +#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-48.0.0" } +#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-48.0.0" } +#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-48.0.0" } +#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-48.0.0" } # Uncomment to use local checkout of cranelift #cranelift-codegen = { path = "../wasmtime/cranelift/codegen" } diff --git a/Readme.md b/Readme.md index c5436cf67c80a..48003ad270e6f 100644 --- a/Readme.md +++ b/Readme.md @@ -66,7 +66,7 @@ For more docs on how to build and test see [build_system/usage.txt](build_system |OS \ architecture|x86\_64|AArch64|Riscv64|s390x (System-Z)| |---|---|---|---|---| |Linux|✅|✅|✅[^no-rustup]|✅[^no-rustup]| -|FreeBSD|✅[^no-rustup][^tls]|❓|❓|❓| +|FreeBSD|✅[^no-rustup]|❓|❓|❓| |AIX|❌[^xcoff]|N/A|N/A|❌[^xcoff]| |Other unixes|❓|❓|❓|❓| |macOS|✅|✅|N/A|N/A| @@ -80,7 +80,6 @@ Not all targets are available as rustup component for nightly. See notes in the [^xcoff]: XCOFF object file format is not supported. [^no-rustup]: Not available as [rustup component for nightly](https://rust-lang.github.io/rustup-components-history/). You can build it yourself. -[^tls]: FreeBSD requires setting `LD_STATIC_TLS_EXTRA=4096` to build cg_clif. In addition you need at least FreeBSD 14. ## Usage diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 71c0523615ff1..3ac7724f8f318 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -252,7 +252,6 @@ fn build_clif_sysroot_for_target( build_cmd.arg("--features").arg("backtrace panic-unwind"); build_cmd.arg(format!("-Zroot-dir={}", STDLIB_SRC.to_path(dirs).display())); build_cmd.arg("-Zembed-metadata=no"); - build_cmd.arg("-Zbuild-dir-new-layout"); build_cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "true"); build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); if compiler.target.contains("apple") { diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 5e986201b385c..9a710caae9cd1 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -1,7 +1,6 @@ #![feature( no_core, lang_items, - never_type, extern_types, thread_local, repr_simd, diff --git a/patches/0027-stdlib-128bit-atomic-operations.patch b/patches/0027-stdlib-128bit-atomic-operations.patch index 2268ff9cb266e..f821099e68f88 100644 --- a/patches/0027-stdlib-128bit-atomic-operations.patch +++ b/patches/0027-stdlib-128bit-atomic-operations.patch @@ -5,83 +5,54 @@ Subject: [PATCH] Disable 128bit atomic operations Cranelift doesn't support them yet --- - library/core/src/panic/unwind_safe.rs | 6 ----- - library/core/src/sync/atomic.rs | 38 --------------------------- - 2 files changed, 44 deletions(-) + library/core/src/panic/unwind_safe.rs | 4 ++-- + library/core/src/sync/atomic.rs | 4 ++-- + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/panic/unwind_safe.rs b/library/core/src/panic/unwind_safe.rs -index a60f0799c0e..af056fbf41f 100644 +index bf2e61d..cb82b07 100644 --- a/library/core/src/panic/unwind_safe.rs +++ b/library/core/src/panic/unwind_safe.rs -@@ -216,9 +216,6 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicI32 {} +@@ -217,7 +217,7 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicI32 {} #[cfg(target_has_atomic_load_store = "64")] #[stable(feature = "integer_atomics_stable", since = "1.34.0")] impl RefUnwindSafe for crate::sync::atomic::AtomicI64 {} -#[cfg(target_has_atomic_load_store = "128")] --#[unstable(feature = "integer_atomics", issue = "99069")] --impl RefUnwindSafe for crate::sync::atomic::AtomicI128 {} ++#[cfg(false)] + #[unstable(feature = "integer_atomics", issue = "99069")] + impl RefUnwindSafe for crate::sync::atomic::AtomicI128 {} - #[cfg(target_has_atomic_load_store = "ptr")] - #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] -@@ -235,9 +232,6 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicU32 {} +@@ -236,7 +236,7 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicU32 {} #[cfg(target_has_atomic_load_store = "64")] #[stable(feature = "integer_atomics_stable", since = "1.34.0")] impl RefUnwindSafe for crate::sync::atomic::AtomicU64 {} -#[cfg(target_has_atomic_load_store = "128")] --#[unstable(feature = "integer_atomics", issue = "99069")] --impl RefUnwindSafe for crate::sync::atomic::AtomicU128 {} ++#[cfg(false)] + #[unstable(feature = "integer_atomics", issue = "99069")] + impl RefUnwindSafe for crate::sync::atomic::AtomicU128 {} - #[cfg(target_has_atomic_load_store = "8")] - #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs -index 8a9a0b5..92ed9a6 100644 +index e676a38..b6a9a3c 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs -@@ -3762,44 +3757,6 @@ atomic_int! { +@@ -3850,7 +3850,7 @@ atomic_int! { 8, u64 AtomicU64 } -#[cfg(any(target_has_atomic_load_store = "128", doc))] --atomic_int! { -- target_has_atomic_load_store = "128", -- target_has_atomic = "128", -- target_has_atomic_primitive_alignment = "128", -- unstable(feature = "integer_atomics", issue = "99069"), -- unstable(feature = "integer_atomics", issue = "99069"), -- unstable(feature = "integer_atomics", issue = "99069"), -- unstable(feature = "integer_atomics", issue = "99069"), -- unstable(feature = "integer_atomics", issue = "99069"), -- unstable(feature = "integer_atomics", issue = "99069"), -- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), -- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), -- "i128", -- "#![feature(integer_atomics)]\n\n", -- atomic_min, atomic_max, -- 16, -- i128 AtomicI128 --} ++#[cfg(false)] + atomic_int! { + target_has_atomic_load_store = "128", + target_has_atomic = "128", +@@ -3869,7 +3869,7 @@ atomic_int! { + 16, + i128 AtomicI128 + } -#[cfg(any(target_has_atomic_load_store = "128", doc))] --atomic_int! { -- target_has_atomic_load_store = "128", -- target_has_atomic = "128", -- target_has_atomic_primitive_alignment = "128", -- unstable(feature = "integer_atomics", issue = "99069"), -- unstable(feature = "integer_atomics", issue = "99069"), -- unstable(feature = "integer_atomics", issue = "99069"), -- unstable(feature = "integer_atomics", issue = "99069"), -- unstable(feature = "integer_atomics", issue = "99069"), -- unstable(feature = "integer_atomics", issue = "99069"), -- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), -- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), -- "u128", -- "#![feature(integer_atomics)]\n\n", -- atomic_umin, atomic_umax, -- 16, -- u128 AtomicU128 --} - - #[cfg(target_has_atomic_load_store = "ptr")] - macro_rules! atomic_int_ptr_sized { ++#[cfg(false)] + atomic_int! { + target_has_atomic_load_store = "128", + target_has_atomic = "128", -- 2.48.1 diff --git a/rust-toolchain.toml b/rust-toolchain.toml index ea4ff67c93c89..bc8bfacba1923 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2026-08-19" +channel = "nightly-2026-09-08" components = ["rust-src", "rustc-dev", "llvm-tools", "rustfmt"] profile = "minimal" diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 3885561e94a1e..5a1374fe56e09 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -138,6 +138,7 @@ rm -r tests/run-make/panic-impl-transitive rm tests/ui/debuginfo/debuginfo-emit-llvm-ir-and-split-debuginfo.rs rm tests/ui/statics/issue-91050-1.rs rm tests/ui/statics/issue-91050-2.rs +rm -r tests/run-make/locate-panic-runtime # giving different but possibly correct results # ============================================= @@ -157,6 +158,7 @@ rm -r tests/run-make/strip # same rm -r tests/run-make-cargo/compiler-builtins # Expects lib/rustlib/src/rust to contains the standard library source rm -r tests/run-make-cargo/panic-immediate-abort-works # same rm -r tests/run-make-cargo/panic-immediate-abort-codegen # same +rm -r tests/run-make-cargo/panic-strategies # same rm -r tests/run-make/missing-unstable-trait-bound # This disables support for unstable features, but running cg_clif needs some unstable features rm -r tests/run-make/const-trait-stable-toolchain # same rm -r tests/run-make/print-request-help-stable-unstable # same @@ -174,6 +176,7 @@ rm tests/ui/process/println-with-broken-pipe.rs # same rm -r tests/run-make/extern-fn-explicit-align # argument alignment not yet supported rm -r tests/run-make/panic-abort-eh_frame # .eh_frame emitted with panic=abort rm -r tests/run-make/used-proc-macro # doesn't work on arm64 for some reason +rm tests/ui/async-await/async-drop/async-drop-async-gen-return-pending.rs # rustc side fnsig issue # bugs in the test suite # ====================== diff --git a/src/constant.rs b/src/constant.rs index b1cb5f30cbdfe..e2b0035361733 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -415,49 +415,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant data.set_align(alloc.align.bytes()); if let Some(section_name) = section_name { - let (segment_name, section_name) = if tcx.sess.target.is_like_darwin { - // See https://github.com/llvm/llvm-project/blob/main/llvm/lib/MC/MCSectionMachO.cpp - let mut parts = section_name.as_str().split(','); - let Some(segment_name) = parts.next() else { - tcx.dcx().fatal(format!( - "#[link_section = \"{}\"] is not valid for macos target: must be segment and section separated by comma", - section_name - )); - }; - let Some(section_name) = parts.next() else { - tcx.dcx().fatal(format!( - "#[link_section = \"{}\"] is not valid for macos target: must be segment and section separated by comma", - section_name - )); - }; - if section_name.len() > 16 { - tcx.dcx().fatal(format!( - "#[link_section = \"{}\"] is not valid for macos target: section name bigger than 16 bytes", - section_name - )); - } - let section_type = parts.next().unwrap_or("regular"); - if section_type != "regular" && section_type != "cstring_literals" { - tcx.dcx().fatal(format!( - "#[link_section = \"{}\"] is not supported: unsupported section type {}", - section_name, section_type, - )); - } - let _attrs = parts.next(); - if parts.next().is_some() { - tcx.dcx().fatal(format!( - "#[link_section = \"{}\"] is not valid for macos target: too many components", - section_name - )); - } - // FIXME(bytecodealliance/wasmtime#8901) set S_CSTRING_LITERALS section type when - // cstring_literals is specified - (segment_name, section_name) - } else { - ("", section_name.as_str()) - }; - // FIXME pass correct section flags on Mach-O - data.set_segment_section(segment_name, section_name, 0); + data.set_custom_section(section_name.as_str()); } let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec(); diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index 4b0260a8abc74..ad0a15bf7f6e5 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -204,7 +204,7 @@ impl UnwindContext { let mut data = DataDescription::new(); data.define(gcc_except_table.writer.into_vec().into_boxed_slice()); - data.set_segment_section("", ".gcc_except_table", 0); + data.set_custom_section(".gcc_except_table"); for reloc in &gcc_except_table.relocs { match reloc.name { diff --git a/src/lib.rs b/src/lib.rs index 71fce9e28f120..6d2a353745235 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,8 @@ extern crate rustc_index; extern crate rustc_log; extern crate rustc_session; extern crate rustc_span; +#[cfg(feature = "jit")] +extern crate rustc_structures; extern crate rustc_symbol_mangling; extern crate rustc_target; From 26800a4dda0c2cefea63d656bafcc4084e7ee532 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 9 Sep 2026 12:47:02 +0200 Subject: [PATCH 03/12] Pass -Zforce-unstable-if-unmarked to cg_clif tests This makes their test environment consistent between runs inside the cg_clif and rust repos. --- build_system/tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build_system/tests.rs b/build_system/tests.rs index c7b61f519d247..5ae76dc1e591e 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -478,6 +478,8 @@ impl<'a> TestRunner<'a> { cmd.arg("--check-cfg=cfg(jit)"); cmd.arg("--check-cfg=cfg(target_has_reliable_f128)"); cmd.arg("--edition=2024"); + // implicitly passed when building inside the rust repo + cmd.arg("-Zforce-unstable-if-unmarked"); cmd.args(args); cmd } From 54b751d55a2e2748171c0ba761ae9006552cbe88 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 17 Aug 2026 17:15:59 +0200 Subject: [PATCH 04/12] Remove emit_almost_fatal A fatal error that doesn't actually abort is indistinguishable from a regular error. And the only places where emit_almost_fatal is called, the produced FatalError is ignored. --- compiler/rustc_codegen_llvm/src/intrinsic.rs | 10 ++--- compiler/rustc_errors/src/diagnostic.rs | 7 --- compiler/rustc_errors/src/lib.rs | 46 +++++++------------- 3 files changed, 20 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 1844a8e5c0bca..743145a0e5baf 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -231,11 +231,11 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { } sym::offload => { if tcx.sess.opts.unstable_opts.offload.is_empty() { - let _ = tcx.dcx().emit_almost_fatal(OffloadWithoutEnable); + let _ = tcx.dcx().emit_err(OffloadWithoutEnable); } if tcx.sess.lto() != rustc_session::config::Lto::Fat { - let _ = tcx.dcx().emit_almost_fatal(OffloadWithoutFatLTO); + let _ = tcx.dcx().emit_err(OffloadWithoutFatLTO); } codegen_offload(self, tcx, instance, args); @@ -1752,18 +1752,18 @@ fn codegen_autodiff<'ll, 'tcx>( ) -> IntrinsicResult<'tcx, &'ll Value> { let tcx = bx.tcx; if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) { - let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutEnable); + let _ = tcx.dcx().emit_err(AutoDiffWithoutEnable); } let ct = tcx.crate_types(); let lto = tcx.sess.lto(); if ct.len() == 1 && ct.contains(&CrateType::Executable) { if lto != rustc_session::config::Lto::Fat { - let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutLto); + let _ = tcx.dcx().emit_err(AutoDiffWithoutLto); } } else { if lto != rustc_session::config::Lto::Fat && !tcx.sess.opts.cg.linker_plugin_lto.enabled() { - let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutLto); + let _ = tcx.dcx().emit_err(AutoDiffWithoutLto); } } diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index d1dc3ab6e9525..caba9e55edcc3 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -73,13 +73,6 @@ impl EmissionGuarantee for FatalAbort { } } -impl EmissionGuarantee for rustc_span::fatal_error::FatalError { - fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult { - diag.emit_producing_nothing(); - rustc_span::fatal_error::FatalError - } -} - /// Trait implemented by error types. This is rarely implemented manually. Instead, use /// `#[derive(Diagnostic)]` -- see [rustc_macros::Diagnostic]. /// diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index f868b11ea6fd2..146eef4096f17 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1026,19 +1026,6 @@ impl<'a> DiagCtxtHandle<'a> { self.create_fatal(fatal).emit() } - #[track_caller] - pub fn create_almost_fatal( - self, - fatal: impl Diagnostic<'a, FatalError>, - ) -> Diag<'a, FatalError> { - fatal.into_diag(self, Fatal) - } - - #[track_caller] - pub fn emit_almost_fatal(self, fatal: impl Diagnostic<'a, FatalError>) -> FatalError { - self.create_almost_fatal(fatal).emit() - } - // FIXME: This method should be removed (every error should have an associated error code). #[track_caller] pub fn struct_err(self, msg: impl Into) -> Diag<'a> { @@ -1582,24 +1569,21 @@ impl DelayedDiagInner { } } -/// | Level | is_error | EmissionGuarantee | Top-level | Sub | Used in lints? -/// | ----- | -------- | ----------------- | --------- | --- | -------------- -/// | Bug | yes | BugAbort | yes | - | - -/// | Fatal | yes | FatalAbort/FatalError[^star] | yes | - | - -/// | Error | yes | ErrorGuaranteed | yes | - | yes -/// | DelayedBug | yes | ErrorGuaranteed | yes | - | - -/// | ForceWarning | - | () | yes | - | lint-only -/// | Warning | - | () | yes | yes | yes -/// | Note | - | () | rare | yes | - -/// | OnceNote | - | () | - | yes | lint-only -/// | Help | - | () | rare | yes | - -/// | OnceHelp | - | () | - | yes | lint-only -/// | FailureNote | - | () | rare | - | - -/// | Allow | - | () | yes | - | lint-only -/// | Expect | - | () | yes | - | lint-only -/// -/// [^star]: `FatalAbort` normally, `FatalError` in the non-aborting "almost fatal" case that is -/// occasionally used. +/// | Level | is_error | EmissionGuarantee | Top-level | Sub | Used in lints? +/// | ----- | -------- | ----------------- | --------- | --- | -------------- +/// | Bug | yes | BugAbort | yes | - | - +/// | Fatal | yes | FatalAbort | yes | - | - +/// | Error | yes | ErrorGuaranteed | yes | - | yes +/// | DelayedBug | yes | ErrorGuaranteed | yes | - | - +/// | ForceWarning | - | () | yes | - | lint-only +/// | Warning | - | () | yes | yes | yes +/// | Note | - | () | rare | yes | - +/// | OnceNote | - | () | - | yes | lint-only +/// | Help | - | () | rare | yes | - +/// | OnceHelp | - | () | - | yes | lint-only +/// | FailureNote | - | () | rare | - | - +/// | Allow | - | () | yes | - | lint-only +/// | Expect | - | () | yes | - | lint-only /// #[derive(Copy, PartialEq, Eq, Clone, Hash, Debug, Encodable, Decodable)] pub enum Level { From 8b71848ed47f0f4f9e041bff45e4ca0aeb11c4a5 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 17 Aug 2026 17:47:40 +0200 Subject: [PATCH 05/12] Avoid fatal errors in raw-dylib handling --- compiler/rustc_metadata/src/native_libs.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index 87e0902b1f7f8..eff464bcfc526 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -274,7 +274,8 @@ impl<'tcx> Collector<'tcx> { DllCallingConvention::Vectorcall(self.i686_arg_list_size(item)) } _ => { - self.tcx.dcx().emit_fatal(diagnostics::RawDylibUnsupportedAbi { span }); + self.tcx.dcx().emit_err(diagnostics::RawDylibUnsupportedAbi { span }); + return None; } } } else { @@ -283,7 +284,8 @@ impl<'tcx> Collector<'tcx> { DllCallingConvention::C } _ => { - self.tcx.dcx().emit_fatal(diagnostics::RawDylibUnsupportedAbi { span }); + self.tcx.dcx().emit_err(diagnostics::RawDylibUnsupportedAbi { span }); + return None; } } }; From d9e75ad87ca8e084700e2b83fa7ec7f69d0b9f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Wed, 9 Sep 2026 13:29:37 +0200 Subject: [PATCH 06/12] Fix run-make/prune-link-args to work with MinGW The explanation provided was wrong. Libc doesn't exist on Windows, so naturally this failed on missing lib. I have no idea what shenanigans link.exe does to make this pass, but surely it doesn't actually link libc. --- tests/run-make/prune-link-args/rmake.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/run-make/prune-link-args/rmake.rs b/tests/run-make/prune-link-args/rmake.rs index ea4ffa732bf3f..6702984d2e85a 100644 --- a/tests/run-make/prune-link-args/rmake.rs +++ b/tests/run-make/prune-link-args/rmake.rs @@ -6,12 +6,10 @@ // See https://github.com/rust-lang/rust/pull/10749 //@ ignore-cross-compile -//@ ignore-windows-gnu -// Reason: The space is parsed as an empty linker argument on windows-gnu. use run_make_support::rustc; fn main() { - // Notice the space at the end of -lc, which emulates the output of pkg-config. - rustc().arg("-Clink-args=-lc ").input("empty.rs").run(); + // Notice the space at the end of -lm, which emulates the output of pkg-config. + rustc().arg("-Clink-args=-lm ").input("empty.rs").run(); } From 910f84c5c78003cef02e3b2ce9634472249ee9f0 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Wed, 9 Sep 2026 22:37:11 +0200 Subject: [PATCH 07/12] Attemped fix for home dir problem --- src/ci/scripts/disable-git-crlf-conversion.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ci/scripts/disable-git-crlf-conversion.sh b/src/ci/scripts/disable-git-crlf-conversion.sh index 6de080a9fde00..856c2fa03700e 100755 --- a/src/ci/scripts/disable-git-crlf-conversion.sh +++ b/src/ci/scripts/disable-git-crlf-conversion.sh @@ -10,4 +10,8 @@ set -euo pipefail IFS=$'\n\t' +# Workaround for issue where the home dir of `msys64` sometimes doesn't exist on github runners +echo $HOME +mkdir -p $HOME + git config --replace-all --global core.autocrlf false From 88db34ad12223f211786050877bb6005cfcaa1e6 Mon Sep 17 00:00:00 2001 From: Jonas Berlin Date: Thu, 10 Sep 2026 08:49:25 +0300 Subject: [PATCH 08/12] doc: Fix external mention of signum() return value regarding NaNs --- library/core/src/num/f128.rs | 4 ++-- library/core/src/num/f16.rs | 4 ++-- library/core/src/num/f32.rs | 4 ++-- library/core/src/num/f64.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/core/src/num/f128.rs b/library/core/src/num/f128.rs index 93dd52198f488..db05d7fdc5087 100644 --- a/library/core/src/num/f128.rs +++ b/library/core/src/num/f128.rs @@ -594,7 +594,7 @@ impl f128 { /// conserved over arithmetic operations, the result of `is_sign_positive` on /// a NaN might produce an unexpected or non-portable result. See the [specification /// of NaN bit patterns](f32#nan-bit-patterns) for more info. Use `self.signum() == 1.0` - /// if you need fully portable behavior (will return `false` for all NaNs). + /// if you need fully portable behavior (will return NaN for all NaNs). /// /// ``` /// #![feature(f128)] @@ -620,7 +620,7 @@ impl f128 { /// conserved over arithmetic operations, the result of `is_sign_negative` on /// a NaN might produce an unexpected or non-portable result. See the [specification /// of NaN bit patterns](f32#nan-bit-patterns) for more info. Use `self.signum() == -1.0` - /// if you need fully portable behavior (will return `false` for all NaNs). + /// if you need fully portable behavior (will return NaN for all NaNs). /// /// ``` /// #![feature(f128)] diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs index cb79c0736c608..273ef3688ca5f 100644 --- a/library/core/src/num/f16.rs +++ b/library/core/src/num/f16.rs @@ -588,7 +588,7 @@ impl f16 { /// conserved over arithmetic operations, the result of `is_sign_positive` on /// a NaN might produce an unexpected or non-portable result. See the [specification /// of NaN bit patterns](f32#nan-bit-patterns) for more info. Use `self.signum() == 1.0` - /// if you need fully portable behavior (will return `false` for all NaNs). + /// if you need fully portable behavior (will return NaN for all NaNs). /// /// ``` /// #![feature(f16)] @@ -616,7 +616,7 @@ impl f16 { /// conserved over arithmetic operations, the result of `is_sign_negative` on /// a NaN might produce an unexpected or non-portable result. See the [specification /// of NaN bit patterns](f32#nan-bit-patterns) for more info. Use `self.signum() == -1.0` - /// if you need fully portable behavior (will return `false` for all NaNs). + /// if you need fully portable behavior (will return NaN for all NaNs). /// /// ``` /// #![feature(f16)] diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 8a02aa7517474..d3dea38dc2fcf 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -811,7 +811,7 @@ impl f32 { /// conserved over arithmetic operations, the result of `is_sign_positive` on /// a NaN might produce an unexpected or non-portable result. See the [specification /// of NaN bit patterns](f32#nan-bit-patterns) for more info. Use `self.signum() == 1.0` - /// if you need fully portable behavior (will return `false` for all NaNs). + /// if you need fully portable behavior (will return NaN for all NaNs). /// /// ``` /// let f = 7.0_f32; @@ -836,7 +836,7 @@ impl f32 { /// conserved over arithmetic operations, the result of `is_sign_negative` on /// a NaN might produce an unexpected or non-portable result. See the [specification /// of NaN bit patterns](f32#nan-bit-patterns) for more info. Use `self.signum() == -1.0` - /// if you need fully portable behavior (will return `false` for all NaNs). + /// if you need fully portable behavior (will return NaN for all NaNs). /// /// ``` /// let f = 7.0f32; diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index e0bb0e35415b6..7c5082749cd11 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -810,7 +810,7 @@ impl f64 { /// conserved over arithmetic operations, the result of `is_sign_positive` on /// a NaN might produce an unexpected or non-portable result. See the [specification /// of NaN bit patterns](f32#nan-bit-patterns) for more info. Use `self.signum() == 1.0` - /// if you need fully portable behavior (will return `false` for all NaNs). + /// if you need fully portable behavior (will return NaN for all NaNs). /// /// ``` /// let f = 7.0_f64; @@ -835,7 +835,7 @@ impl f64 { /// conserved over arithmetic operations, the result of `is_sign_negative` on /// a NaN might produce an unexpected or non-portable result. See the [specification /// of NaN bit patterns](f32#nan-bit-patterns) for more info. Use `self.signum() == -1.0` - /// if you need fully portable behavior (will return `false` for all NaNs). + /// if you need fully portable behavior (will return NaN for all NaNs). /// /// ``` /// let f = 7.0_f64; From 052ee70292daaccd4fa5b383a4784ee730f9cc6e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 31 Aug 2026 12:56:40 +0200 Subject: [PATCH 09/12] Don't rely on codegen emitting fn_abi_of_* errors in abi checks This avoids a delayed bug if compilation is aborted between checking function ABIs and codegening all functions. --- .../rustc_codegen_cranelift/src/common.rs | 21 ++------ compiler/rustc_codegen_gcc/src/context.rs | 23 ++------ compiler/rustc_codegen_llvm/src/context.rs | 22 ++------ compiler/rustc_middle/src/ty/layout.rs | 26 ++++++++- .../src/mono_checks/abi_check.rs | 53 ++++++++++++++----- tests/crashes/152204.rs | 9 ---- tests/ui/abi/no_delayed_bug.rs | 15 ++++++ tests/ui/abi/no_delayed_bug.stderr | 11 ++++ tests/ui/limits/issue-17913.32bit.stderr | 5 +- tests/ui/limits/issue-17913.64bit.stderr | 5 +- tests/ui/limits/issue-17913.rs | 1 + 11 files changed, 111 insertions(+), 80 deletions(-) delete mode 100644 tests/crashes/152204.rs create mode 100644 tests/ui/abi/no_delayed_bug.rs create mode 100644 tests/ui/abi/no_delayed_bug.stderr diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs index 1bdb3efefa1aa..d31c8fc810b2c 100644 --- a/compiler/rustc_codegen_cranelift/src/common.rs +++ b/compiler/rustc_codegen_cranelift/src/common.rs @@ -5,8 +5,9 @@ use rustc_index::IndexVec; use rustc_middle::ty::TypeFoldable; use rustc_middle::ty::layout::{ self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, + codegen_handle_fn_abi_err, }; -use rustc_span::{Spanned, Symbol}; +use rustc_span::Symbol; use rustc_target::callconv::FnAbi; use rustc_target::spec::{Arch, HasTargetSpec, Target}; @@ -453,23 +454,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for FullyMonomorphizedLayoutCx<'tcx> { span: Span, fn_abi_request: FnAbiRequest<'tcx>, ) -> ! { - if let FnAbiError::Layout(LayoutError::SizeOverflow(_) | LayoutError::InvalidSimd { .. }) = - err - { - self.0.sess.dcx().emit_fatal(Spanned { span, node: err }) - } else { - match fn_abi_request { - FnAbiRequest::OfFnPtr { sig, extra_args } => { - span_bug!(span, "`fn_abi_of_fn_ptr({sig}, {extra_args:?})` failed: {err:?}"); - } - FnAbiRequest::OfInstance { instance, extra_args } => { - span_bug!( - span, - "`fn_abi_of_instance({instance}, {extra_args:?})` failed: {err:?}" - ); - } - } - } + codegen_handle_fn_abi_err(self.0, err, span, fn_abi_request).raise_fatal() } } diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index 19fbe37c27b9e..64f9982ac7de6 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -10,16 +10,15 @@ use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, ToBaseN}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_middle::mir::interpret::Allocation; use rustc_middle::mono::CodegenUnit; -use rustc_middle::span_bug; use rustc_middle::ty::layout::{ FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, - LayoutOfHelpers, + LayoutOfHelpers, codegen_handle_fn_abi_err, }; use rustc_middle::ty::{self, ExistentialTraitRef, Instance, Ty, TyCtxt}; #[cfg(feature = "master")] use rustc_session::config::DebugInfo; use rustc_session::{PointerAuthSchema, Session}; -use rustc_span::{DUMMY_SP, Span, Symbol, respan}; +use rustc_span::{DUMMY_SP, Span, Symbol}; use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, TlsModel, X86Abi}; #[cfg(feature = "master")] @@ -562,23 +561,7 @@ impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> { span: Span, fn_abi_request: FnAbiRequest<'tcx>, ) -> ! { - if let FnAbiError::Layout(LayoutError::SizeOverflow(_) | LayoutError::InvalidSimd { .. }) = - err - { - self.tcx.dcx().emit_fatal(respan(span, err)) - } else { - match fn_abi_request { - FnAbiRequest::OfFnPtr { sig, extra_args } => { - span_bug!(span, "`fn_abi_of_fn_ptr({sig}, {extra_args:?})` failed: {err:?}"); - } - FnAbiRequest::OfInstance { instance, extra_args } => { - span_bug!( - span, - "`fn_abi_of_instance({instance}, {extra_args:?})` failed: {err:?}" - ); - } - } - } + codegen_handle_fn_abi_err(self.tcx, err, span, fn_abi_request).raise_fatal() } } diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 9e127edbd2ff9..3b58a7f00146b 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -14,18 +14,19 @@ use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, ToBaseN}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; +use rustc_middle::bug; use rustc_middle::mono::CodegenUnit; use rustc_middle::ty::layout::{ FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTypingEnv, LayoutError, LayoutOfHelpers, + codegen_handle_fn_abi_err, }; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; -use rustc_middle::{bug, span_bug}; use rustc_sanitizers::ignorelist::{SanitizerIgnoreList, typename_for_ignore_list}; use rustc_session::config::{ BranchProtection, CFGuard, CFProtection, DebugInfo, FunctionReturn, PAuthKey, PacRet, }; use rustc_session::{PointerAuthSchema, Session}; -use rustc_span::{DUMMY_SP, Span, Spanned, Symbol, sym}; +use rustc_span::{DUMMY_SP, Span, Symbol, sym}; use rustc_structures::CrateType; use rustc_target::spec::{ Arch, CfgAbi, Env, FramePointer, HasTargetSpec, Os, RelocModel, SmallDataThresholdSupport, @@ -1316,21 +1317,6 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'_, 'tcx> { span: Span, fn_abi_request: FnAbiRequest<'tcx>, ) -> ! { - match err { - FnAbiError::Layout(LayoutError::SizeOverflow(_) | LayoutError::InvalidSimd { .. }) => { - self.tcx.dcx().emit_fatal(Spanned { span, node: err }); - } - _ => match fn_abi_request { - FnAbiRequest::OfFnPtr { sig, extra_args } => { - span_bug!(span, "`fn_abi_of_fn_ptr({sig}, {extra_args:?})` failed: {err:?}",); - } - FnAbiRequest::OfInstance { instance, extra_args } => { - span_bug!( - span, - "`fn_abi_of_instance({instance}, {extra_args:?})` failed: {err:?}", - ); - } - }, - } + codegen_handle_fn_abi_err(self.tcx, err, span, fn_abi_request).raise_fatal() } } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index c18bf81121377..85e1df8b057a0 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -14,7 +14,7 @@ use rustc_hir::attrs::lang_items::LangItem; use rustc_hir::def_id::DefId; use rustc_macros::{StableHash, TyDecodable, TyEncodable, extension}; use rustc_session::config::OptLevel; -use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym}; +use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Spanned, Symbol, sym}; use rustc_structures::Limit; use rustc_target::callconv::FnAbi; use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, X86Abi}; @@ -1374,6 +1374,8 @@ pub trait FnAbiOfHelpers<'tcx>: LayoutOfHelpers<'tcx> { /// but this hook allows e.g. codegen to return only `&FnAbi` from its /// `cx.fn_abi_of_*(...)`, without any `Result<...>` around it to deal with /// (and any `FnAbiError`s are turned into fatal errors or ICEs). + /// + /// Codegen backends should use [`codegen_handle_fn_abi_err`] as implementation. fn handle_fn_abi_err( &self, err: FnAbiError<'tcx>, @@ -1382,6 +1384,28 @@ pub trait FnAbiOfHelpers<'tcx>: LayoutOfHelpers<'tcx> { ) -> >>>::Error; } +/// Implementation of [`FnAbiOfHelpers::handle_fn_abi_err`] for codegen backends. +pub fn codegen_handle_fn_abi_err<'tcx>( + tcx: TyCtxt<'tcx>, + err: FnAbiError<'tcx>, + span: Span, + fn_abi_request: FnAbiRequest<'tcx>, +) -> ErrorGuaranteed { + match err { + FnAbiError::Layout(LayoutError::SizeOverflow(_) | LayoutError::InvalidSimd { .. }) => { + tcx.dcx().emit_err(Spanned { span, node: err }) + } + _ => match fn_abi_request { + FnAbiRequest::OfFnPtr { sig, extra_args } => { + span_bug!(span, "`fn_abi_of_fn_ptr({sig}, {extra_args:?})` failed: {err:?}",); + } + FnAbiRequest::OfInstance { instance, extra_args } => { + span_bug!(span, "`fn_abi_of_instance({instance}, {extra_args:?})` failed: {err:?}",); + } + }, + } +} + /// Blanket extension trait for contexts that can compute `FnAbi`s. pub trait FnAbiOf<'tcx>: FnAbiOfHelpers<'tcx> { /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers. diff --git a/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs b/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs index 885ad6071d91c..1ba48e6829070 100644 --- a/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs +++ b/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs @@ -3,6 +3,7 @@ use rustc_abi::{BackendRepr, CanonAbi, ExternAbi, RegKind, X86Call}; use rustc_hir::{CRATE_HIR_ID, HirId}; use rustc_middle::mir::{self, Location, traversal}; +use rustc_middle::ty::layout::{FnAbiRequest, codegen_handle_fn_abi_err}; use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt}; use rustc_span::def_id::DefId; use rustc_span::{DUMMY_SP, Span, Symbol, sym}; @@ -173,12 +174,19 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) { // LLVM intrinsics return; } - let Ok(abi) = tcx.fn_abi_of_instance(typing_env.as_query_input((instance, ty::List::empty()))) - else { - // An error will be reported during codegen if we cannot determine the ABI of this - // function. - tcx.dcx().delayed_bug("ABI computation failure should lead to compilation failure"); - return; + let abi = match tcx.fn_abi_of_instance(typing_env.as_query_input((instance, ty::List::empty()))) + { + Ok(abi) => abi, + Err(err) => { + codegen_handle_fn_abi_err( + tcx, + *err, + tcx.def_span(instance.def_id()), + FnAbiRequest::OfInstance { instance, extra_args: ty::List::empty() }, + ); + // ABI failed to compute; this will not get through codegen. + return; + } }; // Unlike the call-site check, we do also check "Rust" ABI functions here. This can actually // trigger due to scalable vectors being require for the "Rust" ABI for some types. @@ -214,7 +222,20 @@ fn check_call_site_abi<'tcx>( let typing_env = ty::TypingEnv::fully_monomorphized(); let callee_abi = match *callee.kind() { ty::FnPtr(..) => { - tcx.fn_abi_of_fn_ptr(typing_env.as_query_input((callee.fn_sig(tcx), ty::List::empty()))) + let sig = callee.fn_sig(tcx); + match tcx.fn_abi_of_fn_ptr(typing_env.as_query_input((sig, ty::List::empty()))) { + Ok(callee_abi) => callee_abi, + Err(err) => { + codegen_handle_fn_abi_err( + tcx, + *err, + loc().0, + FnAbiRequest::OfFnPtr { sig, extra_args: ty::List::empty() }, + ); + // ABI failed to compute; this will not get through codegen. + return; + } + } } ty::FnDef(def_id, args) => { // Intrinsics are handled separately by the compiler. @@ -232,17 +253,25 @@ fn check_call_site_abi<'tcx>( // LLVM intrinsics don't have an ABI, so there is nothing to check. return; } - tcx.fn_abi_of_instance(typing_env.as_query_input((instance, ty::List::empty()))) + match tcx.fn_abi_of_instance(typing_env.as_query_input((instance, ty::List::empty()))) { + Ok(callee_abi) => callee_abi, + Err(err) => { + codegen_handle_fn_abi_err( + tcx, + *err, + loc().0, + FnAbiRequest::OfInstance { instance, extra_args: ty::List::empty() }, + ); + // ABI failed to compute; this will not get through codegen. + return; + } + } } _ => { panic!("Invalid function call"); } }; - let Ok(callee_abi) = callee_abi else { - // ABI failed to compute; this will not get through codegen. - return; - }; do_check_unsized_params(tcx, callee_abi, /*is_call*/ true, loc); do_check_simd_vector_abi(tcx, callee_abi, caller.def_id(), /*is_call*/ true, loc); } diff --git a/tests/crashes/152204.rs b/tests/crashes/152204.rs deleted file mode 100644 index 8c9be213d9ea5..0000000000000 --- a/tests/crashes/152204.rs +++ /dev/null @@ -1,9 +0,0 @@ -//@ known-bug: #152204 -//@ compile-flags: -Copt-level=0 -#![feature(portable_simd)] - -fn main() { - if false { - let _ = core::simd::Simd::::splat(0); - } -} diff --git a/tests/ui/abi/no_delayed_bug.rs b/tests/ui/abi/no_delayed_bug.rs new file mode 100644 index 0000000000000..9b378ba9d25a7 --- /dev/null +++ b/tests/ui/abi/no_delayed_bug.rs @@ -0,0 +1,15 @@ +// Used to ICE due to the ABI checker emitting a delayed bug when failing to get +// the FnAbi due to a const assert, while codegen skipped the call due to being +// unreachable. +//@ compile-flags: -Copt-level=0 +//@ build-fail + +//~? ERROR the SIMD type `Simd` has more elements than the limit 64 + +#![feature(portable_simd)] + +fn main() { + if false { + let _ = core::simd::Simd::::splat(0); + } +} diff --git a/tests/ui/abi/no_delayed_bug.stderr b/tests/ui/abi/no_delayed_bug.stderr new file mode 100644 index 0000000000000..c21256b86a6c4 --- /dev/null +++ b/tests/ui/abi/no_delayed_bug.stderr @@ -0,0 +1,11 @@ +error: the SIMD type `Simd` has more elements than the limit 64 + --> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/vector.rs:LL:COL + +note: the above error was encountered while instantiating `fn Simd::::splat` + --> $DIR/no_delayed_bug.rs:13:17 + | +LL | let _ = core::simd::Simd::::splat(0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/limits/issue-17913.32bit.stderr b/tests/ui/limits/issue-17913.32bit.stderr index 1e3e3a9f32295..6ddde4b891836 100644 --- a/tests/ui/limits/issue-17913.32bit.stderr +++ b/tests/ui/limits/issue-17913.32bit.stderr @@ -1,3 +1,6 @@ +error: values of the type `[&usize; usize::MAX]` are too big for the target architecture + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | @@ -9,6 +12,6 @@ note: the above error was encountered while instantiating `fn Box::<[&usize; usi LL | let a: Box<_> = Box::new([&n; SIZE]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/limits/issue-17913.64bit.stderr b/tests/ui/limits/issue-17913.64bit.stderr index 5e92c70a764c4..d35d697d5f3f3 100644 --- a/tests/ui/limits/issue-17913.64bit.stderr +++ b/tests/ui/limits/issue-17913.64bit.stderr @@ -1,3 +1,6 @@ +error: values of the type `[&usize; usize::MAX]` are too big for the target architecture + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | @@ -9,6 +12,6 @@ note: the above error was encountered while instantiating `fn Box::<[&usize; usi LL | let a: Box<_> = Box::new([&n; SIZE]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/limits/issue-17913.rs b/tests/ui/limits/issue-17913.rs index 9448358edba00..d804b64ab330e 100644 --- a/tests/ui/limits/issue-17913.rs +++ b/tests/ui/limits/issue-17913.rs @@ -18,3 +18,4 @@ fn main() { } //~? ERROR are too big for the target architecture +//~? ERROR are too big for the target architecture From e525d70b9faee49982f1e5cf6bc5ad87e147ed02 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 31 Aug 2026 13:12:15 +0200 Subject: [PATCH 10/12] Avoid panic when metadata encoder is called with errors And remove the encoded metadata if there are any errors or delayed bugs after encoding. --- compiler/rustc_interface/src/passes.rs | 5 ++++- compiler/rustc_metadata/src/fs.rs | 9 +++++++-- compiler/rustc_metadata/src/rmeta/encoder.rs | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 68af061769437..12f3140a8c7b3 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -1302,7 +1302,10 @@ pub(crate) fn start_codegen<'tcx>( info!("Pre-codegen\n{:?}", tcx.debug_stats()); - let metadata = rustc_metadata::fs::encode_and_write_metadata(tcx); + let metadata = match rustc_metadata::fs::encode_and_write_metadata(tcx) { + Ok(metadata) => metadata, + Err(guar) => guar.raise_fatal(), + }; let is_host_metadata = tcx .sess diff --git a/compiler/rustc_metadata/src/fs.rs b/compiler/rustc_metadata/src/fs.rs index 535197b3dc51a..ed177708facc0 100644 --- a/compiler/rustc_metadata/src/fs.rs +++ b/compiler/rustc_metadata/src/fs.rs @@ -7,6 +7,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_session::config::{OutFileName, OutputType}; use rustc_session::output::filename_for_metadata; +use rustc_span::ErrorGuaranteed; use rustc_structures::CrateType; use crate::diagnostics::{ @@ -34,7 +35,7 @@ pub fn emit_wrapper_file(sess: &Session, data: &[u8], tmpdir: &Path, name: &str) out_filename } -pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata { +pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> Result { let out_filename = filename_for_metadata(tcx.sess, tcx.output_filenames(())); // To avoid races with another rustc process scanning the output directory, // we need to write the file somewhere else and atomically move it to its @@ -70,6 +71,10 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata { } } + if let Some(guar) = tcx.sess.dcx().has_errors_or_delayed_bugs() { + return Err(guar); + } + let _prof_timer = tcx.sess.prof.generic_activity("write_crate_metadata"); // If the user requests metadata as output, rename `metadata_filename` @@ -109,7 +114,7 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata { tcx.dcx().emit_fatal(FailedCreateEncodedMetadata { err }); }); - metadata + Ok(metadata) } #[cfg(not(target_os = "linux"))] diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 713671c3a5b47..dc4a41ace6b88 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1571,8 +1571,19 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } if let DefKind::Static { .. } = def_kind { if !self.tcx.is_foreign_item(def_id) { - let data = self.tcx.eval_static_initializer(def_id).unwrap(); - record!(self.tables.eval_static_initializer[def_id] <- data); + match self.tcx.eval_static_initializer(def_id) { + Ok(data) => record!(self.tables.eval_static_initializer[def_id] <- data), + Err(err) => match err { + interpret::ErrorHandled::Reported(_, _) => { + self.tcx.dcx().delayed_bug(format!( + "eval_static_initializer returned an error in metadata emission" + )); + } + interpret::ErrorHandled::TooGeneric(span) => { + span_bug!(span, "generic static???"); + } + }, + }; } } if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind { From 5e120485964f4857f1ad70f7d661fd244d087668 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 10 Sep 2026 10:13:46 +0200 Subject: [PATCH 11/12] Rustup to rustc 1.100.0-nightly (a36d05efa 2026-09-09) --- example/mini_core.rs | 1 + rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index 40ce0bf30d144..08adec96a079b 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -6,6 +6,7 @@ extern_types, decl_macro, rustc_attrs, + rustc_private, transparent_unions, pattern_types, auto_traits, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index bc8bfacba1923..b83354ee49fb9 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2026-09-08" +channel = "nightly-2026-09-10" components = ["rust-src", "rustc-dev", "llvm-tools", "rustfmt"] profile = "minimal" From 21b046d7dc696715a327415fc70a24d180618ea4 Mon Sep 17 00:00:00 2001 From: Jiaxiang Zhang Date: Thu, 10 Sep 2026 09:21:12 +0000 Subject: [PATCH 12/12] fix(traits): Remove expression references from index suggestions * fix(traits): Remove expression references from index suggestions * Use expression spans for index reference removal suggestions * refactor(trait-selection): Simplify dereference suggestion guard --- .../src/error_reporting/traits/suggestions.rs | 32 +++++++++ .../suggest-remove-reference-index.fixed | 10 +++ .../suggest-remove-reference-index.rs | 10 +++ .../suggest-remove-reference-index.stderr | 66 +++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 tests/ui/suggestions/suggest-remove-reference-index.fixed create mode 100644 tests/ui/suggestions/suggest-remove-reference-index.rs create mode 100644 tests/ui/suggestions/suggest-remove-reference-index.stderr diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 65e589d336500..51527991b073b 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -5147,6 +5147,38 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { && let ty::Ref(_, inner_ty, _) = trait_pred.skip_binder().self_ty().kind() && let ty::Uint(ty::UintTy::Usize) = inner_ty.kind() { + // If the index is written as `&i`, suggest removing the borrow instead of + // dereferencing it, i.e. `v[&i]` -> `v[i]` rather than `v[*&i]`. + let span = obligation.cause.span; + if !span.from_expansion() + && let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_def_id) + && let Some(expr) = { + let mut finder = FindExprBySpan::new(span, self.tcx); + finder.visit_expr(body.value); + finder.result + } + && let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, borrowed) = + expr.kind + && let Some(amp_span) = borrowed + .span + .find_ancestor_inside_same_ctxt(expr.span) + .map(|borrowed_span| expr.span.until(borrowed_span)) + && self + .tcx + .sess + .source_map() + .span_to_snippet(amp_span) + .is_ok_and(|snippet| snippet.starts_with('&')) + { + err.span_suggestion_verbose( + amp_span, + "remove this reference", + "", + Applicability::MachineApplicable, + ); + return; + } + err.span_suggestion_verbose( obligation.cause.span.shrink_to_lo(), "dereference this index", diff --git a/tests/ui/suggestions/suggest-remove-reference-index.fixed b/tests/ui/suggestions/suggest-remove-reference-index.fixed new file mode 100644 index 0000000000000..646c650de4584 --- /dev/null +++ b/tests/ui/suggestions/suggest-remove-reference-index.fixed @@ -0,0 +1,10 @@ +//@ run-rustfix + +fn main() { + let arr = [false]; + let i = 0usize; + + println!("{}", arr[i]); //~ ERROR the type `[bool]` cannot be indexed by `&usize` + println!("{}", arr[(i + 0)]); //~ ERROR the type `[bool]` cannot be indexed by `&usize` + println!("{}", arr[i]); //~ ERROR the type `[bool]` cannot be indexed by `&usize` +} diff --git a/tests/ui/suggestions/suggest-remove-reference-index.rs b/tests/ui/suggestions/suggest-remove-reference-index.rs new file mode 100644 index 0000000000000..db0a33a89eff3 --- /dev/null +++ b/tests/ui/suggestions/suggest-remove-reference-index.rs @@ -0,0 +1,10 @@ +//@ run-rustfix + +fn main() { + let arr = [false]; + let i = 0usize; + + println!("{}", arr[&i]); //~ ERROR the type `[bool]` cannot be indexed by `&usize` + println!("{}", arr[&(i + 0)]); //~ ERROR the type `[bool]` cannot be indexed by `&usize` + println!("{}", arr[& i]); //~ ERROR the type `[bool]` cannot be indexed by `&usize` +} diff --git a/tests/ui/suggestions/suggest-remove-reference-index.stderr b/tests/ui/suggestions/suggest-remove-reference-index.stderr new file mode 100644 index 0000000000000..4f396fe529508 --- /dev/null +++ b/tests/ui/suggestions/suggest-remove-reference-index.stderr @@ -0,0 +1,66 @@ +error[E0277]: the type `[bool]` cannot be indexed by `&usize` + --> $DIR/suggest-remove-reference-index.rs:7:24 + | +LL | println!("{}", arr[&i]); + | ^^ slice indices are of type `usize` or ranges of `usize` + | + = help: the trait `SliceIndex<[bool]>` is not implemented for `&usize` +help: `usize` implements trait `SliceIndex` + --> $SRC_DIR/core/src/slice/index.rs:LL:COL + | + = note: `SliceIndex<[T]>` + --> $SRC_DIR/core/src/bstr/traits.rs:LL:COL + | + = note: `SliceIndex` + = note: required for `[bool]` to implement `Index<&usize>` +help: remove this reference + | +LL - println!("{}", arr[&i]); +LL + println!("{}", arr[i]); + | + +error[E0277]: the type `[bool]` cannot be indexed by `&usize` + --> $DIR/suggest-remove-reference-index.rs:8:24 + | +LL | println!("{}", arr[&(i + 0)]); + | ^^^^^^^^ slice indices are of type `usize` or ranges of `usize` + | + = help: the trait `SliceIndex<[bool]>` is not implemented for `&usize` +help: `usize` implements trait `SliceIndex` + --> $SRC_DIR/core/src/slice/index.rs:LL:COL + | + = note: `SliceIndex<[T]>` + --> $SRC_DIR/core/src/bstr/traits.rs:LL:COL + | + = note: `SliceIndex` + = note: required for `[bool]` to implement `Index<&usize>` +help: remove this reference + | +LL - println!("{}", arr[&(i + 0)]); +LL + println!("{}", arr[(i + 0)]); + | + +error[E0277]: the type `[bool]` cannot be indexed by `&usize` + --> $DIR/suggest-remove-reference-index.rs:9:24 + | +LL | println!("{}", arr[& i]); + | ^^^ slice indices are of type `usize` or ranges of `usize` + | + = help: the trait `SliceIndex<[bool]>` is not implemented for `&usize` +help: `usize` implements trait `SliceIndex` + --> $SRC_DIR/core/src/slice/index.rs:LL:COL + | + = note: `SliceIndex<[T]>` + --> $SRC_DIR/core/src/bstr/traits.rs:LL:COL + | + = note: `SliceIndex` + = note: required for `[bool]` to implement `Index<&usize>` +help: remove this reference + | +LL - println!("{}", arr[& i]); +LL + println!("{}", arr[i]); + | + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`.