@@ -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 } ;
23+ use crate :: { BorrowckInferCtxt , NllRegionVariableOrigin , bug } ;
2424
2525/// A set of outlives constraints after rewriting to remove
2626/// higher-kinded constraints.
@@ -178,12 +178,12 @@ impl RegionTracker {
178178 } )
179179 }
180180
181- /// Check for the second and final type of placeholder leak,
182- /// where a placeholder `'p` outlives (transitively) an existential `'e`
183- /// and `'e` cannot name `'p`. This is sort of a dual of `unnameable_placeholder`;
184- /// one of the members of this SCC cannot be named by the SCC .
181+ /// Check for placeholder leaks where a placeholder `'p` outlives (transitively)
182+ /// an existential `'e` and `'e` cannot name `'p`. This is sort of a dual of
183+ /// `unnameable_placeholder`; one of the members of this SCC cannot be named by
184+ /// the SCC itself .
185185 ///
186- /// Returns *a* culprit (though there may be more than one).
186+ /// Returns *a* culprit (there may be more than one).
187187 fn reaches_existential_that_cannot_name_us ( & self ) -> Option < RegionVid > {
188188 let Representative :: Placeholder ( _p) = self . representative else {
189189 return None ;
@@ -424,39 +424,33 @@ pub(crate) fn rewrite_placeholder_outlives<'tcx>(
424424 // That constraint is annotated with some placeholder `unnameable` where
425425 // `unnameable` is unnameable from `r` and there is a path in the constraint graph
426426 // between them.
427- //
428- // There is one exception; if some other region in this SCC can't name `'r`, then
429- // we pick the region with the smallest universe in the SCC, so that a path can
430- // always start in `'r` to find a motivation that isn't cyclic.
431- let blame_to = if annotation. representative . rvid ( ) == max_u_rvid {
432- // Assertion: the region that lowered our universe is an existential one and we are a placeholder!
433-
427+ if annotation. representative . rvid ( ) != max_u_rvid {
428+ // FIXME: if we can extract a useful blame span here, future error
429+ // reporting and constraint search can be simplified.
430+
431+ added_constraints = true ;
432+ outlives_constraints. push ( OutlivesConstraint {
433+ sup : annotation. representative . rvid ( ) ,
434+ sub : fr_static,
435+ category : ConstraintCategory :: OutlivesUnnameablePlaceholder ( max_u_rvid) ,
436+ locations : Locations :: All ( rustc_span:: DUMMY_SP ) ,
437+ span : rustc_span:: DUMMY_SP ,
438+ variance_info : VarianceDiagInfo :: None ,
439+ from_closure : false ,
440+ } ) ;
441+ } else if !( annotation. reaches_existential_that_cannot_name_us ( ) . is_some ( )
442+ || annotation. reaches_other_placeholder ( annotation. representative . rvid ( ) ) . is_some ( ) )
443+ {
434444 // The SCC's representative is not nameable from some region
435- // that ends up in the SCC.
436- let small_universed_rvid = annotation. max_nameable_universe . 1 ;
437- debug ! (
438- "{small_universed_rvid:?} lowered our universe to {:?}" ,
439- annotation. max_nameable_universe( )
445+ // that ends up in the SCC. This means there is nothing for us to do.
446+ // However, this is only possible under circumstances that produce
447+ // errors, so we make sure that we catch them here. Otherwise,
448+ // there might actually be soundness issues!
449+ bug ! (
450+ "Universe of SCC {scc:?} should have been lowered by an existential or at least another placeholder but was lowered by {:?}, which is neither." ,
451+ annotation. max_nameable_universe
440452 ) ;
441- small_universed_rvid
442- } else {
443- // `max_u_rvid` is not nameable by the SCC's representative.
444- max_u_rvid
445453 } ;
446-
447- // FIXME: if we can extract a useful blame span here, future error
448- // reporting and constraint search can be simplified.
449-
450- added_constraints = true ;
451- outlives_constraints. push ( OutlivesConstraint {
452- sup : annotation. representative . rvid ( ) ,
453- sub : fr_static,
454- category : ConstraintCategory :: OutlivesUnnameablePlaceholder ( blame_to) ,
455- locations : Locations :: All ( rustc_span:: DUMMY_SP ) ,
456- span : rustc_span:: DUMMY_SP ,
457- variance_info : VarianceDiagInfo :: None ,
458- from_closure : false ,
459- } ) ;
460454 }
461455 added_constraints
462456}
0 commit comments