8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use infer:: { InferCtxt , InferOk } ;
11
+ use infer:: { RegionObligation , InferCtxt , InferOk } ;
12
12
use ty:: { self , Ty , TypeFoldable , ToPolyTraitRef , ToPredicate } ;
13
13
use ty:: error:: ExpectedFound ;
14
14
use rustc_data_structures:: obligation_forest:: { ObligationForest , Error } ;
15
15
use rustc_data_structures:: obligation_forest:: { ForestObligation , ObligationProcessor } ;
16
16
use std:: marker:: PhantomData ;
17
- use syntax:: ast;
18
- use util:: nodemap:: NodeMap ;
19
17
use hir:: def_id:: DefId ;
20
18
21
19
use super :: CodeAmbiguity ;
@@ -48,39 +46,6 @@ pub struct FulfillmentContext<'tcx> {
48
46
// A list of all obligations that have been registered with this
49
47
// fulfillment context.
50
48
predicates : ObligationForest < PendingPredicateObligation < ' tcx > > ,
51
-
52
- // A set of constraints that regionck must validate. Each
53
- // constraint has the form `T:'a`, meaning "some type `T` must
54
- // outlive the lifetime 'a". These constraints derive from
55
- // instantiated type parameters. So if you had a struct defined
56
- // like
57
- //
58
- // struct Foo<T:'static> { ... }
59
- //
60
- // then in some expression `let x = Foo { ... }` it will
61
- // instantiate the type parameter `T` with a fresh type `$0`. At
62
- // the same time, it will record a region obligation of
63
- // `$0:'static`. This will get checked later by regionck. (We
64
- // can't generally check these things right away because we have
65
- // to wait until types are resolved.)
66
- //
67
- // These are stored in a map keyed to the id of the innermost
68
- // enclosing fn body / static initializer expression. This is
69
- // because the location where the obligation was incurred can be
70
- // relevant with respect to which sublifetime assumptions are in
71
- // place. The reason that we store under the fn-id, and not
72
- // something more fine-grained, is so that it is easier for
73
- // regionck to be sure that it has found *all* the region
74
- // obligations (otherwise, it's easy to fail to walk to a
75
- // particular node-id).
76
- region_obligations : NodeMap < Vec < RegionObligation < ' tcx > > > ,
77
- }
78
-
79
- #[ derive( Clone ) ]
80
- pub struct RegionObligation < ' tcx > {
81
- pub sub_region : ty:: Region < ' tcx > ,
82
- pub sup_type : Ty < ' tcx > ,
83
- pub cause : ObligationCause < ' tcx > ,
84
49
}
85
50
86
51
#[ derive( Clone , Debug ) ]
@@ -94,7 +59,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
94
59
pub fn new ( ) -> FulfillmentContext < ' tcx > {
95
60
FulfillmentContext {
96
61
predicates : ObligationForest :: new ( ) ,
97
- region_obligations : NodeMap ( ) ,
98
62
}
99
63
}
100
64
@@ -184,17 +148,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
184
148
}
185
149
}
186
150
187
-
188
- pub fn region_obligations ( & self ,
189
- body_id : ast:: NodeId )
190
- -> & [ RegionObligation < ' tcx > ]
191
- {
192
- match self . region_obligations . get ( & body_id) {
193
- None => Default :: default ( ) ,
194
- Some ( vec) => vec,
195
- }
196
- }
197
-
198
151
pub fn select_all_or_error ( & mut self ,
199
152
infcx : & InferCtxt < ' a , ' gcx , ' tcx > )
200
153
-> Result < ( ) , Vec < FulfillmentError < ' tcx > > >
@@ -237,10 +190,7 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
237
190
debug ! ( "select: starting another iteration" ) ;
238
191
239
192
// Process pending obligations.
240
- let outcome = self . predicates . process_obligations ( & mut FulfillProcessor {
241
- selcx,
242
- region_obligations : & mut self . region_obligations ,
243
- } ) ;
193
+ let outcome = self . predicates . process_obligations ( & mut FulfillProcessor { selcx } ) ;
244
194
debug ! ( "select: outcome={:?}" , outcome) ;
245
195
246
196
// FIXME: if we kept the original cache key, we could mark projection
@@ -269,7 +219,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
269
219
270
220
struct FulfillProcessor < ' a , ' b : ' a , ' gcx : ' tcx , ' tcx : ' b > {
271
221
selcx : & ' a mut SelectionContext < ' b , ' gcx , ' tcx > ,
272
- region_obligations : & ' a mut NodeMap < Vec < RegionObligation < ' tcx > > > ,
273
222
}
274
223
275
224
impl < ' a , ' b , ' gcx , ' tcx > ObligationProcessor for FulfillProcessor < ' a , ' b , ' gcx , ' tcx > {
@@ -280,9 +229,7 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
280
229
obligation : & mut Self :: Obligation )
281
230
-> Result < Option < Vec < Self :: Obligation > > , Self :: Error >
282
231
{
283
- process_predicate ( self . selcx ,
284
- obligation,
285
- self . region_obligations )
232
+ process_predicate ( self . selcx , obligation)
286
233
. map ( |os| os. map ( |os| os. into_iter ( ) . map ( |o| PendingPredicateObligation {
287
234
obligation : o,
288
235
stalled_on : vec ! [ ]
@@ -321,8 +268,7 @@ fn trait_ref_type_vars<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 't
321
268
/// - `Err` if the predicate does not hold
322
269
fn process_predicate < ' a , ' gcx , ' tcx > (
323
270
selcx : & mut SelectionContext < ' a , ' gcx , ' tcx > ,
324
- pending_obligation : & mut PendingPredicateObligation < ' tcx > ,
325
- region_obligations : & mut NodeMap < Vec < RegionObligation < ' tcx > > > )
271
+ pending_obligation : & mut PendingPredicateObligation < ' tcx > )
326
272
-> Result < Option < Vec < PredicateObligation < ' tcx > > > ,
327
273
FulfillmentErrorCode < ' tcx > >
328
274
{
@@ -444,18 +390,26 @@ fn process_predicate<'a, 'gcx, 'tcx>(
444
390
// `for<'a> T: 'a where 'a not in T`, which we can treat as `T: 'static`.
445
391
Some ( t_a) => {
446
392
let r_static = selcx. tcx ( ) . types . re_static ;
447
- register_region_obligation ( t_a, r_static,
448
- obligation. cause . clone ( ) ,
449
- region_obligations) ;
393
+ selcx. infcx ( ) . register_region_obligation (
394
+ obligation. cause . body_id ,
395
+ RegionObligation {
396
+ sup_type : t_a,
397
+ sub_region : r_static,
398
+ cause : obligation. cause . clone ( ) ,
399
+ } ) ;
450
400
Ok ( Some ( vec ! [ ] ) )
451
401
}
452
402
}
453
403
}
454
404
// If there aren't, register the obligation.
455
405
Some ( ty:: OutlivesPredicate ( t_a, r_b) ) => {
456
- register_region_obligation ( t_a, r_b,
457
- obligation. cause . clone ( ) ,
458
- region_obligations) ;
406
+ selcx. infcx ( ) . register_region_obligation (
407
+ obligation. cause . body_id ,
408
+ RegionObligation {
409
+ sup_type : t_a,
410
+ sub_region : r_b,
411
+ cause : obligation. cause . clone ( )
412
+ } ) ;
459
413
Ok ( Some ( vec ! [ ] ) )
460
414
}
461
415
}
@@ -558,25 +512,6 @@ fn process_predicate<'a, 'gcx, 'tcx>(
558
512
}
559
513
}
560
514
561
-
562
- fn register_region_obligation < ' tcx > ( t_a : Ty < ' tcx > ,
563
- r_b : ty:: Region < ' tcx > ,
564
- cause : ObligationCause < ' tcx > ,
565
- region_obligations : & mut NodeMap < Vec < RegionObligation < ' tcx > > > )
566
- {
567
- let region_obligation = RegionObligation { sup_type : t_a,
568
- sub_region : r_b,
569
- cause : cause } ;
570
-
571
- debug ! ( "register_region_obligation({:?}, cause={:?})" ,
572
- region_obligation, region_obligation. cause) ;
573
-
574
- region_obligations. entry ( region_obligation. cause . body_id )
575
- . or_insert ( vec ! [ ] )
576
- . push ( region_obligation) ;
577
-
578
- }
579
-
580
515
fn to_fulfillment_error < ' tcx > (
581
516
error : Error < PendingPredicateObligation < ' tcx > , FulfillmentErrorCode < ' tcx > > )
582
517
-> FulfillmentError < ' tcx >
0 commit comments