Skip to content

Commit bce0933

Browse files
committed
handle safety lubbing correctly
1 parent e98be41 commit bce0933

File tree

15 files changed

+215
-189
lines changed

15 files changed

+215
-189
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

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

10741074
Rvalue::Cast(cast_kind, op, ty) => {
10751075
match *cast_kind {
1076-
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, coercion_source) => {
1076+
CastKind::PointerCoercion(
1077+
PointerCoercion::ReifyFnPointer(target_safety),
1078+
coercion_source,
1079+
) => {
10771080
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
10781081
let src_ty = op.ty(self.body, tcx);
10791082
let mut src_sig = src_ty.fn_sig(tcx);
@@ -1090,6 +1093,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10901093
src_sig = safe_sig;
10911094
}
10921095

1096+
if src_sig.safety().is_safe() && target_safety.is_unsafe() {
1097+
src_sig = tcx.safe_to_unsafe_sig(src_sig);
1098+
}
1099+
10931100
// HACK: This shouldn't be necessary... We can remove this when we actually
10941101
// get binders with where clauses, then elaborate implied bounds into that
10951102
// 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
@@ -670,7 +670,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
670670
lval.write_cvalue(fx, res);
671671
}
672672
Rvalue::Cast(
673-
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, _),
673+
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer(_), _),
674674
ref operand,
675675
to_ty,
676676
) => {

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)