-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use the informative error as the main const eval error message #141698
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ use std::sync::atomic::Ordering::Relaxed; | |
|
||
use either::{Left, Right}; | ||
use rustc_abi::{self as abi, BackendRepr}; | ||
use rustc_errors::E0080; | ||
use rustc_hir::def::DefKind; | ||
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo, ReportedErrorInfo}; | ||
use rustc_middle::mir::{self, ConstAlloc, ConstValue}; | ||
|
@@ -290,12 +291,18 @@ pub fn eval_to_const_value_raw_provider<'tcx>( | |
|error| { | ||
let span = tcx.def_span(def_id); | ||
|
||
// FIXME(oli-obk): why don't we have any tests for this code path? | ||
super::report( | ||
tcx, | ||
error.into_kind(), | ||
span, | ||
|| (span, vec![]), | ||
|span, _| errors::NullaryIntrinsicError { span }, | ||
|diag, span, _| { | ||
diag.span_label( | ||
span, | ||
crate::fluent_generated::const_eval_nullary_intrinsic_fail, | ||
); | ||
}, | ||
) | ||
}, | ||
); | ||
|
@@ -443,11 +450,15 @@ fn report_eval_error<'tcx>( | |
error, | ||
DUMMY_SP, | ||
|| super::get_span_and_frames(ecx.tcx, ecx.stack()), | ||
|span, frames| errors::ConstEvalError { | ||
span, | ||
error_kind: kind, | ||
instance, | ||
frame_notes: frames, | ||
|diag, span, frames| { | ||
// FIXME(oli-obk): figure out how to use structured diagnostics again. | ||
diag.code(E0080); | ||
diag.span_label(span, crate::fluent_generated::const_eval_error); | ||
diag.arg("instance", instance); | ||
diag.arg("error_kind", kind); | ||
for frame in frames { | ||
diag.subdiagnostic(frame); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment explaining what we are doing here and why. Why is the error code now repeated in a bunch of places where it was central before? Seems like this is now doing by hand what previously was done by the derive macros for the diagnostic types? Is there no way to still use a diagnostic type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is, but not without the aforementioned refactoring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it because diagnostic error types need to have a single fixed primary message and can't read it from their fields or have it otherwise altered? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they can read it from their fields, but it needs work to set up as we can't just use the enums we have, or even just use a fluent identifier as a derive field. We'd have to eagerly format the error to a string, put that in a field and then make the derive just print that field. But that also needs a refactoring because the current logic isn't set up to do that |
||
}, | ||
) | ||
} | ||
|
@@ -477,6 +488,15 @@ fn report_validation_error<'tcx>( | |
error, | ||
DUMMY_SP, | ||
|| crate::const_eval::get_span_and_frames(ecx.tcx, ecx.stack()), | ||
move |span, frames| errors::ValidationFailure { span, ub_note: (), frames, raw_bytes }, | ||
move |diag, span, frames| { | ||
// FIXME(oli-obk): figure out how to use structured diagnostics again. | ||
diag.code(E0080); | ||
diag.span_label(span, crate::fluent_generated::const_eval_validation_failure); | ||
diag.note(crate::fluent_generated::const_eval_validation_failure_note); | ||
for frame in frames { | ||
diag.subdiagnostic(frame); | ||
} | ||
diag.subdiagnostic(raw_bytes); | ||
}, | ||
) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.