1313//! The second pass over the AST determines the set of constraints.
1414//! We walk the set of items and, for each member, generate new constraints.
1515
16+ use dep_graph:: DepTrackingMapConfig ;
1617use middle:: def_id:: DefId ;
1718use middle:: resolve_lifetime as rl;
1819use middle:: subst;
1920use middle:: subst:: ParamSpace ;
2021use middle:: ty:: { self , Ty } ;
22+ use middle:: ty:: maps:: ItemVariances ;
2123use rustc:: front:: map as hir_map;
2224use syntax:: ast;
2325use rustc_front:: hir;
@@ -48,10 +50,10 @@ pub struct Constraint<'a> {
4850 pub variance : & ' a VarianceTerm < ' a > ,
4951}
5052
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 > )
5354 -> ConstraintContext < ' a , ' tcx >
5455{
56+ let tcx = terms_cx. tcx ;
5557 let covariant = terms_cx. arena . alloc ( ConstantTerm ( ty:: Covariant ) ) ;
5658 let contravariant = terms_cx. arena . alloc ( ConstantTerm ( ty:: Contravariant ) ) ;
5759 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>,
6466 bivariant : bivariant,
6567 constraints : Vec :: new ( ) ,
6668 } ;
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+
6874 constraint_cx
6975}
7076
@@ -289,6 +295,11 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
289295
290296 let trait_def = self . tcx ( ) . lookup_trait_def ( trait_ref. def_id ) ;
291297
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+
292303 self . add_constraints_from_substs (
293304 generics,
294305 trait_ref. def_id ,
@@ -345,6 +356,11 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
345356 ty:: TyStruct ( def, substs) => {
346357 let item_type = self . tcx ( ) . lookup_item_type ( def. did ) ;
347358
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+
348364 // All type parameters on enums and structs should be
349365 // in the TypeSpace.
350366 assert ! ( item_type. generics. types. is_empty_in( subst:: SelfSpace ) ) ;
@@ -364,6 +380,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
364380 ty:: TyProjection ( ref data) => {
365381 let trait_ref = & data. trait_ref ;
366382 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+
367389 self . add_constraints_from_substs (
368390 generics,
369391 trait_ref. def_id ,
@@ -424,7 +446,6 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
424446 }
425447 }
426448
427-
428449 /// Adds constraints appropriate for a nominal type (enum, struct,
429450 /// object, etc) appearing in a context with ambient variance `variance`
430451 fn add_constraints_from_substs ( & mut self ,
0 commit comments