@@ -2,7 +2,7 @@ use rustc_data_structures::fx::FxHashMap;
22use rustc_hir:: def:: DefKind ;
33use rustc_hir:: def_id:: DefId ;
44use rustc_middle:: ty:: subst:: { GenericArg , GenericArgKind , Subst } ;
5- use rustc_middle:: ty:: { self , EarlyBinder , Ty , TyCtxt } ;
5+ use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
66use rustc_span:: Span ;
77
88use super :: explicit:: ExplicitPredicatesMap ;
@@ -13,20 +13,19 @@ use super::utils::*;
1313/// `global_inferred_outlives`: this is initially the empty map that
1414/// was generated by walking the items in the crate. This will
1515/// now be filled with inferred predicates.
16- pub fn infer_predicates < ' tcx > (
16+ pub ( super ) fn infer_predicates < ' tcx > (
1717 tcx : TyCtxt < ' tcx > ,
18- explicit_map : & mut ExplicitPredicatesMap < ' tcx > ,
19- ) -> FxHashMap < DefId , RequiredPredicates < ' tcx > > {
18+ ) -> FxHashMap < DefId , ty:: EarlyBinder < RequiredPredicates < ' tcx > > > {
2019 debug ! ( "infer_predicates" ) ;
2120
22- let mut predicates_added = true ;
21+ let mut explicit_map = ExplicitPredicatesMap :: new ( ) ;
2322
2423 let mut global_inferred_outlives = FxHashMap :: default ( ) ;
2524
2625 // If new predicates were added then we need to re-calculate
2726 // all crates since there could be new implied predicates.
28- while predicates_added {
29- predicates_added = false ;
27+ ' outer : loop {
28+ let mut predicates_added = false ;
3029
3130 // Visit all the crates and infer predicates
3231 for id in tcx. hir ( ) . items ( ) {
@@ -53,9 +52,9 @@ pub fn infer_predicates<'tcx>(
5352 tcx,
5453 field_ty,
5554 field_span,
56- & mut global_inferred_outlives,
55+ & global_inferred_outlives,
5756 & mut item_required_predicates,
58- explicit_map,
57+ & mut explicit_map,
5958 ) ;
6059 }
6160 }
@@ -70,12 +69,17 @@ pub fn infer_predicates<'tcx>(
7069 // we walk the crates again and re-calculate predicates for all
7170 // items.
7271 let item_predicates_len: usize =
73- global_inferred_outlives. get ( & item_did. to_def_id ( ) ) . map_or ( 0 , |p| p. len ( ) ) ;
72+ global_inferred_outlives. get ( & item_did. to_def_id ( ) ) . map_or ( 0 , |p| p. 0 . len ( ) ) ;
7473 if item_required_predicates. len ( ) > item_predicates_len {
7574 predicates_added = true ;
76- global_inferred_outlives. insert ( item_did. to_def_id ( ) , item_required_predicates) ;
75+ global_inferred_outlives
76+ . insert ( item_did. to_def_id ( ) , ty:: EarlyBinder ( item_required_predicates) ) ;
7777 }
7878 }
79+
80+ if !predicates_added {
81+ break ' outer;
82+ }
7983 }
8084
8185 global_inferred_outlives
@@ -85,7 +89,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
8589 tcx : TyCtxt < ' tcx > ,
8690 field_ty : Ty < ' tcx > ,
8791 field_span : Span ,
88- global_inferred_outlives : & FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
92+ global_inferred_outlives : & FxHashMap < DefId , ty :: EarlyBinder < RequiredPredicates < ' tcx > > > ,
8993 required_predicates : & mut RequiredPredicates < ' tcx > ,
9094 explicit_map : & mut ExplicitPredicatesMap < ' tcx > ,
9195) {
@@ -133,11 +137,13 @@ fn insert_required_predicates_to_be_wf<'tcx>(
133137 // 'a` holds for `Foo`.
134138 debug ! ( "Adt" ) ;
135139 if let Some ( unsubstituted_predicates) = global_inferred_outlives. get ( & def. did ( ) ) {
136- for ( unsubstituted_predicate, & span) in unsubstituted_predicates {
140+ for ( unsubstituted_predicate, & span) in & unsubstituted_predicates. 0 {
137141 // `unsubstituted_predicate` is `U: 'b` in the
138142 // example above. So apply the substitution to
139143 // get `T: 'a` (or `predicate`):
140- let predicate = EarlyBinder ( * unsubstituted_predicate) . subst ( tcx, substs) ;
144+ let predicate = unsubstituted_predicates
145+ . rebind ( * unsubstituted_predicate)
146+ . subst ( tcx, substs) ;
141147 insert_outlives_predicate (
142148 tcx,
143149 predicate. 0 ,
@@ -224,7 +230,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
224230/// will give us `U: 'static` and `U: Foo`. The latter we
225231/// can ignore, but we will want to process `U: 'static`,
226232/// applying the substitution as above.
227- pub fn check_explicit_predicates < ' tcx > (
233+ fn check_explicit_predicates < ' tcx > (
228234 tcx : TyCtxt < ' tcx > ,
229235 def_id : DefId ,
230236 substs : & [ GenericArg < ' tcx > ] ,
@@ -242,7 +248,7 @@ pub fn check_explicit_predicates<'tcx>(
242248 ) ;
243249 let explicit_predicates = explicit_map. explicit_predicates_of ( tcx, def_id) ;
244250
245- for ( outlives_predicate, & span) in explicit_predicates {
251+ for ( outlives_predicate, & span) in & explicit_predicates. 0 {
246252 debug ! ( "outlives_predicate = {:?}" , & outlives_predicate) ;
247253
248254 // Careful: If we are inferring the effects of a `dyn Trait<..>`
@@ -287,7 +293,7 @@ pub fn check_explicit_predicates<'tcx>(
287293 continue ;
288294 }
289295
290- let predicate = EarlyBinder ( * outlives_predicate) . subst ( tcx, substs) ;
296+ let predicate = explicit_predicates . rebind ( * outlives_predicate) . subst ( tcx, substs) ;
291297 debug ! ( "predicate = {:?}" , & predicate) ;
292298 insert_outlives_predicate ( tcx, predicate. 0 , predicate. 1 , span, required_predicates) ;
293299 }
0 commit comments