From 33e8aaf830578d71ac55c6e612dbcff7aef766d2 Mon Sep 17 00:00:00 2001 From: nidnogg Date: Thu, 18 Aug 2022 22:49:59 -0300 Subject: Migration on ops.rs for unstable const functions --- compiler/rustc_const_eval/src/errors.rs | 8 ++++++++ compiler/rustc_const_eval/src/transform/check_consts/ops.rs | 8 +++----- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'compiler/rustc_const_eval/src') diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 728d890ca60..19e9e33ab80 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 ba7f2d07277..22d681fd336 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"); -- cgit 1.4.1-3-g733a5