Skip to content

Commit 76bd21a

Browse files
committed
account for safe target features in fndef<->closure and fndef<->fndef coerce-lubs
1 parent 2676c93 commit 76bd21a

File tree

23 files changed

+266
-229
lines changed

23 files changed

+266
-229
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

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

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

1084+
if src_sig.safety().is_safe() && target_safety.is_unsafe() {
1085+
src_sig = tcx.safe_to_unsafe_sig(src_sig);
1086+
}
1087+
10811088
// HACK: This shouldn't be necessary... We can remove this when we actually
10821089
// get binders with where clauses, then elaborate implied bounds into that
10831090
// 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
@@ -689,7 +689,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
689689
lval.write_cvalue(fx, res);
690690
}
691691
Rvalue::Cast(
692-
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, _),
692+
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer(_), _),
693693
ref operand,
694694
to_ty,
695695
) => {

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
405405
let lladdr = bx.ptrtoint(llptr, llcast_ty);
406406
OperandValue::Immediate(lladdr)
407407
}
408-
mir::CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, _) => {
408+
mir::CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer(_), _) => {
409409
match *operand.layout.ty.kind() {
410410
ty::FnDef(def_id, args) => {
411411
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)