Skip to content

Commit eb6434f

Browse files
committed
handle safety lubbing correctly
1 parent 7391a34 commit eb6434f

File tree

15 files changed

+214
-188
lines changed

15 files changed

+214
-188
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10621062

10631063
Rvalue::Cast(cast_kind, op, ty) => {
10641064
match *cast_kind {
1065-
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, coercion_source) => {
1065+
CastKind::PointerCoercion(
1066+
PointerCoercion::ReifyFnPointer(target_safety),
1067+
coercion_source,
1068+
) => {
10661069
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
10671070
let src_ty = op.ty(self.body, tcx);
10681071
let mut src_sig = src_ty.fn_sig(tcx);
@@ -1079,6 +1082,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10791082
src_sig = safe_sig;
10801083
}
10811084

1085+
if src_sig.safety().is_safe() && target_safety.is_unsafe() {
1086+
src_sig = tcx.safe_to_unsafe_sig(src_sig);
1087+
}
1088+
10821089
// HACK: This shouldn't be necessary... We can remove this when we actually
10831090
// get binders with where clauses, then elaborate implied bounds into that
10841091
// binder, and implement a higher-ranked subtyping algorithm that actually

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
665665
lval.write_cvalue(fx, res);
666666
}
667667
Rvalue::Cast(
668-
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, _),
668+
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer(_), _),
669669
ref operand,
670670
to_ty,
671671
) => {

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
399399
let lladdr = bx.ptrtoint(llptr, llcast_ty);
400400
OperandValue::Immediate(lladdr)
401401
}
402-
mir::CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, _) => {
402+
mir::CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer(_), _) => {
403403
match *operand.layout.ty.kind() {
404404
ty::FnDef(def_id, args) => {
405405
let instance = ty::Instance::resolve_for_fn_ptr(

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
627627
| PointerCoercion::ArrayToPointer
628628
| PointerCoercion::UnsafeFnPointer
629629
| PointerCoercion::ClosureFnPointer(_)
630-
| PointerCoercion::ReifyFnPointer,
630+
| PointerCoercion::ReifyFnPointer(_),
631631
_,
632632
),
633633
_,

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
7474
bug!("{cast_kind:?} casts are for borrowck only, not runtime MIR");
7575
}
7676

77-
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, _) => {
77+
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer(_), _) => {
7878
// All reifications must be monomorphic, bail out otherwise.
7979
ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
8080

0 commit comments

Comments
 (0)