@@ -84,13 +84,14 @@ use self::TupleArgumentsFlag::*;
84
84
85
85
use astconv:: { mod, ast_region_to_region, ast_ty_to_ty, AstConv } ;
86
86
use check:: _match:: pat_ctxt;
87
- use middle:: { const_eval, def, traits } ;
87
+ use middle:: { const_eval, def} ;
88
88
use middle:: infer;
89
89
use middle:: lang_items:: IteratorItem ;
90
90
use middle:: mem_categorization:: { mod, McResult } ;
91
91
use middle:: pat_util:: { mod, pat_id_map} ;
92
92
use middle:: region:: CodeExtent ;
93
93
use middle:: subst:: { mod, Subst , Substs , VecPerParamSpace , ParamSpace } ;
94
+ use middle:: traits;
94
95
use middle:: ty:: { FnSig , VariantInfo , Polytype } ;
95
96
use middle:: ty:: { Disr , ParamTy , ParameterEnvironment } ;
96
97
use middle:: ty:: { mod, Ty } ;
@@ -108,7 +109,6 @@ use util::ppaux::{mod, UserString, Repr};
108
109
use util:: nodemap:: { DefIdMap , FnvHashMap , NodeMap } ;
109
110
110
111
use std:: cell:: { Cell , Ref , RefCell } ;
111
- use std:: collections:: hash_map:: { Occupied , Vacant } ;
112
112
use std:: mem:: replace;
113
113
use std:: rc:: Rc ;
114
114
use syntax:: { mod, abi, attr} ;
@@ -161,42 +161,10 @@ pub struct Inherited<'a, 'tcx: 'a> {
161
161
// one is never copied into the tcx: it is only used by regionck.
162
162
fn_sig_map : RefCell < NodeMap < Vec < Ty < ' tcx > > > > ,
163
163
164
- // A set of constraints that regionck must validate. Each
165
- // constraint has the form `T:'a`, meaning "some type `T` must
166
- // outlive the lifetime 'a". These constraints derive from
167
- // instantiated type parameters. So if you had a struct defined
168
- // like
169
- //
170
- // struct Foo<T:'static> { ... }
171
- //
172
- // then in some expression `let x = Foo { ... }` it will
173
- // instantiate the type parameter `T` with a fresh type `$0`. At
174
- // the same time, it will record a region obligation of
175
- // `$0:'static`. This will get checked later by regionck. (We
176
- // can't generally check these things right away because we have
177
- // to wait until types are resolved.)
178
- //
179
- // These are stored in a map keyed to the id of the innermost
180
- // enclosing fn body / static initializer expression. This is
181
- // because the location where the obligation was incurred can be
182
- // relevant with respect to which sublifetime assumptions are in
183
- // place. The reason that we store under the fn-id, and not
184
- // something more fine-grained, is so that it is easier for
185
- // regionck to be sure that it has found *all* the region
186
- // obligations (otherwise, it's easy to fail to walk to a
187
- // particular node-id).
188
- region_obligations : RefCell < NodeMap < Vec < RegionObligation < ' tcx > > > > ,
189
-
190
164
// Tracks trait obligations incurred during this function body.
191
165
fulfillment_cx : RefCell < traits:: FulfillmentContext < ' tcx > > ,
192
166
}
193
167
194
- struct RegionObligation < ' tcx > {
195
- sub_region : ty:: Region ,
196
- sup_type : Ty < ' tcx > ,
197
- origin : infer:: SubregionOrigin < ' tcx > ,
198
- }
199
-
200
168
/// When type-checking an expression, we propagate downward
201
169
/// whatever type hint we are able in the form of an `Expectation`.
202
170
enum Expectation < ' tcx > {
@@ -328,7 +296,6 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> {
328
296
upvar_borrow_map : RefCell :: new ( FnvHashMap :: new ( ) ) ,
329
297
unboxed_closures : RefCell :: new ( DefIdMap :: new ( ) ) ,
330
298
fn_sig_map : RefCell :: new ( NodeMap :: new ( ) ) ,
331
- region_obligations : RefCell :: new ( NodeMap :: new ( ) ) ,
332
299
fulfillment_cx : RefCell :: new ( traits:: FulfillmentContext :: new ( ) ) ,
333
300
}
334
301
}
@@ -1988,15 +1955,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1988
1955
ty : Ty < ' tcx > ,
1989
1956
r : ty:: Region )
1990
1957
{
1991
- let mut region_obligations = self . inh . region_obligations . borrow_mut ( ) ;
1992
- let region_obligation = RegionObligation { sub_region : r,
1993
- sup_type : ty,
1994
- origin : origin } ;
1995
-
1996
- match region_obligations. entry ( self . body_id ) {
1997
- Vacant ( entry) => { entry. set ( vec ! [ region_obligation] ) ; } ,
1998
- Occupied ( mut entry) => { entry. get_mut ( ) . push ( region_obligation) ; } ,
1999
- }
1958
+ let mut fulfillment_cx = self . inh . fulfillment_cx . borrow_mut ( ) ;
1959
+ let region_obligation = traits:: RegionObligation { sub_region : r,
1960
+ sup_type : ty,
1961
+ origin : origin } ;
1962
+ fulfillment_cx. register_region_obligation ( self . body_id , region_obligation) ;
2000
1963
}
2001
1964
2002
1965
pub fn add_default_region_param_bounds ( & self ,
@@ -5833,11 +5796,3 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
5833
5796
}
5834
5797
}
5835
5798
5836
- impl < ' tcx > Repr < ' tcx > for RegionObligation < ' tcx > {
5837
- fn repr ( & self , tcx : & ty:: ctxt < ' tcx > ) -> String {
5838
- format ! ( "RegionObligation(sub_region={}, sup_type={}, origin={})" ,
5839
- self . sub_region. repr( tcx) ,
5840
- self . sup_type. repr( tcx) ,
5841
- self . origin. repr( tcx) )
5842
- }
5843
- }
0 commit comments