Skip to content

Commit d72e63b

Browse files
committed
Check const_fn_pointer feature in mir context
1 parent 80ef1af commit d72e63b

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
218218
_ => bug!("{} cannot be cast to a fn ptr", operand.layout.ty),
219219
}
220220
}
221-
mir::CastKind::Pointer(PointerCast::UnsafeFnPointer) => {
222-
// This is a no-op at the LLVM level.
223-
operand.val
224-
}
225-
mir::CastKind::Pointer(PointerCast::NotConstFnPointer) => {
221+
mir::CastKind::Pointer(
222+
PointerCast::UnsafeFnPointer
223+
| PointerCast::NotConstFnPointer
224+
| PointerCast::UnsafeNotConstFnPointer,
225+
) => {
226226
// This is a no-op at the LLVM level.
227227
operand.val
228228
}
229-
mir::CastKind::Pointer(PointerCast::UnsafeNotConstFnPointer) => {
230-
// This is a no-op at the LLVM level
231-
operand.val
232-
}
233229
mir::CastKind::Pointer(PointerCast::Unsize) => {
234230
assert!(bx.cx().is_backend_scalar_pair(cast));
235231
match operand.val {

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,15 +2340,16 @@ impl<'tcx> ty::Instance<'tcx> {
23402340

23412341
let env_ty = tcx.closure_env_ty(def_id, substs).unwrap();
23422342

2343-
sig.map_bound(|sig|
2344-
tcx.mk_fn_sig(
2345-
iter::once(env_ty.skip_binder()).chain(sig.inputs().iter().cloned()),
2346-
sig.output(),
2347-
sig.c_variadic,
2348-
sig.unsafety,
2349-
sig.abi,
2350-
hir::Constness::NotConst,
2351-
))
2343+
sig.map_bound(|sig| {
2344+
tcx.mk_fn_sig(
2345+
iter::once(env_ty.skip_binder()).chain(sig.inputs().iter().cloned()),
2346+
sig.output(),
2347+
sig.c_variadic,
2348+
sig.unsafety,
2349+
sig.abi,
2350+
hir::Constness::NotConst,
2351+
)
2352+
})
23522353
}
23532354
ty::Generator(_, substs, _) => {
23542355
let sig = substs.as_generator().poly_sig();

compiler/rustc_mir/src/transform/check_consts/validation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,8 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
748748
ty::FnPtr(fn_sig) => {
749749
// At this point, we are calling a function by raw pointer because
750750
// we know that it is const
751-
if fn_sig.constness() == hir::Constness::Const {
751+
if self.ccx.tcx.features().const_fn_pointer &&
752+
fn_sig.constness() == hir::Constness::Const {
752753
return;
753754
}
754755
self.check_op(ops::FnCallIndirect);

0 commit comments

Comments
 (0)