1
- use crate :: infer:: free_regions:: FreeRegionMap ;
2
1
use crate :: infer:: GenericKind ;
2
+ use crate :: infer:: { free_regions:: FreeRegionMap , outlives:: explicit_outlives_bounds} ;
3
3
use crate :: traits:: query:: OutlivesBound ;
4
4
use rustc_data_structures:: fx:: FxIndexSet ;
5
5
use rustc_data_structures:: transitive_relation:: TransitiveRelationBuilder ;
6
6
use rustc_middle:: ty:: { self , Region } ;
7
7
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
+ }
9
27
10
28
/// The `OutlivesEnvironment` collects information about what outlives
11
29
/// what in a given type-checking setting. For example, if we have a
@@ -28,7 +46,7 @@ use super::explicit_outlives_bounds;
28
46
/// interested in the `OutlivesEnvironment`. -nmatsakis
29
47
#[ derive( Clone ) ]
30
48
pub struct OutlivesEnvironment < ' tcx > {
31
- pub param_env : ty:: ParamEnv < ' tcx > ,
49
+ pub clauses : Vec < ty:: Clause < ' tcx > > ,
32
50
free_region_map : FreeRegionMap < ' tcx > ,
33
51
34
52
// Contains the implied region bounds in scope for our current body.
@@ -54,8 +72,8 @@ pub struct OutlivesEnvironment<'tcx> {
54
72
55
73
/// Builder of OutlivesEnvironment.
56
74
#[ derive( Debug ) ]
57
- struct OutlivesEnvironmentBuilder < ' tcx > {
58
- param_env : ty:: ParamEnv < ' tcx > ,
75
+ pub struct OutlivesEnvironmentBuilder < ' tcx > {
76
+ clauses : Vec < ty:: Clause < ' tcx > > ,
59
77
region_relation : TransitiveRelationBuilder < Region < ' tcx > > ,
60
78
region_bound_pairs : RegionBoundPairs < ' tcx > ,
61
79
}
@@ -68,32 +86,12 @@ pub type RegionBoundPairs<'tcx> =
68
86
69
87
impl < ' tcx > OutlivesEnvironment < ' tcx > {
70
88
/// 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 ! [ ] ,
74
92
region_relation : Default :: default ( ) ,
75
93
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
+ }
97
95
}
98
96
99
97
/// Borrows current value of the `free_region_map`.
@@ -110,16 +108,21 @@ impl<'tcx> OutlivesEnvironment<'tcx> {
110
108
impl < ' tcx > OutlivesEnvironmentBuilder < ' tcx > {
111
109
#[ inline]
112
110
#[ instrument( level = "debug" ) ]
113
- fn build ( self ) -> OutlivesEnvironment < ' tcx > {
111
+ pub fn build ( self ) -> OutlivesEnvironment < ' tcx > {
114
112
OutlivesEnvironment {
115
- param_env : self . param_env ,
113
+ clauses : self . clauses ,
116
114
free_region_map : FreeRegionMap { relation : self . region_relation . freeze ( ) } ,
117
115
region_bound_pairs : self . region_bound_pairs ,
118
116
}
119
117
}
120
118
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
+
121
124
/// 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 )
123
126
where
124
127
I : IntoIterator < Item = OutlivesBound < ' tcx > > ,
125
128
{
0 commit comments