1
Fork 0

don't point at const usage site for resolution-time errors

also share the code that emits the actual error
This commit is contained in:
Ralf Jung 2023-09-11 23:09:11 +02:00
parent 89ac57db4d
commit 9ac8b363e3
47 changed files with 133 additions and 171 deletions

View file

@ -239,13 +239,6 @@ pub struct LongRunningWarn {
pub item_span: Span,
}
#[derive(Diagnostic)]
#[diag(const_eval_erroneous_constant)]
pub(crate) struct ErroneousConstUsed {
#[primary_span]
pub span: Span,
}
#[derive(Subdiagnostic)]
#[note(const_eval_non_const_impl)]
pub(crate) struct NonConstImplNote {

View file

@ -24,7 +24,7 @@ use super::{
MemPlaceMeta, Memory, MemoryKind, OpTy, Operand, Place, PlaceTy, Pointer, PointerArithmetic,
Projectable, Provenance, Scalar, StackPopJump,
};
use crate::errors::{self, ErroneousConstUsed};
use crate::errors;
use crate::util;
use crate::{fluent_generated as fluent, ReportErrorExt};
@ -1063,17 +1063,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
) -> Result<T, ErrorHandled> {
// Use a precise span for better cycle errors.
query(self.tcx.at(span.unwrap_or_else(|| self.cur_span()))).map_err(|err| {
match err {
ErrorHandled::Reported(err, reported_span) => {
// We trust the provided span more than the one that came out of the query.
let span = span.unwrap_or(reported_span);
if !err.is_tainted_by_errors() {
// To make it easier to figure out where this error comes from, also add a note at the current location.
self.tcx.sess.emit_note(ErroneousConstUsed { span });
}
}
ErrorHandled::TooGeneric(_) => {}
}
err.emit_note(*self.tcx);
err
})
}