Skip to content

Diagnostics migr const eval #100738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 27, 2022
Merged
Prev Previous commit
Next Next commit
Migration on ops.rs for unstable const functions
  • Loading branch information
nidnogg committed Aug 22, 2022
commit 33e8aaf830578d71ac55c6e612dbcff7aef766d2
8 changes: 8 additions & 0 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
8 changes: 3 additions & 5 deletions compiler/rustc_const_eval/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_error_messages/locales/en-US/const_eval.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
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