@@ -20,7 +20,7 @@ use crate::ty::VarianceDiagInfo;
2020use crate :: type_check:: free_region_relations:: UniversalRegionRelations ;
2121use crate :: type_check:: { Locations , MirTypeckRegionConstraints } ;
2222use crate :: universal_regions:: UniversalRegions ;
23- use crate :: { BorrowckInferCtxt , NllRegionVariableOrigin , bug } ;
23+ use crate :: { BorrowckInferCtxt , NllRegionVariableOrigin } ;
2424
2525/// A set of outlives constraints after rewriting to remove
2626/// higher-kinded constraints.
@@ -188,13 +188,23 @@ impl RegionTracker {
188188 /// the SCC itself.
189189 ///
190190 /// Returns *a* culprit (there may be more than one).
191- fn reaches_existential_that_cannot_name_us ( & self ) -> Option < RegionVid > {
191+ fn reaches_existential_that_cannot_name_us (
192+ & self ,
193+ region_definitions : & IndexVec < RegionVid , RegionDefinition < ' _ > > ,
194+ ) -> Option < RegionVid > {
192195 let Representative :: Placeholder ( _p) = self . representative else {
193196 return None ;
194197 } ;
195198
196199 let ( reachable_lowest_max_u, reachable_lowest_max_u_rvid) = self . max_nameable_universe ;
197200
201+ let NllRegionVariableOrigin :: Existential { .. } =
202+ region_definitions[ reachable_lowest_max_u_rvid] . origin
203+ else {
204+ debug ! ( "SCC universe wasn't lowered by an existential; skipping." ) ;
205+ return None ;
206+ } ;
207+
198208 ( !self . reachable_placeholders . can_be_named_by ( reachable_lowest_max_u) )
199209 . then_some ( reachable_lowest_max_u_rvid)
200210 }
@@ -442,19 +452,7 @@ fn rewrite_placeholder_outlives<'tcx>(
442452 variance_info : VarianceDiagInfo :: None ,
443453 from_closure : false ,
444454 } ) ;
445- } else if !( annotation. reaches_existential_that_cannot_name_us ( ) . is_some ( )
446- || annotation. reaches_other_placeholder ( annotation. representative . rvid ( ) ) . is_some ( ) )
447- {
448- // The SCC's representative is not nameable from some region
449- // that ends up in the SCC. This means there is nothing for us to do.
450- // However, this is only possible under circumstances that produce
451- // errors, so we make sure that we catch them here. Otherwise,
452- // there might actually be soundness issues!
453- bug ! (
454- "Universe of SCC {scc:?} should have been lowered by an existential or at least another placeholder but was lowered by {:?}, which is neither." ,
455- annotation. max_nameable_universe
456- ) ;
457- } ;
455+ }
458456 }
459457 added_constraints
460458}
@@ -486,12 +484,14 @@ fn find_placeholder_mismatch_errors<'tcx>(
486484 let scc = sccs. scc ( rvid) ;
487485 let annotation = annotations. scc_to_annotation [ scc] ;
488486
489- if let Some ( existential_that_cannot_name_rvid ) =
490- annotation. reaches_existential_that_cannot_name_us ( )
487+ if let Some ( cannot_name_rvid ) =
488+ annotation. reaches_existential_that_cannot_name_us ( definitions )
491489 {
490+ debug ! ( "Existential {cannot_name_rvid:?} lowered our universe..." ) ;
491+
492492 errors_buffer. push ( RegionErrorKind :: PlaceholderOutlivesExistentialThatCannotNameIt {
493493 longer_fr : rvid,
494- existential_that_cannot_name_longer : existential_that_cannot_name_rvid ,
494+ existential_that_cannot_name_longer : cannot_name_rvid ,
495495 placeholder : origin_a,
496496 } )
497497 }
0 commit comments