Skip to content

Commit 0fc1523

Browse files
authored
Unrolled build for #120587
Rollup merge of #120587 - lukas-code:miri-tail-normalize, r=RalfJung miri: normalize struct tail in ABI compat check fixes rust-lang/miri#3282 extracted from #120354, see #120354 (comment) for context r? ```@RalfJung```
2 parents 0984bec + 30e7b87 commit 0fc1523

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

compiler/rustc_const_eval/src/interpret/terminator.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
373373
if let (Some(caller), Some(callee)) = (pointee_ty(caller.ty)?, pointee_ty(callee.ty)?) {
374374
// This is okay if they have the same metadata type.
375375
let meta_ty = |ty: Ty<'tcx>| {
376-
let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, |ty| ty);
376+
// Even if `ty` is normalized, the search for the unsized tail will project
377+
// to fields, which can yield non-normalized types. So we need to provide a
378+
// normalization function.
379+
let normalize = |ty| self.tcx.normalize_erasing_regions(self.param_env, ty);
380+
let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, normalize);
377381
assert!(
378382
!only_if_sized,
379383
"there should be no more 'maybe has that metadata' types during interpretation"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// regression test for an ICE: https://github.com/rust-lang/miri/issues/3282
2+
3+
trait Id {
4+
type Assoc: ?Sized;
5+
}
6+
7+
impl<T: ?Sized> Id for T {
8+
type Assoc = T;
9+
}
10+
11+
#[repr(transparent)]
12+
struct Foo<T: ?Sized> {
13+
field: <T as Id>::Assoc,
14+
}
15+
16+
fn main() {
17+
let x = unsafe { std::mem::transmute::<fn(&str), fn(&Foo<str>)>(|_| ()) };
18+
let foo: &Foo<str> = unsafe { &*("uwu" as *const str as *const Foo<str>) };
19+
x(foo);
20+
}

0 commit comments

Comments
 (0)