fix ICE on type error in promoted
This commit is contained in:
parent
9c707a8b76
commit
ed8ee39930
25 changed files with 78 additions and 213 deletions
|
@ -8,6 +8,7 @@ use rustc_session::config::RemapPathScopeComponents;
|
|||
use rustc_span::{DUMMY_SP, Span};
|
||||
use rustc_type_ir::visit::TypeVisitableExt;
|
||||
|
||||
use super::interpret::ReportedErrorInfo;
|
||||
use crate::mir::interpret::{AllocId, ConstAllocation, ErrorHandled, Scalar, alloc_range};
|
||||
use crate::mir::{Promoted, pretty_print_const_value};
|
||||
use crate::ty::print::{pretty_print_const, with_no_trimmed_paths};
|
||||
|
@ -331,7 +332,10 @@ impl<'tcx> Const<'tcx> {
|
|||
ConstKind::Expr(_) => {
|
||||
bug!("Normalization of `ty::ConstKind::Expr` is unimplemented")
|
||||
}
|
||||
_ => Err(tcx.dcx().delayed_bug("Unevaluated `ty::Const` in MIR body").into()),
|
||||
_ => Err(ReportedErrorInfo::non_const_eval_error(
|
||||
tcx.dcx().delayed_bug("Unevaluated `ty::Const` in MIR body"),
|
||||
)
|
||||
.into()),
|
||||
}
|
||||
}
|
||||
Const::Unevaluated(uneval, _) => {
|
||||
|
|
|
@ -28,10 +28,10 @@ pub enum ErrorHandled {
|
|||
TooGeneric(Span),
|
||||
}
|
||||
|
||||
impl From<ErrorGuaranteed> for ErrorHandled {
|
||||
impl From<ReportedErrorInfo> for ErrorHandled {
|
||||
#[inline]
|
||||
fn from(error: ErrorGuaranteed) -> ErrorHandled {
|
||||
ErrorHandled::Reported(error.into(), DUMMY_SP)
|
||||
fn from(error: ReportedErrorInfo) -> ErrorHandled {
|
||||
ErrorHandled::Reported(error, DUMMY_SP)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,20 @@ pub struct ReportedErrorInfo {
|
|||
}
|
||||
|
||||
impl ReportedErrorInfo {
|
||||
#[inline]
|
||||
pub fn const_eval_error(error: ErrorGuaranteed) -> ReportedErrorInfo {
|
||||
ReportedErrorInfo { allowed_in_infallible: false, error }
|
||||
}
|
||||
|
||||
/// Use this when the error that led to this is *not* a const-eval error
|
||||
/// (e.g., a layout or type checking error).
|
||||
#[inline]
|
||||
pub fn non_const_eval_error(error: ErrorGuaranteed) -> ReportedErrorInfo {
|
||||
ReportedErrorInfo { allowed_in_infallible: true, error }
|
||||
}
|
||||
|
||||
/// Use this when the error that led to this *is* a const-eval error, but
|
||||
/// we do allow it to occur in infallible constants (e.g., resource exhaustion).
|
||||
#[inline]
|
||||
pub fn allowed_in_infallible(error: ErrorGuaranteed) -> ReportedErrorInfo {
|
||||
ReportedErrorInfo { allowed_in_infallible: true, error }
|
||||
|
@ -74,13 +88,6 @@ impl ReportedErrorInfo {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<ErrorGuaranteed> for ReportedErrorInfo {
|
||||
#[inline]
|
||||
fn from(error: ErrorGuaranteed) -> ReportedErrorInfo {
|
||||
ReportedErrorInfo { allowed_in_infallible: false, error }
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<ErrorGuaranteed> for ReportedErrorInfo {
|
||||
#[inline]
|
||||
fn into(self) -> ErrorGuaranteed {
|
||||
|
@ -180,12 +187,6 @@ fn print_backtrace(backtrace: &Backtrace) {
|
|||
eprintln!("\n\nAn error occurred in the MIR interpreter:\n{backtrace}");
|
||||
}
|
||||
|
||||
impl From<ErrorGuaranteed> for InterpErrorInfo<'_> {
|
||||
fn from(err: ErrorGuaranteed) -> Self {
|
||||
InterpErrorKind::InvalidProgram(InvalidProgramInfo::AlreadyReported(err.into())).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorHandled> for InterpErrorInfo<'_> {
|
||||
fn from(err: ErrorHandled) -> Self {
|
||||
InterpErrorKind::InvalidProgram(match err {
|
||||
|
|
|
@ -6,6 +6,7 @@ use tracing::{debug, instrument};
|
|||
|
||||
use super::{
|
||||
ErrorHandled, EvalToAllocationRawResult, EvalToConstValueResult, EvalToValTreeResult, GlobalId,
|
||||
ReportedErrorInfo,
|
||||
};
|
||||
use crate::mir;
|
||||
use crate::query::TyCtxtEnsure;
|
||||
|
@ -81,7 +82,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
// For errors during resolution, we deliberately do not point at the usage site of the constant,
|
||||
// since for these errors the place the constant is used shouldn't matter.
|
||||
Ok(None) => Err(ErrorHandled::TooGeneric(DUMMY_SP)),
|
||||
Err(err) => Err(ErrorHandled::Reported(err.into(), DUMMY_SP)),
|
||||
Err(err) => {
|
||||
Err(ErrorHandled::Reported(ReportedErrorInfo::non_const_eval_error(err), DUMMY_SP))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,7 +141,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
// For errors during resolution, we deliberately do not point at the usage site of the constant,
|
||||
// since for these errors the place the constant is used shouldn't matter.
|
||||
Ok(None) => Err(ErrorHandled::TooGeneric(DUMMY_SP)),
|
||||
Err(err) => Err(ErrorHandled::Reported(err.into(), DUMMY_SP)),
|
||||
Err(err) => {
|
||||
Err(ErrorHandled::Reported(ReportedErrorInfo::non_const_eval_error(err), DUMMY_SP))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue