Skip to content

Commit 05f4924

Browse files
committed
Allow call const function pointer in const methods
1 parent 855eca0 commit 05f4924

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ impl<'tcx> PolyFnSig<'tcx> {
11791179
pub fn abi(&self) -> abi::Abi {
11801180
self.skip_binder().abi
11811181
}
1182+
pub fn constness(&self) -> hir::Constness { self.skip_binder().constness }
11821183
}
11831184

11841185
pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder<FnSig<'tcx>>>;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,10 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
745745
let (mut callee, substs) = match *fn_ty.kind() {
746746
ty::FnDef(def_id, substs) => (def_id, substs),
747747

748-
ty::FnPtr(_) => {
748+
ty::FnPtr(fn_sig) => {
749+
// At this point, we are calling a function by raw pointer because
750+
// we know that it is const
751+
if fn_sig.constness() == hir::Constness::Const { return; }
749752
self.check_op(ops::FnCallIndirect);
750753
return;
751754
}

0 commit comments

Comments
 (0)