Skip to content

Commit

Permalink
Rollup merge of rust-lang#98554 - DrMeepster:box_unsizing_is_not_spec…
Browse files Browse the repository at this point in the history
…ial, r=RalfJung

Fix box with custom allocator in miri

This should fix the failures in rust-lang/miri#2072 and rust-lang#98510.

cc ``@RalfJung``
  • Loading branch information
Dylan-DPC authored Jun 29, 2022
2 parents 1445b53 + 9039265 commit 8ee7e20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
16 changes: 0 additions & 16 deletions compiler/rustc_const_eval/src/interpret/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,22 +366,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
assert_eq!(def_a, def_b);
if def_a.is_box() || def_b.is_box() {
if !def_a.is_box() || !def_b.is_box() {
span_bug!(
self.cur_span(),
"invalid unsizing between {:?} -> {:?}",
src.layout.ty,
cast_ty.ty
);
}
return self.unsize_into_ptr(
src,
dest,
src.layout.ty.boxed_ty(),
cast_ty.ty.boxed_ty(),
);
}

// unsizing of generic struct with pointer fields
// Example: `Arc<T>` -> `Arc<Trait>`
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,13 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
Ok(true)
}
ty::Adt(def, ..) if def.is_box() => {
self.check_safe_pointer(value, "box")?;
let unique = self.ecx.operand_field(value, 0)?;
let nonnull = self.ecx.operand_field(&unique, 0)?;
let ptr = self.ecx.operand_field(&nonnull, 0)?;
self.check_safe_pointer(&ptr, "box")?;

// Check other fields of Box
self.walk_value(value)?;
Ok(true)
}
ty::FnPtr(_sig) => {
Expand Down

0 comments on commit 8ee7e20

Please sign in to comment.