Skip to content

Commit c387b89

Browse files
author
Lukas Markeffsky
committed
miri: normalize struct tail in ABI compat check
1 parent 2a4e05a commit c387b89

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
372372
};
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.
375-
let meta_ty = |ty: Ty<'tcx>| ty.ptr_metadata_ty(*self.tcx, |ty| ty);
375+
let normalize = |ty: Ty<'tcx>| self.tcx.normalize_erasing_regions(self.param_env, ty);
376+
let meta_ty = |ty: Ty<'tcx>| ty.ptr_metadata_ty(*self.tcx, normalize);
376377
return Ok(meta_ty(caller) == meta_ty(callee));
377378
}
378379

Lines changed: 20 additions & 0 deletions
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)