Skip to content

Commit 70ea986

Browse files
committed
Migrated Unallowed function pointer calls in interpreter/ops
1 parent 6af8e46 commit 70ea986

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

compiler/rustc_const_eval/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,11 @@ pub(crate) struct MaxNumNodesExceeded {
9595
pub span: Span,
9696
pub s: String,
9797
}
98+
99+
#[derive(SessionDiagnostic)]
100+
#[error(const_eval::unallowed_fn_pointer_call)]
101+
pub(crate) struct UnallowedFnPointerCall {
102+
#[primary_span]
103+
pub span: Span,
104+
pub kind: ConstContext,
105+
}

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_trait_selection::traits::SelectionContext;
2525
use super::ConstCx;
2626
use crate::errors::{
2727
MutDerefErr, NonConstOpErr, PanicNonStrErr, RawPtrToIntErr, StaticAccessErr,
28-
TransientMutBorrowErr, TransientMutBorrowErrRaw,
28+
TransientMutBorrowErr, TransientMutBorrowErrRaw, UnallowedFnPointerCall,
2929
};
3030
use crate::util::{call_kind, CallDesugaringKind, CallKind};
3131

@@ -97,10 +97,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
9797
ccx: &ConstCx<'_, 'tcx>,
9898
span: Span,
9999
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
100-
ccx.tcx.sess.struct_span_err(
101-
span,
102-
&format!("function pointer calls are not allowed in {}s", ccx.const_kind()),
103-
)
100+
ccx.tcx.sess.create_err(UnallowedFnPointerCall { span, kind: ccx.const_kind() })
104101
}
105102
}
106103

compiler/rustc_error_messages/locales/en-US/const_eval.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ const_eval_transient_mut_borrow = mutable references are not allowed in {$kind}s
3131
const_eval_transient_mut_borrow_raw = raw mutable references are not allowed in {$kind}s
3232
3333
const_evaL_max_num_nodes_exceeded = maximum number of nodes exceeded in constant {$s}
34+
35+
const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in {$const_kind}s

0 commit comments

Comments
 (0)