@@ -20,7 +20,7 @@ use crate::ty::VarianceDiagInfo;
20
20
use crate :: type_check:: free_region_relations:: UniversalRegionRelations ;
21
21
use crate :: type_check:: { Locations , MirTypeckRegionConstraints } ;
22
22
use crate :: universal_regions:: UniversalRegions ;
23
- use crate :: { BorrowckInferCtxt , NllRegionVariableOrigin } ;
23
+ use crate :: { BorrowckInferCtxt , NllRegionVariableOrigin , bug } ;
24
24
25
25
/// A set of outlives constraints after rewriting to remove
26
26
/// higher-kinded constraints.
@@ -178,12 +178,12 @@ impl RegionTracker {
178
178
} )
179
179
}
180
180
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 .
185
185
///
186
- /// Returns *a* culprit (though there may be more than one).
186
+ /// Returns *a* culprit (there may be more than one).
187
187
fn reaches_existential_that_cannot_name_us ( & self ) -> Option < RegionVid > {
188
188
let Representative :: Placeholder ( _p) = self . representative else {
189
189
return None ;
@@ -424,39 +424,33 @@ fn rewrite_placeholder_outlives<'tcx>(
424
424
// That constraint is annotated with some placeholder `unnameable` where
425
425
// `unnameable` is unnameable from `r` and there is a path in the constraint graph
426
426
// 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
+ {
434
444
// 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
440
452
) ;
441
- small_universed_rvid
442
- } else {
443
- // `max_u_rvid` is not nameable by the SCC's representative.
444
- max_u_rvid
445
453
} ;
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
- } ) ;
460
454
}
461
455
added_constraints
462
456
}
0 commit comments