summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_const_eval/src/const_eval/error.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /compiler/rustc_const_eval/src/const_eval/error.rs
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_const_eval/src/const_eval/error.rs')
-rw-r--r--compiler/rustc_const_eval/src/const_eval/error.rs39
1 files changed, 9 insertions, 30 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/error.rs b/compiler/rustc_const_eval/src/const_eval/error.rs
index d39a7e8a1..bf1e0a370 100644
--- a/compiler/rustc_const_eval/src/const_eval/error.rs
+++ b/compiler/rustc_const_eval/src/const_eval/error.rs
@@ -4,8 +4,7 @@ use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, IntoDiagnostic, IntoDi
use rustc_middle::mir::AssertKind;
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::{layout::LayoutError, ConstInt};
-use rustc_span::source_map::Spanned;
-use rustc_span::{ErrorGuaranteed, Span, Symbol};
+use rustc_span::{ErrorGuaranteed, Span, Symbol, DUMMY_SP};
use super::InterpCx;
use crate::errors::{self, FrameNote, ReportErrorExt};
@@ -18,7 +17,6 @@ pub enum ConstEvalErrKind {
ModifiedGlobal,
AssertFailure(AssertKind<ConstInt>),
Panic { msg: Symbol, line: u32, col: u32, file: Symbol },
- Abort(String),
}
impl MachineStopType for ConstEvalErrKind {
@@ -30,7 +28,6 @@ impl MachineStopType for ConstEvalErrKind {
ModifiedGlobal => const_eval_modified_global,
Panic { .. } => const_eval_panic,
AssertFailure(x) => x.diagnostic_message(),
- Abort(msg) => msg.to_string().into(),
}
}
fn add_args(
@@ -39,7 +36,7 @@ impl MachineStopType for ConstEvalErrKind {
) {
use ConstEvalErrKind::*;
match *self {
- ConstAccessesStatic | ModifiedGlobal | Abort(_) => {}
+ ConstAccessesStatic | ModifiedGlobal => {}
AssertFailure(kind) => kind.add_args(adder),
Panic { msg, line, col, file } => {
adder("msg".into(), msg.into_diagnostic_arg());
@@ -134,35 +131,17 @@ where
{
// Special handling for certain errors
match error {
- // Don't emit a new diagnostic for these errors
+ // Don't emit a new diagnostic for these errors, they are already reported elsewhere or
+ // should remain silent.
err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => {
- ErrorHandled::TooGeneric
+ ErrorHandled::TooGeneric(span.unwrap_or(DUMMY_SP))
}
- err_inval!(AlreadyReported(guar)) => ErrorHandled::Reported(guar),
+ err_inval!(AlreadyReported(guar)) => ErrorHandled::Reported(guar, span.unwrap_or(DUMMY_SP)),
err_inval!(Layout(LayoutError::ReferencesError(guar))) => {
- ErrorHandled::Reported(guar.into())
- }
- err_inval!(Layout(layout_error @ LayoutError::SizeOverflow(_))) => {
- // We must *always* hard error on these, even if the caller wants just a lint.
- // The `message` makes little sense here, this is a more serious error than the
- // caller thinks anyway.
- // See <https://github.com/rust-lang/rust/pull/63152>.
- let (our_span, frames) = get_span_and_frames();
- let span = span.unwrap_or(our_span);
- let mut err =
- tcx.sess.create_err(Spanned { span, node: layout_error.into_diagnostic() });
- err.code(rustc_errors::error_code!(E0080));
- let Some((mut err, handler)) = err.into_diagnostic() else {
- panic!("did not emit diag");
- };
- for frame in frames {
- err.eager_subdiagnostic(handler, frame);
- }
-
- ErrorHandled::Reported(handler.emit_diagnostic(&mut err).unwrap().into())
+ ErrorHandled::Reported(guar.into(), span.unwrap_or(DUMMY_SP))
}
+ // Report remaining errors.
_ => {
- // Report as hard error.
let (our_span, frames) = get_span_and_frames();
let span = span.unwrap_or(our_span);
let err = mk(span, frames);
@@ -173,7 +152,7 @@ where
// Use *our* span to label the interp error
err.span_label(our_span, msg);
- ErrorHandled::Reported(err.emit().into())
+ ErrorHandled::Reported(err.emit().into(), span)
}
}
}