1
Fork 0

Do not abort compilation when failing to normalize opaque types.

This commit is contained in:
Camille GILLOT 2022-09-11 11:22:47 +02:00
parent 7919ef0ec5
commit caefec955f
2 changed files with 43 additions and 11 deletions

View file

@ -101,6 +101,18 @@ pub trait InferCtxtExt<'tcx> {
} }
pub trait TypeErrCtxtExt<'tcx> { pub trait TypeErrCtxtExt<'tcx> {
fn build_overflow_error<T>(
&self,
predicate: &T,
span: Span,
suggest_increasing_limit: bool,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>
where
T: fmt::Display
+ TypeFoldable<'tcx>
+ Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>,
<T as Print<'tcx, FmtPrinter<'tcx, 'tcx>>>::Error: std::fmt::Debug;
fn report_overflow_error<T>( fn report_overflow_error<T>(
&self, &self,
predicate: &T, predicate: &T,
@ -478,6 +490,26 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
suggest_increasing_limit: bool, suggest_increasing_limit: bool,
mutate: impl FnOnce(&mut Diagnostic), mutate: impl FnOnce(&mut Diagnostic),
) -> ! ) -> !
where
T: fmt::Display
+ TypeFoldable<'tcx>
+ Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>,
<T as Print<'tcx, FmtPrinter<'tcx, 'tcx>>>::Error: std::fmt::Debug,
{
let mut err = self.build_overflow_error(predicate, span, suggest_increasing_limit);
mutate(&mut err);
err.emit();
self.tcx.sess.abort_if_errors();
bug!();
}
fn build_overflow_error<T>(
&self,
predicate: &T,
span: Span,
suggest_increasing_limit: bool,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>
where where
T: fmt::Display T: fmt::Display
+ TypeFoldable<'tcx> + TypeFoldable<'tcx>
@ -511,11 +543,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
self.suggest_new_overflow_limit(&mut err); self.suggest_new_overflow_limit(&mut err);
} }
mutate(&mut err); err
err.emit();
self.tcx.sess.abort_if_errors();
bug!();
} }
/// Reports that an overflow has occurred and halts compilation. We /// Reports that an overflow has occurred and halts compilation. We

View file

@ -216,12 +216,16 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
let substs = substs.try_fold_with(self)?; let substs = substs.try_fold_with(self)?;
let recursion_limit = self.tcx().recursion_limit(); let recursion_limit = self.tcx().recursion_limit();
if !recursion_limit.value_within_limit(self.anon_depth) { if !recursion_limit.value_within_limit(self.anon_depth) {
self.infcx.err_ctxt().report_overflow_error( // A closure or generator may have itself as in its upvars. This
&ty, // should be checked handled by the recursion check for opaque types,
self.cause.span, // but we may end up here before that check can happen. In that case,
true, // we delay a bug to mark the trip, and continue without revealing the
|_| {}, // opaque.
); self.infcx
.err_ctxt()
.build_overflow_error(&ty, self.cause.span, true)
.delay_as_bug();
return ty.try_super_fold_with(self);
} }
let generic_ty = self.tcx().bound_type_of(def_id); let generic_ty = self.tcx().bound_type_of(def_id);