@@ -18,7 +18,7 @@ use rustc_middle::mir::{
1818} ;
1919use rustc_middle:: traits:: ObligationCause ;
2020use rustc_middle:: traits:: ObligationCauseCode ;
21- use rustc_middle:: ty:: { self , RegionVid , Ty , TyCtxt , TypeFoldable , TypeVisitableExt } ;
21+ use rustc_middle:: ty:: { self , RegionVid , Ty , TyCtxt , TypeFoldable } ;
2222use rustc_mir_dataflow:: points:: DenseLocationMap ;
2323use rustc_span:: Span ;
2424
@@ -1145,6 +1145,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11451145 }
11461146
11471147 let ty = ty. fold_with ( & mut OpaqueFolder { tcx } ) ;
1148+ let mut failed = false ;
11481149
11491150 let ty = tcx. fold_regions ( ty, |r, _depth| {
11501151 let r_vid = self . to_region_vid ( r) ;
@@ -1160,15 +1161,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11601161 . filter ( |& u_r| !self . universal_regions . is_local_free_region ( u_r) )
11611162 . find ( |& u_r| self . eval_equal ( u_r, r_vid) )
11621163 . map ( |u_r| ty:: Region :: new_var ( tcx, u_r) )
1163- // In the case of a failure, use `ReErased`. We will eventually
1164- // return `None` in this case.
1165- . unwrap_or ( tcx. lifetimes . re_erased )
1164+ // In case we could not find a named region to map to,
1165+ // we will return `None` below.
1166+ . unwrap_or_else ( || {
1167+ failed = true ;
1168+ r
1169+ } )
11661170 } ) ;
11671171
11681172 debug ! ( "try_promote_type_test_subject: folded ty = {:?}" , ty) ;
11691173
11701174 // This will be true if we failed to promote some region.
1171- if ty . has_erased_regions ( ) {
1175+ if failed {
11721176 return None ;
11731177 }
11741178
0 commit comments