@@ -83,6 +83,15 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
8383 let placeholder_indices = Default :: default ( ) ;
8484 let mut scc_values =
8585 RegionValues :: new ( location_map, universal_regions. len ( ) , placeholder_indices) ;
86+ for variable in definitions. indices ( ) {
87+ let scc = constraint_sccs. scc ( variable) ;
88+ match definitions[ variable] . origin {
89+ NllRegionVariableOrigin :: FreeRegion => {
90+ scc_values. add_element ( scc, variable) ;
91+ }
92+ _ => { }
93+ }
94+ }
8695 scc_values. propagate_constraints ( & constraint_sccs) ;
8796 for entry in & mut opaque_types {
8897 // Map all opaque types to their SCC representatives.
@@ -274,7 +283,8 @@ impl<'tcx> OpaqueHiddenTypeFolder<'_, 'tcx> {
274283 #[ instrument( level = "debug" , skip( self ) ) ]
275284 fn apply_member_constraint ( & mut self , member_vid : RegionVid ) -> Option < Region < ' tcx > > {
276285 let member = self . constraint_sccs . scc ( member_vid) ;
277- if let Some ( ( _, reg) ) = self . arg_regions . iter ( ) . copied ( ) . find ( |& ( vid, _) | vid == member_vid) {
286+ if let Some ( ( _, reg) ) = self . arg_regions . iter ( ) . copied ( ) . find ( |& ( vid, _) | vid == member_vid)
287+ {
278288 debug ! ( "member equal to arg" ) ;
279289 return Some ( reg) ;
280290 }
@@ -305,8 +315,14 @@ impl<'tcx> OpaqueHiddenTypeFolder<'_, 'tcx> {
305315 // free region that must outlive the member region `R0` (`UB:
306316 // R0`). Therefore, we need only keep an option `O` if `UB: O`
307317 // for all UB.
318+ //
319+ // If we have a requirement `'upper_bound: 'member`, equating `'member`
320+ // with some region `'choice` means we now also require `'upper_bound: 'choice`.
321+ // Avoid choice regions for which this does not hold.
308322 for ub in self . rev_scc_graph . upper_bounds ( member) {
309- choice_regions. retain ( |& ( o_r, _) | self . universal_region_relations . outlives ( ub, o_r) ) ;
323+ choice_regions. retain ( |& ( choice_region, _) | {
324+ self . universal_region_relations . outlives ( ub, choice_region)
325+ } ) ;
310326 }
311327
312328 debug ! ( ?choice_regions, "after enforcing upper-bound" ) ;
0 commit comments