Skip to content

Commit 46e3c4d

Browse files
committed
further cleanup and deduplication
1 parent 5064056 commit 46e3c4d

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{fmt, mem};
22

3-
use rustc_errors::Diag;
3+
use rustc_errors::{Diag, E0080};
44
use rustc_middle::mir::AssertKind;
55
use rustc_middle::mir::interpret::{
66
AllocId, Provenance, ReportedErrorInfo, UndefinedBehaviorInfo, UnsupportedOpInfo,
@@ -187,6 +187,7 @@ pub(super) fn report<'tcx>(
187187
_ => {
188188
let (span, frames) = super::get_span_and_frames(ecx.tcx, ecx.stack());
189189
let mut err = tcx.dcx().struct_span_err(span, error.to_string());
190+
err.code(E0080);
190191
if matches!(
191192
error,
192193
InterpErrorKind::UndefinedBehavior(UndefinedBehaviorInfo::ValidationError {

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::sync::atomic::Ordering::Relaxed;
22

33
use either::{Left, Right};
44
use rustc_abi::{self as abi, BackendRepr};
5-
use rustc_errors::{E0080, msg};
65
use rustc_hir::def::DefKind;
76
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo, ReportedErrorInfo};
87
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
@@ -460,23 +459,17 @@ fn report_eval_error<'tcx>(
460459

461460
super::report(ecx, error, |diag, span, frames| {
462461
let num_frames = frames.len();
463-
// FIXME(oli-obk): figure out how to use structured diagnostics again.
464-
diag.code(E0080);
465462
diag.span_label(
466463
span,
467-
msg!(
468-
"evaluation of `{$instance}` failed {$num_frames ->
469-
[0] here
470-
*[other] inside this call
471-
}"
464+
format!(
465+
"evaluation of `{instance}` failed {where_}",
466+
instance = with_no_trimmed_paths!(cid.instance.to_string()),
467+
where_ = if num_frames == 0 { "here" } else { "inside this call" },
472468
),
473469
);
474470
for frame in frames {
475471
diag.subdiagnostic(frame);
476472
}
477-
// Add after the frame rendering above, as it adds its own `instance` args.
478-
diag.arg("instance", with_no_trimmed_paths!(cid.instance.to_string()));
479-
diag.arg("num_frames", num_frames);
480473
})
481474
}
482475

@@ -501,13 +494,9 @@ fn report_validation_error<'tcx>(
501494
errors::RawBytesNote { size: info.size.bytes(), align: info.align.bytes(), bytes };
502495

503496
crate::const_eval::report(ecx, error, move |diag, span, frames| {
504-
// FIXME(oli-obk): figure out how to use structured diagnostics again.
505-
diag.code(E0080);
506497
diag.span_label(span, "it is undefined behavior to use this value");
507498
diag.note("the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.");
508-
for frame in frames {
509-
diag.subdiagnostic(frame);
510-
}
499+
assert!(frames.is_empty()); // we just report validation errors for the final const here
511500
diag.subdiagnostic(raw_bytes);
512501
})
513502
}

0 commit comments

Comments
 (0)