Validation
This commit is contained in:
parent
b63341e892
commit
442b9a9387
2 changed files with 40 additions and 2 deletions
|
@ -279,6 +279,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
}
|
||||
|
||||
WrapUnsafeBinder(ref op, _ty) => {
|
||||
// Constructing an unsafe binder acts like a transmute
|
||||
// since the operand's layout does not change.
|
||||
let op = self.eval_operand(op, None)?;
|
||||
self.copy_op_allow_transmute(&op, &dest)?;
|
||||
}
|
||||
|
|
|
@ -807,6 +807,25 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
|||
)
|
||||
}
|
||||
}
|
||||
ProjectionElem::UnwrapUnsafeBinder(unwrapped_ty) => {
|
||||
let binder_ty = place_ref.ty(&self.body.local_decls, self.tcx);
|
||||
let ty::UnsafeBinder(binder_ty) = *binder_ty.ty.kind() else {
|
||||
self.fail(
|
||||
location,
|
||||
format!("WrapUnsafeBinder does not produce a ty::UnsafeBinder"),
|
||||
);
|
||||
return;
|
||||
};
|
||||
let binder_inner_ty = self.tcx.instantiate_bound_regions_with_erased(*binder_ty);
|
||||
if !self.mir_assign_valid_types(unwrapped_ty, binder_inner_ty) {
|
||||
self.fail(
|
||||
location,
|
||||
format!(
|
||||
"Cannot unwrap unsafe binder {binder_ty:?} into type {unwrapped_ty:?}"
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.super_projection_elem(place_ref, elem, context, location);
|
||||
|
@ -1361,8 +1380,25 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
|||
| Rvalue::ThreadLocalRef(_)
|
||||
| Rvalue::RawPtr(_, _)
|
||||
| Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::UbChecks, _)
|
||||
| Rvalue::Discriminant(_)
|
||||
| Rvalue::WrapUnsafeBinder(..) => {}
|
||||
| Rvalue::Discriminant(_) => {}
|
||||
|
||||
Rvalue::WrapUnsafeBinder(op, ty) => {
|
||||
let unwrapped_ty = op.ty(self.body, self.tcx);
|
||||
let ty::UnsafeBinder(binder_ty) = *ty.kind() else {
|
||||
self.fail(
|
||||
location,
|
||||
format!("WrapUnsafeBinder does not produce a ty::UnsafeBinder"),
|
||||
);
|
||||
return;
|
||||
};
|
||||
let binder_inner_ty = self.tcx.instantiate_bound_regions_with_erased(*binder_ty);
|
||||
if !self.mir_assign_valid_types(unwrapped_ty, binder_inner_ty) {
|
||||
self.fail(
|
||||
location,
|
||||
format!("Cannot wrap {unwrapped_ty:?} into unsafe binder {binder_ty:?}"),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.super_rvalue(rvalue, location);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue