From bdf8d908da75be0b7d90fc66e7ac1c13e90cb090 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Wed, 29 Jul 2026 08:11:49 +0000 Subject: [PATCH 1/3] make sure check_transmutes to adheres to typingEnv bounder constraint around rigid alias --- compiler/rustc_hir_typeck/src/intrinsicck.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index 430f4d828b9..29684aee5bd 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -150,6 +150,7 @@ pub(crate) fn check_transmutes(tcx: TyCtxt<'_>, owner: LocalDefId) -> Result<(), let typing_env = ty::TypingEnv::codegen(tcx, owner); let mut result = Ok(()); for &(from, to, hir_id) in &typeck_results.transmutes_to_check { + let (to, from) = ty::set_aliases_to_non_rigid(tcx, (to, from)).skip_normalization(); result = result.and(check_transmute(tcx, typing_env, from, to, hir_id)); } result From 9d94e8ac59bd196bb3774083ce0d9ed20b679713 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 30 Jul 2026 09:26:22 +0000 Subject: [PATCH 2/3] Fix typing mode handling in transmute and layout checks Types obtained from typeck_results may contain aliases marked as rigid for their original typing environment. Make these aliases non-rigid before normalizing transmute types in TypingMode::Codegen. Also use TypingMode::Codegen in rustc_dump_layout, since opaque types may normalize to coroutines whose layouts cannot be computed in PostAnalysis mode. Add regression coverage for both cases. --- compiler/rustc_hir_typeck/src/intrinsicck.rs | 8 +++---- compiler/rustc_passes/src/layout_test.rs | 2 +- .../opaques/dump-layout-opaque-coroutine.rs | 23 +++++++++++++++++++ .../dump-layout-opaque-coroutine.stderr | 8 +++++++ .../opaques/transmute-async-fn-return-type.rs | 13 +++++++++++ 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.rs create mode 100644 tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.stderr create mode 100644 tests/ui/traits/next-solver/opaques/transmute-async-fn-return-type.rs diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index 29684aee5bd..c5969322077 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -70,13 +70,13 @@ fn skeleton_string<'tcx>( fn check_transmute<'tcx>( tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>, - from: Ty<'tcx>, - to: Ty<'tcx>, + from: Unnormalized<'tcx, Ty<'tcx>>, + to: Unnormalized<'tcx, Ty<'tcx>>, hir_id: HirId, ) -> Result<(), ErrorGuaranteed> { let span = tcx.hir_span(hir_id); let normalize = |ty| { - if let Ok(ty) = tcx.try_normalize_erasing_regions(typing_env, Unnormalized::new_wip(ty)) { + if let Ok(ty) = tcx.try_normalize_erasing_regions(typing_env, ty) { ty } else { Ty::new_error_with_message( @@ -150,7 +150,7 @@ pub(crate) fn check_transmutes(tcx: TyCtxt<'_>, owner: LocalDefId) -> Result<(), let typing_env = ty::TypingEnv::codegen(tcx, owner); let mut result = Ok(()); for &(from, to, hir_id) in &typeck_results.transmutes_to_check { - let (to, from) = ty::set_aliases_to_non_rigid(tcx, (to, from)).skip_normalization(); + let (to, from) = ty::set_aliases_to_non_rigid(tcx, (to, from)).unzip(); result = result.and(check_transmute(tcx, typing_env, from, to, hir_id)); } result diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index 19f2ca3af92..5b7b2572d06 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -60,7 +60,7 @@ pub fn ensure_wf<'tcx>( } fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, kinds: &[RustcDumpLayoutKind]) { - let typing_env = ty::TypingEnv::post_analysis(tcx, item_def_id); + let typing_env = ty::TypingEnv::codegen(tcx, item_def_id); let ty = tcx.type_of(item_def_id).instantiate_identity().skip_norm_wip(); let span = tcx.def_span(item_def_id.to_def_id()); if !ensure_wf(tcx, typing_env, ty, item_def_id, span) { diff --git a/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.rs b/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.rs new file mode 100644 index 00000000000..d77f0c48278 --- /dev/null +++ b/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.rs @@ -0,0 +1,23 @@ +//@ edition: 2024 + +// Regression test for the second example in +// https://github.com/rust-lang/trait-system-refactor-initiative/issues/283. +// +// `rustc_dump_layout` normalizes `Foo` to the coroutine returned by `get`. Coroutine layouts can +// only be computed in `TypingMode::Codegen`, using `TypingMode::PostAnalysis` makes `layout_of` +// return error instead of reporting the expected layout. This was in both trait solvers. + +#![feature(rustc_attrs)] +#![feature(type_alias_impl_trait)] +#![expect(internal_features)] + +async fn get() {} + +#[rustc_dump_layout(size)] +type Foo = impl Sized; +//~^ ERROR: size: Size(1 bytes) + +#[define_opaque(Foo)] +fn main() { + let _: Foo = get(); +} diff --git a/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.stderr b/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.stderr new file mode 100644 index 00000000000..74549a307ad --- /dev/null +++ b/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.stderr @@ -0,0 +1,8 @@ +error: size: Size(1 bytes) + --> $DIR/dump-layout-opaque-coroutine.rs:17:1 + | +LL | type Foo = impl Sized; + | ^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/traits/next-solver/opaques/transmute-async-fn-return-type.rs b/tests/ui/traits/next-solver/opaques/transmute-async-fn-return-type.rs new file mode 100644 index 00000000000..237abb98349 --- /dev/null +++ b/tests/ui/traits/next-solver/opaques/transmute-async-fn-return-type.rs @@ -0,0 +1,13 @@ +//@ check-pass +//@ edition: 2024 +//@ compile-flags: -Znext-solver + +// Regression test for https://github.com/rust-lang/trait-system-refactor-initiative/issues/283. +// +// `check_transmutes` must make the alias non-rigid when crossing the typing-mode boundary. + +async fn get(_r: std::marker::PhantomData) {} +fn main() { + let v = get(loop {}); + unsafe { v = std::mem::transmute(0_u8) } +} From a67d71db4526662c561bd21744e14294387c9235 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 30 Jul 2026 10:46:22 +0000 Subject: [PATCH 3/3] Add revision for dump_layout_opaque-coroutine and have both next and old solver behavior depicted. --- ...ne.stderr => dump-layout-opaque-coroutine.next.stderr} | 2 +- .../opaques/dump-layout-opaque-coroutine.old.stderr | 8 ++++++++ .../next-solver/opaques/dump-layout-opaque-coroutine.rs | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) rename tests/ui/traits/next-solver/opaques/{dump-layout-opaque-coroutine.stderr => dump-layout-opaque-coroutine.next.stderr} (70%) create mode 100644 tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.old.stderr diff --git a/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.stderr b/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.next.stderr similarity index 70% rename from tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.stderr rename to tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.next.stderr index 74549a307ad..52aa7cbcab5 100644 --- a/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.stderr +++ b/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.next.stderr @@ -1,5 +1,5 @@ error: size: Size(1 bytes) - --> $DIR/dump-layout-opaque-coroutine.rs:17:1 + --> $DIR/dump-layout-opaque-coroutine.rs:19:1 | LL | type Foo = impl Sized; | ^^^^^^^^ diff --git a/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.old.stderr b/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.old.stderr new file mode 100644 index 00000000000..52aa7cbcab5 --- /dev/null +++ b/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.old.stderr @@ -0,0 +1,8 @@ +error: size: Size(1 bytes) + --> $DIR/dump-layout-opaque-coroutine.rs:19:1 + | +LL | type Foo = impl Sized; + | ^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.rs b/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.rs index d77f0c48278..cb95c2f6747 100644 --- a/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.rs +++ b/tests/ui/traits/next-solver/opaques/dump-layout-opaque-coroutine.rs @@ -1,3 +1,5 @@ +//@ revisions: old next +//@[next] compile-flags: -Znext-solver //@ edition: 2024 // Regression test for the second example in