1- use crate :: infer:: free_regions:: FreeRegionMap ;
21use crate :: infer:: GenericKind ;
2+ use crate :: infer:: { free_regions:: FreeRegionMap , outlives:: explicit_outlives_bounds} ;
33use crate :: traits:: query:: OutlivesBound ;
44use rustc_data_structures:: fx:: FxIndexSet ;
55use rustc_data_structures:: transitive_relation:: TransitiveRelationBuilder ;
66use rustc_middle:: ty:: { self , Region } ;
77
8- use super :: explicit_outlives_bounds;
8+ pub struct RegionCheckingAssumptions < ' tcx > {
9+ pub param_env : ty:: ParamEnv < ' tcx > ,
10+ pub extra_bounds : FxIndexSet < OutlivesBound < ' tcx > > ,
11+ }
12+
13+ impl < ' tcx > RegionCheckingAssumptions < ' tcx > {
14+ /// Create a new `RegionCheckingAssumptions` without extra outlives bounds.
15+ pub fn new ( param_env : ty:: ParamEnv < ' tcx > ) -> RegionCheckingAssumptions < ' tcx > {
16+ RegionCheckingAssumptions { param_env, extra_bounds : Default :: default ( ) }
17+ }
18+
19+ /// Create a new `RegionCheckingAssumptions` with extra outlives bounds.
20+ pub fn with_bounds (
21+ param_env : ty:: ParamEnv < ' tcx > ,
22+ extra_bounds : impl IntoIterator < Item = OutlivesBound < ' tcx > > ,
23+ ) -> RegionCheckingAssumptions < ' tcx > {
24+ RegionCheckingAssumptions { param_env, extra_bounds : extra_bounds. into_iter ( ) . collect ( ) }
25+ }
26+ }
927
1028/// The `OutlivesEnvironment` collects information about what outlives
1129/// what in a given type-checking setting. For example, if we have a
@@ -28,7 +46,7 @@ use super::explicit_outlives_bounds;
2846/// interested in the `OutlivesEnvironment`. -nmatsakis
2947#[ derive( Clone ) ]
3048pub struct OutlivesEnvironment < ' tcx > {
31- pub param_env : ty:: ParamEnv < ' tcx > ,
49+ pub clauses : Vec < ty:: Clause < ' tcx > > ,
3250 free_region_map : FreeRegionMap < ' tcx > ,
3351
3452 // Contains the implied region bounds in scope for our current body.
@@ -54,8 +72,8 @@ pub struct OutlivesEnvironment<'tcx> {
5472
5573/// Builder of OutlivesEnvironment.
5674#[ derive( Debug ) ]
57- struct OutlivesEnvironmentBuilder < ' tcx > {
58- param_env : ty:: ParamEnv < ' tcx > ,
75+ pub struct OutlivesEnvironmentBuilder < ' tcx > {
76+ clauses : Vec < ty:: Clause < ' tcx > > ,
5977 region_relation : TransitiveRelationBuilder < Region < ' tcx > > ,
6078 region_bound_pairs : RegionBoundPairs < ' tcx > ,
6179}
@@ -68,32 +86,12 @@ pub type RegionBoundPairs<'tcx> =
6886
6987impl < ' tcx > OutlivesEnvironment < ' tcx > {
7088 /// Create a builder using `ParamEnv` and add explicit outlives bounds into it.
71- fn builder ( param_env : ty :: ParamEnv < ' tcx > ) -> OutlivesEnvironmentBuilder < ' tcx > {
72- let mut builder = OutlivesEnvironmentBuilder {
73- param_env ,
89+ pub fn builder ( ) -> OutlivesEnvironmentBuilder < ' tcx > {
90+ OutlivesEnvironmentBuilder {
91+ clauses : vec ! [ ] ,
7492 region_relation : Default :: default ( ) ,
7593 region_bound_pairs : Default :: default ( ) ,
76- } ;
77-
78- builder. add_outlives_bounds ( explicit_outlives_bounds ( param_env) ) ;
79-
80- builder
81- }
82-
83- #[ inline]
84- /// Create a new `OutlivesEnvironment` without extra outlives bounds.
85- pub fn new ( param_env : ty:: ParamEnv < ' tcx > ) -> Self {
86- Self :: builder ( param_env) . build ( )
87- }
88-
89- /// Create a new `OutlivesEnvironment` with extra outlives bounds.
90- pub fn with_bounds (
91- param_env : ty:: ParamEnv < ' tcx > ,
92- extra_bounds : impl IntoIterator < Item = OutlivesBound < ' tcx > > ,
93- ) -> Self {
94- let mut builder = Self :: builder ( param_env) ;
95- builder. add_outlives_bounds ( extra_bounds) ;
96- builder. build ( )
94+ }
9795 }
9896
9997 /// Borrows current value of the `free_region_map`.
@@ -110,16 +108,21 @@ impl<'tcx> OutlivesEnvironment<'tcx> {
110108impl < ' tcx > OutlivesEnvironmentBuilder < ' tcx > {
111109 #[ inline]
112110 #[ instrument( level = "debug" ) ]
113- fn build ( self ) -> OutlivesEnvironment < ' tcx > {
111+ pub fn build ( self ) -> OutlivesEnvironment < ' tcx > {
114112 OutlivesEnvironment {
115- param_env : self . param_env ,
113+ clauses : self . clauses ,
116114 free_region_map : FreeRegionMap { relation : self . region_relation . freeze ( ) } ,
117115 region_bound_pairs : self . region_bound_pairs ,
118116 }
119117 }
120118
119+ pub fn add_clauses ( & mut self , clauses : & [ ty:: Clause < ' tcx > ] ) {
120+ self . add_outlives_bounds ( explicit_outlives_bounds ( clauses) ) ;
121+ self . clauses . extend ( clauses. iter ( ) . copied ( ) ) ;
122+ }
123+
121124 /// Processes outlives bounds that are known to hold, whether from implied or other sources.
122- fn add_outlives_bounds < I > ( & mut self , outlives_bounds : I )
125+ pub fn add_outlives_bounds < I > ( & mut self , outlives_bounds : I )
123126 where
124127 I : IntoIterator < Item = OutlivesBound < ' tcx > > ,
125128 {
0 commit comments