From 33e8aaf830578d71ac55c6e612dbcff7aef766d2 Mon Sep 17 00:00:00 2001 From: nidnogg Date: Thu, 18 Aug 2022 22:49:59 -0300 Subject: [PATCH] Migration on ops.rs for unstable const functions --- compiler/rustc_const_eval/src/errors.rs | 8 ++++++++ .../rustc_const_eval/src/transform/check_consts/ops.rs | 8 +++----- .../rustc_error_messages/locales/en-US/const_eval.ftl | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 728d890ca60d..19e9e33ab800 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -103,3 +103,11 @@ pub(crate) struct UnallowedFnPointerCall { pub span: Span, pub kind: ConstContext, } + +#[derive(SessionDiagnostic)] +#[error(const_eval::unstable_const_fn)] +pub(crate) struct UnstableConstFn { + #[primary_span] + pub span: Span, + pub def_id: String, +} 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 ba7f2d072770..22d681fd3367 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, UnallowedFnPointerCall, + TransientMutBorrowErr, TransientMutBorrowErrRaw, UnallowedFnPointerCall, UnstableConstFn, }; use crate::util::{call_kind, CallDesugaringKind, CallKind}; @@ -351,10 +351,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable { ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { let FnCallUnstable(def_id, feature) = *self; - let mut err = ccx.tcx.sess.struct_span_err( - span, - &format!("`{}` is not yet stable as a const fn", ccx.tcx.def_path_str(def_id)), - ); + let mut err = + ccx.tcx.sess.create_err(UnstableConstFn { span, def_id: ccx.tcx.def_path_str(def_id) }); if ccx.is_const_stable_const_fn() { err.help("const-stable functions can only call other const-stable functions"); diff --git a/compiler/rustc_error_messages/locales/en-US/const_eval.ftl b/compiler/rustc_error_messages/locales/en-US/const_eval.ftl index 5bd41dffdb5d..a9d9838a3824 100644 --- a/compiler/rustc_error_messages/locales/en-US/const_eval.ftl +++ b/compiler/rustc_error_messages/locales/en-US/const_eval.ftl @@ -32,4 +32,6 @@ const_eval_transient_mut_borrow_raw = raw mutable references are not allowed in 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 +const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in {$kind}s + +const_eval_unstable_const_fn = `{$def_id}` is not yet stable as a const fn \ No newline at end of file