Skip to content

Commit 4c82845

Browse files
committed
Fixed failing tests (missing labels), added automatic error code in create_feature_err() builder
1 parent d1f14ee commit 4c82845

File tree

5 files changed

+17
-25
lines changed

5 files changed

+17
-25
lines changed

compiler/rustc_const_eval/src/const_eval/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Not in interpret to make sure we do not use private implementation details
22

3-
use crate::errors::MaxNumNodesExceeded;
3+
use crate::errors::MaxNumNodesInConstErr;
44
use crate::interpret::{
55
intern_const_alloc_recursive, ConstValue, InternKind, InterpCx, InterpResult, MemPlaceMeta,
66
Scalar,
@@ -77,7 +77,7 @@ pub(crate) fn eval_to_valtree<'tcx>(
7777
ValTreeCreationError::NodesOverflow => {
7878
let msg = format!("maximum number of nodes exceeded in constant {}", &s);
7979
let mut diag = match tcx.hir().span_if_local(did) {
80-
Some(span) => tcx.sess.create_err(MaxNumNodesExceeded { span, s }),
80+
Some(span) => tcx.sess.create_err(MaxNumNodesInConstErr { span, s }),
8181
None => tcx.sess.struct_err(&msg),
8282
};
8383
diag.emit();

compiler/rustc_const_eval/src/errors.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ pub(crate) struct TransientMutBorrowErrRaw {
8989
}
9090

9191
#[derive(SessionDiagnostic)]
92-
#[error(const_eval::const_evaL_max_num_nodes_exceeded)]
93-
pub(crate) struct MaxNumNodesExceeded {
92+
#[error(const_eval::const_evaL_max_num_nodes_in_const_err)]
93+
pub(crate) struct MaxNumNodesInConstErr {
9494
#[primary_span]
9595
pub span: Span,
9696
pub s: String,
@@ -109,7 +109,7 @@ pub(crate) struct UnallowedFnPointerCall {
109109
pub(crate) struct UnstableConstFn {
110110
#[primary_span]
111111
pub span: Span,
112-
pub def_id: String,
112+
pub def_path: String,
113113
}
114114

115115
#[derive(SessionDiagnostic)]
@@ -160,6 +160,7 @@ pub(crate) struct UnallowedOpInConstContext {
160160
#[error(const_eval::unallowed_heap_allocations, code = "E0010")]
161161
pub(crate) struct UnallowedHeapAllocations {
162162
#[primary_span]
163+
#[label]
163164
pub span: Span,
164165
pub kind: ConstContext,
165166
#[note(const_eval::teach_note)]
@@ -178,6 +179,7 @@ pub(crate) struct UnallowedInlineAsm {
178179
#[error(const_eval::interior_mutable_data_refer, code = "E0492")]
179180
pub(crate) struct InteriorMutableDataRefer {
180181
#[primary_span]
182+
#[label]
181183
pub span: Span,
182184
#[help]
183185
pub opt_help: Option<()>,

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

+4-13
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,10 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
345345
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
346346
let FnCallUnstable(def_id, feature) = *self;
347347

348-
let mut err =
349-
ccx.tcx.sess.create_err(UnstableConstFn { span, def_id: ccx.tcx.def_path_str(def_id) });
348+
let mut err = ccx
349+
.tcx
350+
.sess
351+
.create_err(UnstableConstFn { span, def_path: ccx.tcx.def_path_str(def_id) });
350352

351353
if ccx.is_const_stable_const_fn() {
352354
err.help("const-stable functions can only call other const-stable functions");
@@ -517,17 +519,6 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
517519
ccx: &ConstCx<'_, 'tcx>,
518520
span: Span,
519521
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
520-
// let raw = match self.0 {
521-
// hir::BorrowKind::Raw => "raw ",
522-
// hir::BorrowKind::Ref => "",
523-
// };
524-
525-
// ccx.tcx.sess.create_err(UnallowedMutableRefs {
526-
// span,
527-
// raw,
528-
// kind: ccx.const_kind(),
529-
// teach: ccx.tcx.sess.teach(&error_code!(E0764)).then_some(()),
530-
// })
531522
match self.0 {
532523
hir::BorrowKind::Raw => ccx.tcx.sess.create_err(UnallowedMutableRefsRaw {
533524
span,

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ const_eval_transient_mut_borrow = mutable references are not allowed in {$kind}s
3030
3131
const_eval_transient_mut_borrow_raw = raw mutable references are not allowed in {$kind}s
3232
33-
const_evaL_max_num_nodes_exceeded = maximum number of nodes exceeded in constant {$s}
33+
const_evaL_max_num_nodes_in_const_err = maximum number of nodes exceeded in constant {$s}
3434
3535
const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in {$kind}s
3636
37-
const_eval_unstable_const_fn = `{$def_id}` is not yet stable as a const fn
37+
const_eval_unstable_const_fn = `{$def_path}` is not yet stable as a const fn
3838
3939
const_eval_unallowed_mutable_refs =
4040
mutable references are not allowed in the final value of {$kind}s
@@ -65,9 +65,7 @@ const_eval_unallowed_heap_allocations =
6565
allocations are not allowed in {$kind}s
6666
.label = allocation not allowed in {$kind}s
6767
.teach_note =
68-
The value of statics and constants must be known at compile time, and they live for the entire
69-
lifetime of a program. Creating a boxed value allocates memory on the heap at runtime, and
70-
therefore cannot be done at compile time.
68+
The value of statics and constants must be known at compile time, and they live for the entire lifetime of a program. Creating a boxed value allocates memory on the heap at runtime, and therefore cannot be done at compile time.
7169
7270
const_eval_unallowed_inline_asm =
7371
inline assembly is not allowed in {$kind}s

compiler/rustc_session/src/session.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
2020
use rustc_errors::json::JsonEmitter;
2121
use rustc_errors::registry::Registry;
2222
use rustc_errors::{
23-
fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, EmissionGuarantee,
24-
ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan,
23+
error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
24+
EmissionGuarantee, ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan,
2525
};
2626
use rustc_macros::HashStable_Generic;
2727
pub use rustc_span::def_id::StableCrateId;
@@ -467,6 +467,7 @@ impl Session {
467467
feature: Symbol,
468468
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
469469
let mut err = self.parse_sess.create_err(err);
470+
err.code = std::option::Option::Some(error_code!(E0658));
470471
add_feature_diagnostics(&mut err, &self.parse_sess, feature);
471472
err
472473
}

0 commit comments

Comments
 (0)