@@ -29,7 +29,8 @@ use rustc_middle::ty::{self, InlineConstArgs, InlineConstArgsParts, RegionVid, T
2929use rustc_middle:: ty:: { GenericArgs , GenericArgsRef } ;
3030use rustc_middle:: { bug, span_bug} ;
3131use rustc_span:: symbol:: { kw, sym} ;
32- use rustc_span:: Symbol ;
32+ use rustc_span:: { ErrorGuaranteed , Symbol } ;
33+ use std:: cell:: Cell ;
3334use std:: iter;
3435
3536use crate :: renumber:: RegionCtxt ;
@@ -186,6 +187,10 @@ struct UniversalRegionIndices<'tcx> {
186187
187188 /// The vid assigned to `'static`. Used only for diagnostics.
188189 pub fr_static : RegionVid ,
190+
191+ /// Whether we've encountered an error region. If we have, cancel all
192+ /// outlives errors, as they are likely bogus.
193+ pub tainted_by_errors : Cell < Option < ErrorGuaranteed > > ,
189194}
190195
191196#[ derive( Debug , PartialEq ) ]
@@ -408,6 +413,10 @@ impl<'tcx> UniversalRegions<'tcx> {
408413 }
409414 }
410415 }
416+
417+ pub fn tainted_by_errors ( & self ) -> Option < ErrorGuaranteed > {
418+ self . indices . tainted_by_errors . get ( )
419+ }
411420}
412421
413422struct UniversalRegionsBuilder < ' cx , ' tcx > {
@@ -663,7 +672,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
663672 let global_mapping = iter:: once ( ( tcx. lifetimes . re_static , fr_static) ) ;
664673 let arg_mapping = iter:: zip ( identity_args. regions ( ) , fr_args. regions ( ) . map ( |r| r. as_var ( ) ) ) ;
665674
666- UniversalRegionIndices { indices : global_mapping. chain ( arg_mapping) . collect ( ) , fr_static }
675+ UniversalRegionIndices {
676+ indices : global_mapping. chain ( arg_mapping) . collect ( ) ,
677+ fr_static,
678+ tainted_by_errors : Cell :: new ( None ) ,
679+ }
667680 }
668681
669682 fn compute_inputs_and_output (
@@ -868,7 +881,8 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
868881 pub fn to_region_vid ( & self , r : ty:: Region < ' tcx > ) -> RegionVid {
869882 if let ty:: ReVar ( ..) = * r {
870883 r. as_var ( )
871- } else if r. is_error ( ) {
884+ } else if let ty:: ReError ( guar) = * r {
885+ self . tainted_by_errors . set ( Some ( guar) ) ;
872886 // We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
873887 // `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
874888 // errors are being emitted and 2) it leaves the happy path unaffected.
0 commit comments