]> git.lizzy.rs Git - rust.git/commitdiff
Migrated Unallowed function pointer calls in interpreter/ops
authornidnogg <henriquevt98@gmail.com>
Thu, 18 Aug 2022 05:11:52 +0000 (02:11 -0300)
committernidnogg <henriquevt98@gmail.com>
Mon, 22 Aug 2022 02:22:51 +0000 (23:22 -0300)
compiler/rustc_const_eval/src/errors.rs
compiler/rustc_const_eval/src/transform/check_consts/ops.rs
compiler/rustc_error_messages/locales/en-US/const_eval.ftl

index 1a0faad2c2c55f34af9496f407d959dfa525777a..728d890ca60daf4cfcfc27ed805b971be2513465 100644 (file)
@@ -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,
+}
index c9cfc1f3f469c8f3ce3d5598a14e97f61cbea19f..ba7f2d072770d3cfc745c147df2c36419dfe8105 100644 (file)
@@ -25,7 +25,7 @@
 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 @@ fn build_error(
         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() })
     }
 }
 
index 37abbe321bd68a94dcdc56b665e831b028c52ae2..5bd41dffdb5d02cd94cda6523aab403511201dd2 100644 (file)
@@ -31,3 +31,5 @@ const_eval_transient_mut_borrow = mutable references are not allowed in {$kind}s
 const_eval_transient_mut_borrow_raw = raw mutable references are not allowed in {$kind}s
 
 const_evaL_max_num_nodes_exceeded = maximum number of nodes exceeded in constant {$s}
+
+const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in {$const_kind}s
\ No newline at end of file