11use crate :: infer:: free_regions:: FreeRegionMap ;
2- use crate :: infer:: { GenericKind , InferCtxt } ;
2+ use crate :: infer:: GenericKind ;
33use crate :: traits:: query:: OutlivesBound ;
44use rustc_data_structures:: fx:: FxIndexSet ;
55use rustc_data_structures:: transitive_relation:: TransitiveRelationBuilder ;
6- use rustc_middle:: ty:: { self , ReEarlyBound , ReFree , ReVar , Region } ;
6+ use rustc_middle:: ty:: { self , Region } ;
77
88use super :: explicit_outlives_bounds;
99
@@ -75,7 +75,7 @@ impl<'tcx> OutlivesEnvironment<'tcx> {
7575 region_bound_pairs : Default :: default ( ) ,
7676 } ;
7777
78- builder. add_outlives_bounds ( None , explicit_outlives_bounds ( param_env) ) ;
78+ builder. add_outlives_bounds ( explicit_outlives_bounds ( param_env) ) ;
7979
8080 builder
8181 }
@@ -89,11 +89,10 @@ impl<'tcx> OutlivesEnvironment<'tcx> {
8989 /// Create a new `OutlivesEnvironment` with extra outlives bounds.
9090 pub fn with_bounds (
9191 param_env : ty:: ParamEnv < ' tcx > ,
92- infcx : Option < & InferCtxt < ' tcx > > ,
9392 extra_bounds : impl IntoIterator < Item = OutlivesBound < ' tcx > > ,
9493 ) -> Self {
9594 let mut builder = Self :: builder ( param_env) ;
96- builder. add_outlives_bounds ( infcx , extra_bounds) ;
95+ builder. add_outlives_bounds ( extra_bounds) ;
9796 builder. build ( )
9897 }
9998
@@ -120,12 +119,7 @@ impl<'tcx> OutlivesEnvironmentBuilder<'tcx> {
120119 }
121120
122121 /// Processes outlives bounds that are known to hold, whether from implied or other sources.
123- ///
124- /// The `infcx` parameter is optional; if the implied bounds may
125- /// contain inference variables, it must be supplied, in which
126- /// case we will register "givens" on the inference context. (See
127- /// `RegionConstraintData`.)
128- fn add_outlives_bounds < I > ( & mut self , infcx : Option < & InferCtxt < ' tcx > > , outlives_bounds : I )
122+ fn add_outlives_bounds < I > ( & mut self , outlives_bounds : I )
129123 where
130124 I : IntoIterator < Item = OutlivesBound < ' tcx > > ,
131125 {
@@ -142,27 +136,17 @@ impl<'tcx> OutlivesEnvironmentBuilder<'tcx> {
142136 self . region_bound_pairs
143137 . insert ( ty:: OutlivesPredicate ( GenericKind :: Alias ( alias_b) , r_a) ) ;
144138 }
145- OutlivesBound :: RegionSubRegion ( r_a, r_b) => {
146- if let ( ReEarlyBound ( _) | ReFree ( _) , ReVar ( vid_b) ) = ( r_a. kind ( ) , r_b. kind ( ) ) {
147- infcx
148- . expect ( "no infcx provided but region vars found" )
149- . add_given ( r_a, vid_b) ;
150- } else {
151- // In principle, we could record (and take
152- // advantage of) every relationship here, but
153- // we are also free not to -- it simply means
154- // strictly less that we can successfully type
155- // check. Right now we only look for things
156- // relationships between free regions. (It may
157- // also be that we should revise our inference
158- // system to be more general and to make use
159- // of *every* relationship that arises here,
160- // but presently we do not.)
161- if r_a. is_free_or_static ( ) && r_b. is_free ( ) {
162- self . region_relation . add ( r_a, r_b)
163- }
164- }
165- }
139+ OutlivesBound :: RegionSubRegion ( r_a, r_b) => match ( * r_a, * r_b) {
140+ (
141+ ty:: ReStatic | ty:: ReEarlyBound ( _) | ty:: ReFree ( _) ,
142+ ty:: ReStatic | ty:: ReEarlyBound ( _) | ty:: ReFree ( _) ,
143+ ) => self . region_relation . add ( r_a, r_b) ,
144+ ( ty:: ReError ( _) , _) | ( _, ty:: ReError ( _) ) => { }
145+ // FIXME(#109628): We shouldn't have existential variables in implied bounds.
146+ // Panic here once the linked issue is resolved!
147+ ( ty:: ReVar ( _) , _) | ( _, ty:: ReVar ( _) ) => { }
148+ _ => bug ! ( "add_outlives_bounds: unexpected regions: ({r_a:?}, {r_b:?})" ) ,
149+ } ,
166150 }
167151 }
168152 }
0 commit comments