Skip to content

Commit d8ed2fb

Browse files
committed
Fix transmute intrinsic mir validation ICE
1 parent 696aaad commit d8ed2fb

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,21 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
679679
// Unlike `mem::transmute`, a MIR `Transmute` is well-formed
680680
// for any two `Sized` types, just potentially UB to run.
681681

682-
if !op_ty.is_sized(self.tcx, self.param_env) {
682+
if !self
683+
.tcx
684+
.normalize_erasing_regions(self.param_env, op_ty)
685+
.is_sized(self.tcx, self.param_env)
686+
{
683687
self.fail(
684688
location,
685689
format!("Cannot transmute from non-`Sized` type {op_ty:?}"),
686690
);
687691
}
688-
if !target_type.is_sized(self.tcx, self.param_env) {
692+
if !self
693+
.tcx
694+
.normalize_erasing_regions(self.param_env, *target_type)
695+
.is_sized(self.tcx, self.param_env)
696+
{
689697
self.fail(
690698
location,
691699
format!("Cannot transmute to non-`Sized` type {target_type:?}"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// build-pass
2+
// compile-flags: -Zvalidate-mir
3+
// edition: 2021
4+
5+
#![crate_type = "lib"]
6+
7+
// Use `PhantomData` to get target-independent size
8+
async fn get(_r: std::marker::PhantomData<&i32>) {
9+
loop {}
10+
}
11+
12+
pub fn check() {
13+
let mut v = get(loop {});
14+
let _ = || unsafe {
15+
v = std::mem::transmute([0_u8; 1]);
16+
};
17+
}

0 commit comments

Comments
 (0)