Skip to content

Commit b2836bd

Browse files
authored
Rollup merge of #98554 - DrMeepster:box_unsizing_is_not_special, r=RalfJung
Fix box with custom allocator in miri This should fix the failures in rust-lang/miri#2072 and #98510. cc ```@RalfJung```
2 parents 375ab3e + 9039265 commit b2836bd

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

compiler/rustc_const_eval/src/interpret/cast.rs

-16
Original file line numberDiff line numberDiff line change
@@ -366,22 +366,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
366366
}
367367
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
368368
assert_eq!(def_a, def_b);
369-
if def_a.is_box() || def_b.is_box() {
370-
if !def_a.is_box() || !def_b.is_box() {
371-
span_bug!(
372-
self.cur_span(),
373-
"invalid unsizing between {:?} -> {:?}",
374-
src.layout.ty,
375-
cast_ty.ty
376-
);
377-
}
378-
return self.unsize_into_ptr(
379-
src,
380-
dest,
381-
src.layout.ty.boxed_ty(),
382-
cast_ty.ty.boxed_ty(),
383-
);
384-
}
385369

386370
// unsizing of generic struct with pointer fields
387371
// Example: `Arc<T>` -> `Arc<Trait>`

compiler/rustc_const_eval/src/interpret/validity.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,13 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
594594
Ok(true)
595595
}
596596
ty::Adt(def, ..) if def.is_box() => {
597-
self.check_safe_pointer(value, "box")?;
597+
let unique = self.ecx.operand_field(value, 0)?;
598+
let nonnull = self.ecx.operand_field(&unique, 0)?;
599+
let ptr = self.ecx.operand_field(&nonnull, 0)?;
600+
self.check_safe_pointer(&ptr, "box")?;
601+
602+
// Check other fields of Box
603+
self.walk_value(value)?;
598604
Ok(true)
599605
}
600606
ty::FnPtr(_sig) => {

0 commit comments

Comments
 (0)