mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-04 09:44:40 +00:00
Rollup merge of #160125 - bit-aloo:2026-07-29-next-solver-typing-bugs, r=adwinwhite
Fix typing mode handling in transmute checks and rustc_dump_layout closes: https://github.com/rust-lang/trait-system-refactor-initiative/issues/283 r? @adwinwhite cc: @lcnr
This commit is contained in:
@@ -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(
|
||||
@@ -253,6 +253,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)).unzip();
|
||||
result = result.and(check_transmute(tcx, typing_env, from, to, hir_id));
|
||||
}
|
||||
result
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
//@ revisions: old next
|
||||
//@[next] compile-flags: -Znext-solver
|
||||
//@ 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();
|
||||
}
|
||||
@@ -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<i32>) {}
|
||||
fn main() {
|
||||
let v = get(loop {});
|
||||
unsafe { v = std::mem::transmute(0_u8) }
|
||||
}
|
||||
Reference in New Issue
Block a user