about summary refs log tree commit diff
diff options
context:
space:
mode:
authornidnogg <henriquevt98@gmail.com>2022-08-20 16:27:41 -0300
committernidnogg <henriquevt98@gmail.com>2022-08-21 23:22:55 -0300
commit4c82845b3ac583377b871bf01dc07ec513c466fe (patch)
treeededbf4ca5f0fb7512322e75dc7059e7fd28d489
parentd1f14ee1b01dd39cd79cd9cdd71e91ba521901fe (diff)
downloadrust-4c82845b3ac583377b871bf01dc07ec513c466fe.tar.gz
rust-4c82845b3ac583377b871bf01dc07ec513c466fe.zip
Fixed failing tests (missing labels), added automatic error code in create_feature_err() builder
-rw-r--r--compiler/rustc_const_eval/src/const_eval/mod.rs4
-rw-r--r--compiler/rustc_const_eval/src/errors.rs8
-rw-r--r--compiler/rustc_const_eval/src/transform/check_consts/ops.rs17
-rw-r--r--compiler/rustc_error_messages/locales/en-US/const_eval.ftl8
-rw-r--r--compiler/rustc_session/src/session.rs5
5 files changed, 17 insertions, 25 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs
index 57867f77a02..9041d55155e 100644
--- a/compiler/rustc_const_eval/src/const_eval/mod.rs
+++ b/compiler/rustc_const_eval/src/const_eval/mod.rs
@@ -1,6 +1,6 @@
 // Not in interpret to make sure we do not use private implementation details
 
-use crate::errors::MaxNumNodesExceeded;
+use crate::errors::MaxNumNodesInConstErr;
 use crate::interpret::{
     intern_const_alloc_recursive, ConstValue, InternKind, InterpCx, InterpResult, MemPlaceMeta,
     Scalar,
@@ -77,7 +77,7 @@ pub(crate) fn eval_to_valtree<'tcx>(
                 ValTreeCreationError::NodesOverflow => {
                     let msg = format!("maximum number of nodes exceeded in constant {}", &s);
                     let mut diag = match tcx.hir().span_if_local(did) {
-                        Some(span) => tcx.sess.create_err(MaxNumNodesExceeded { span, s }),
+                        Some(span) => tcx.sess.create_err(MaxNumNodesInConstErr { span, s }),
                         None => tcx.sess.struct_err(&msg),
                     };
                     diag.emit();
diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs
index 7fa6a67a7f9..7e1cf4ef1aa 100644
--- a/compiler/rustc_const_eval/src/errors.rs
+++ b/compiler/rustc_const_eval/src/errors.rs
@@ -89,8 +89,8 @@ pub(crate) struct TransientMutBorrowErrRaw {
 }
 
 #[derive(SessionDiagnostic)]
-#[error(const_eval::const_evaL_max_num_nodes_exceeded)]
-pub(crate) struct MaxNumNodesExceeded {
+#[error(const_eval::const_evaL_max_num_nodes_in_const_err)]
+pub(crate) struct MaxNumNodesInConstErr {
     #[primary_span]
     pub span: Span,
     pub s: String,
@@ -109,7 +109,7 @@ pub(crate) struct UnallowedFnPointerCall {
 pub(crate) struct UnstableConstFn {
     #[primary_span]
     pub span: Span,
-    pub def_id: String,
+    pub def_path: String,
 }
 
 #[derive(SessionDiagnostic)]
@@ -160,6 +160,7 @@ pub(crate) struct UnallowedOpInConstContext {
 #[error(const_eval::unallowed_heap_allocations, code = "E0010")]
 pub(crate) struct UnallowedHeapAllocations {
     #[primary_span]
+    #[label]
     pub span: Span,
     pub kind: ConstContext,
     #[note(const_eval::teach_note)]
@@ -178,6 +179,7 @@ pub(crate) struct UnallowedInlineAsm {
 #[error(const_eval::interior_mutable_data_refer, code = "E0492")]
 pub(crate) struct InteriorMutableDataRefer {
     #[primary_span]
+    #[label]
     pub span: Span,
     #[help]
     pub opt_help: Option<()>,
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 e2cf9b2b3c1..5fb4bf638b3 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs
@@ -345,8 +345,10 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
     ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
         let FnCallUnstable(def_id, feature) = *self;
 
-        let mut err =
-            ccx.tcx.sess.create_err(UnstableConstFn { span, def_id: ccx.tcx.def_path_str(def_id) });
+        let mut err = ccx
+            .tcx
+            .sess
+            .create_err(UnstableConstFn { span, def_path: 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");
@@ -517,17 +519,6 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
         ccx: &ConstCx<'_, 'tcx>,
         span: Span,
     ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
-        // let raw = match self.0 {
-        //     hir::BorrowKind::Raw => "raw ",
-        //     hir::BorrowKind::Ref => "",
-        // };
-
-        // ccx.tcx.sess.create_err(UnallowedMutableRefs {
-        //     span,
-        //     raw,
-        //     kind: ccx.const_kind(),
-        //     teach: ccx.tcx.sess.teach(&error_code!(E0764)).then_some(()),
-        // })
         match self.0 {
             hir::BorrowKind::Raw => ccx.tcx.sess.create_err(UnallowedMutableRefsRaw {
                 span,
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 24604869dd1..b8e4199dc1c 100644
--- a/compiler/rustc_error_messages/locales/en-US/const_eval.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/const_eval.ftl
@@ -30,11 +30,11 @@ const_eval_transient_mut_borrow = mutable references are not allowed in {$kind}s
 
 const_eval_transient_mut_borrow_raw = raw mutable references are not allowed in {$kind}s
 
-const_evaL_max_num_nodes_exceeded = maximum number of nodes exceeded in constant {$s}
+const_evaL_max_num_nodes_in_const_err = maximum number of nodes exceeded in constant {$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
+const_eval_unstable_const_fn = `{$def_path}` is not yet stable as a const fn
 
 const_eval_unallowed_mutable_refs =
     mutable references are not allowed in the final value of {$kind}s
@@ -65,9 +65,7 @@ const_eval_unallowed_heap_allocations =
     allocations are not allowed in {$kind}s
     .label = allocation not allowed in {$kind}s
     .teach_note = 
-        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.
+        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.
 
 const_eval_unallowed_inline_asm =
     inline assembly is not allowed in {$kind}s
diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs
index 80de451276c..743b9f429e2 100644
--- a/compiler/rustc_session/src/session.rs
+++ b/compiler/rustc_session/src/session.rs
@@ -20,8 +20,8 @@ use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
 use rustc_errors::json::JsonEmitter;
 use rustc_errors::registry::Registry;
 use rustc_errors::{
-    fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, EmissionGuarantee,
-    ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan,
+    error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
+    EmissionGuarantee, ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan,
 };
 use rustc_macros::HashStable_Generic;
 pub use rustc_span::def_id::StableCrateId;
@@ -467,6 +467,7 @@ impl Session {
         feature: Symbol,
     ) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
         let mut err = self.parse_sess.create_err(err);
+        err.code = std::option::Option::Some(error_code!(E0658));
         add_feature_diagnostics(&mut err, &self.parse_sess, feature);
         err
     }