From 70ea98633e44b1220e40c1e8bcdc82edcc18da77 Mon Sep 17 00:00:00 2001 From: nidnogg Date: Thu, 18 Aug 2022 02:11:52 -0300 Subject: Migrated Unallowed function pointer calls in interpreter/ops --- compiler/rustc_const_eval/src/errors.rs | 8 ++++++++ compiler/rustc_const_eval/src/transform/check_consts/ops.rs | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'compiler/rustc_const_eval') diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 1a0faad2c2c..728d890ca60 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -95,3 +95,11 @@ pub(crate) struct MaxNumNodesExceeded { pub span: Span, pub s: String, } + +#[derive(SessionDiagnostic)] +#[error(const_eval::unallowed_fn_pointer_call)] +pub(crate) struct UnallowedFnPointerCall { + #[primary_span] + pub span: Span, + pub kind: ConstContext, +} diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index c9cfc1f3f46..ba7f2d07277 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -25,7 +25,7 @@ use rustc_trait_selection::traits::SelectionContext; use super::ConstCx; use crate::errors::{ MutDerefErr, NonConstOpErr, PanicNonStrErr, RawPtrToIntErr, StaticAccessErr, - TransientMutBorrowErr, TransientMutBorrowErrRaw, + TransientMutBorrowErr, TransientMutBorrowErrRaw, UnallowedFnPointerCall, }; use crate::util::{call_kind, CallDesugaringKind, CallKind}; @@ -97,10 +97,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallIndirect { ccx: &ConstCx<'_, 'tcx>, span: Span, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { - ccx.tcx.sess.struct_span_err( - span, - &format!("function pointer calls are not allowed in {}s", ccx.const_kind()), - ) + ccx.tcx.sess.create_err(UnallowedFnPointerCall { span, kind: ccx.const_kind() }) } } -- cgit 1.4.1-3-g733a5