@@ -29,7 +29,8 @@ use rustc_middle::ty::{self, InlineConstArgs, InlineConstArgsParts, RegionVid, T
29
29
use rustc_middle:: ty:: { GenericArgs , GenericArgsRef } ;
30
30
use rustc_middle:: { bug, span_bug} ;
31
31
use rustc_span:: symbol:: { kw, sym} ;
32
- use rustc_span:: Symbol ;
32
+ use rustc_span:: { ErrorGuaranteed , Symbol } ;
33
+ use std:: cell:: Cell ;
33
34
use std:: iter;
34
35
35
36
use crate :: renumber:: RegionCtxt ;
@@ -186,6 +187,10 @@ struct UniversalRegionIndices<'tcx> {
186
187
187
188
/// The vid assigned to `'static`. Used only for diagnostics.
188
189
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 > > ,
189
194
}
190
195
191
196
#[ derive( Debug , PartialEq ) ]
@@ -408,6 +413,10 @@ impl<'tcx> UniversalRegions<'tcx> {
408
413
}
409
414
}
410
415
}
416
+
417
+ pub fn tainted_by_errors ( & self ) -> Option < ErrorGuaranteed > {
418
+ self . indices . tainted_by_errors . get ( )
419
+ }
411
420
}
412
421
413
422
struct UniversalRegionsBuilder < ' cx , ' tcx > {
@@ -663,7 +672,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
663
672
let global_mapping = iter:: once ( ( tcx. lifetimes . re_static , fr_static) ) ;
664
673
let arg_mapping = iter:: zip ( identity_args. regions ( ) , fr_args. regions ( ) . map ( |r| r. as_var ( ) ) ) ;
665
674
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
+ }
667
680
}
668
681
669
682
fn compute_inputs_and_output (
@@ -868,7 +881,8 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
868
881
pub fn to_region_vid ( & self , r : ty:: Region < ' tcx > ) -> RegionVid {
869
882
if let ty:: ReVar ( ..) = * r {
870
883
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) ) ;
872
886
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
873
887
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
874
888
// errors are being emitted and 2) it leaves the happy path unaffected.
0 commit comments