13
13
//! The second pass over the AST determines the set of constraints.
14
14
//! We walk the set of items and, for each member, generate new constraints.
15
15
16
+ use dep_graph:: DepTrackingMapConfig ;
16
17
use middle:: def_id:: DefId ;
17
18
use middle:: resolve_lifetime as rl;
18
19
use middle:: subst;
19
20
use middle:: subst:: ParamSpace ;
20
21
use middle:: ty:: { self , Ty } ;
22
+ use middle:: ty:: maps:: ItemVariances ;
21
23
use rustc:: front:: map as hir_map;
22
24
use syntax:: ast;
23
25
use rustc_front:: hir;
@@ -48,10 +50,10 @@ pub struct Constraint<'a> {
48
50
pub variance : & ' a VarianceTerm < ' a > ,
49
51
}
50
52
51
- pub fn add_constraints_from_crate < ' a , ' tcx > ( terms_cx : TermsContext < ' a , ' tcx > ,
52
- krate : & hir:: Crate )
53
+ pub fn add_constraints_from_crate < ' a , ' tcx > ( terms_cx : TermsContext < ' a , ' tcx > )
53
54
-> ConstraintContext < ' a , ' tcx >
54
55
{
56
+ let tcx = terms_cx. tcx ;
55
57
let covariant = terms_cx. arena . alloc ( ConstantTerm ( ty:: Covariant ) ) ;
56
58
let contravariant = terms_cx. arena . alloc ( ConstantTerm ( ty:: Contravariant ) ) ;
57
59
let invariant = terms_cx. arena . alloc ( ConstantTerm ( ty:: Invariant ) ) ;
@@ -64,7 +66,11 @@ pub fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>,
64
66
bivariant : bivariant,
65
67
constraints : Vec :: new ( ) ,
66
68
} ;
67
- krate. visit_all_items ( & mut constraint_cx) ;
69
+
70
+ // See README.md for a discussion on dep-graph management.
71
+ tcx. visit_all_items_in_krate ( |def_id| ItemVariances :: to_dep_node ( & def_id) ,
72
+ & mut constraint_cx) ;
73
+
68
74
constraint_cx
69
75
}
70
76
@@ -289,6 +295,11 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
289
295
290
296
let trait_def = self . tcx ( ) . lookup_trait_def ( trait_ref. def_id ) ;
291
297
298
+ // This edge is actually implied by the call to
299
+ // `lookup_trait_def`, but I'm trying to be future-proof. See
300
+ // README.md for a discussion on dep-graph management.
301
+ self . tcx ( ) . dep_graph . read ( ItemVariances :: to_dep_node ( & trait_ref. def_id ) ) ;
302
+
292
303
self . add_constraints_from_substs (
293
304
generics,
294
305
trait_ref. def_id ,
@@ -345,6 +356,11 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
345
356
ty:: TyStruct ( def, substs) => {
346
357
let item_type = self . tcx ( ) . lookup_item_type ( def. did ) ;
347
358
359
+ // This edge is actually implied by the call to
360
+ // `lookup_trait_def`, but I'm trying to be future-proof. See
361
+ // README.md for a discussion on dep-graph management.
362
+ self . tcx ( ) . dep_graph . read ( ItemVariances :: to_dep_node ( & def. did ) ) ;
363
+
348
364
// All type parameters on enums and structs should be
349
365
// in the TypeSpace.
350
366
assert ! ( item_type. generics. types. is_empty_in( subst:: SelfSpace ) ) ;
@@ -364,6 +380,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
364
380
ty:: TyProjection ( ref data) => {
365
381
let trait_ref = & data. trait_ref ;
366
382
let trait_def = self . tcx ( ) . lookup_trait_def ( trait_ref. def_id ) ;
383
+
384
+ // This edge is actually implied by the call to
385
+ // `lookup_trait_def`, but I'm trying to be future-proof. See
386
+ // README.md for a discussion on dep-graph management.
387
+ self . tcx ( ) . dep_graph . read ( ItemVariances :: to_dep_node ( & trait_ref. def_id ) ) ;
388
+
367
389
self . add_constraints_from_substs (
368
390
generics,
369
391
trait_ref. def_id ,
@@ -424,7 +446,6 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
424
446
}
425
447
}
426
448
427
-
428
449
/// Adds constraints appropriate for a nominal type (enum, struct,
429
450
/// object, etc) appearing in a context with ambient variance `variance`
430
451
fn add_constraints_from_substs ( & mut self ,
0 commit comments