Skip to content

Commit 33e8aaf

Browse files
committed
Migration on ops.rs for unstable const functions
1 parent 70ea986 commit 33e8aaf

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

compiler/rustc_const_eval/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,11 @@ pub(crate) struct UnallowedFnPointerCall {
103103
pub span: Span,
104104
pub kind: ConstContext,
105105
}
106+
107+
#[derive(SessionDiagnostic)]
108+
#[error(const_eval::unstable_const_fn)]
109+
pub(crate) struct UnstableConstFn {
110+
#[primary_span]
111+
pub span: Span,
112+
pub def_id: String,
113+
}

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

Lines changed: 3 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, UnallowedFnPointerCall,
28+
TransientMutBorrowErr, TransientMutBorrowErrRaw, UnallowedFnPointerCall, UnstableConstFn,
2929
};
3030
use crate::util::{call_kind, CallDesugaringKind, CallKind};
3131

@@ -351,10 +351,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
351351
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
352352
let FnCallUnstable(def_id, feature) = *self;
353353

354-
let mut err = ccx.tcx.sess.struct_span_err(
355-
span,
356-
&format!("`{}` is not yet stable as a const fn", ccx.tcx.def_path_str(def_id)),
357-
);
354+
let mut err =
355+
ccx.tcx.sess.create_err(UnstableConstFn { span, def_id: ccx.tcx.def_path_str(def_id) });
358356

359357
if ccx.is_const_stable_const_fn() {
360358
err.help("const-stable functions can only call other const-stable functions");

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ const_eval_transient_mut_borrow_raw = raw mutable references are not allowed in
3232
3333
const_evaL_max_num_nodes_exceeded = maximum number of nodes exceeded in constant {$s}
3434
35-
const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in {$const_kind}s
35+
const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in {$kind}s
36+
37+
const_eval_unstable_const_fn = `{$def_id}` is not yet stable as a const fn

0 commit comments

Comments
 (0)