@@ -15,6 +15,7 @@ use rustc::ty::subst::{Kind, Subst, UnpackedKind};
1515use rustc:: ty:: { self , Ty , TyCtxt } ;
1616use rustc:: util:: nodemap:: FxHashMap ;
1717
18+ use super :: explicit:: ExplicitPredicatesMap ;
1819use super :: utils:: * ;
1920
2021/// Infer predicates for the items in the crate.
@@ -24,7 +25,7 @@ use super::utils::*;
2425/// now be filled with inferred predicates.
2526pub fn infer_predicates < ' tcx > (
2627 tcx : TyCtxt < ' _ , ' tcx , ' tcx > ,
27- explicit_map : & FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
28+ explicit_map : & mut ExplicitPredicatesMap < ' tcx > ,
2829) -> FxHashMap < DefId , RequiredPredicates < ' tcx > > {
2930 debug ! ( "infer_predicates" ) ;
3031
@@ -55,7 +56,7 @@ pub struct InferVisitor<'cx, 'tcx: 'cx> {
5556 tcx : TyCtxt < ' cx , ' tcx , ' tcx > ,
5657 global_inferred_outlives : & ' cx mut FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
5758 predicates_added : & ' cx mut bool ,
58- explicit_map : & ' cx FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
59+ explicit_map : & ' cx mut ExplicitPredicatesMap < ' tcx > ,
5960}
6061
6162impl < ' cx , ' tcx > ItemLikeVisitor < ' tcx > for InferVisitor < ' cx , ' tcx > {
@@ -93,7 +94,7 @@ impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> {
9394 field_ty,
9495 self . global_inferred_outlives ,
9596 & mut item_required_predicates,
96- self . explicit_map ,
97+ & mut self . explicit_map ,
9798 ) ;
9899 }
99100 }
@@ -129,7 +130,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
129130 field_ty : Ty < ' tcx > ,
130131 global_inferred_outlives : & FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
131132 required_predicates : & mut RequiredPredicates < ' tcx > ,
132- explicit_map : & FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
133+ explicit_map : & mut ExplicitPredicatesMap < ' tcx > ,
133134) {
134135 for ty in field_ty. walk ( ) {
135136 match ty. sty {
@@ -257,53 +258,54 @@ pub fn check_explicit_predicates<'tcx>(
257258 def_id : & DefId ,
258259 substs : & [ Kind < ' tcx > ] ,
259260 required_predicates : & mut RequiredPredicates < ' tcx > ,
260- explicit_map : & FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
261+ explicit_map : & mut ExplicitPredicatesMap < ' tcx > ,
261262 ignore_self_ty : bool ,
262263) {
263264 debug ! ( "def_id = {:?}" , & def_id) ;
264265 debug ! ( "substs = {:?}" , & substs) ;
265266 debug ! ( "explicit_map = {:?}" , explicit_map) ;
266267 debug ! ( "required_predicates = {:?}" , required_predicates) ;
267- if let Some ( explicit_predicates) = explicit_map. get ( def_id) {
268- for outlives_predicate in explicit_predicates. iter ( ) {
269- debug ! ( "outlives_predicate = {:?}" , & outlives_predicate) ;
268+ let explicit_predicates = explicit_map. explicit_predicates_of ( tcx, * def_id) ;
270269
271- // Careful: If we are inferring the effects of a `dyn Trait<..>`
272- // type, then when we look up the predicates for `Trait`,
273- // we may find some that reference `Self`. e.g., perhaps the
274- // definition of `Trait` was:
275- //
276- // ```
277- // trait Trait<'a, T> where Self: 'a { .. }
278- // ```
279- //
280- // we want to ignore such predicates here, because
281- // there is no type parameter for them to affect. Consider
282- // a struct containing `dyn Trait`:
283- //
284- // ```
285- // struct MyStruct<'x, X> { field: Box<dyn Trait<'x, X>> }
286- // ```
287- //
288- // The `where Self: 'a` predicate refers to the *existential, hidden type*
289- // that is represented by the `dyn Trait`, not to the `X` type parameter
290- // (or any other generic parameter) declared on `MyStruct`.
291- //
292- // Note that we do this check for self **before** applying `substs`. In the
293- // case that `substs` come from a `dyn Trait` type, our caller will have
294- // included `Self = dyn Trait<'x, X>` as the value for `Self`. If we were
295- // to apply the substs, and not filter this predicate, we might then falsely
296- // conclude that e.g. `X: 'x` was a reasonable inferred requirement.
297- if let UnpackedKind :: Type ( ty) = outlives_predicate. 0 . unpack ( ) {
298- if ty. is_self ( ) && ignore_self_ty {
299- debug ! ( "skipping self ty = {:?}" , & ty) ;
300- continue ;
301- }
302- }
270+ for outlives_predicate in explicit_predicates. iter ( ) {
271+ debug ! ( "outlives_predicate = {:?}" , & outlives_predicate) ;
303272
304- let predicate = outlives_predicate. subst ( tcx, substs) ;
305- debug ! ( "predicate = {:?}" , & predicate) ;
306- insert_outlives_predicate ( tcx, predicate. 0 . into ( ) , predicate. 1 , required_predicates) ;
273+ // Careful: If we are inferring the effects of a `dyn Trait<..>`
274+ // type, then when we look up the predicates for `Trait`,
275+ // we may find some that reference `Self`. e.g., perhaps the
276+ // definition of `Trait` was:
277+ //
278+ // ```
279+ // trait Trait<'a, T> where Self: 'a { .. }
280+ // ```
281+ //
282+ // we want to ignore such predicates here, because
283+ // there is no type parameter for them to affect. Consider
284+ // a struct containing `dyn Trait`:
285+ //
286+ // ```
287+ // struct MyStruct<'x, X> { field: Box<dyn Trait<'x, X>> }
288+ // ```
289+ //
290+ // The `where Self: 'a` predicate refers to the *existential, hidden type*
291+ // that is represented by the `dyn Trait`, not to the `X` type parameter
292+ // (or any other generic parameter) declared on `MyStruct`.
293+ //
294+ // Note that we do this check for self **before** applying `substs`. In the
295+ // case that `substs` come from a `dyn Trait` type, our caller will have
296+ // included `Self = dyn Trait<'x, X>` as the value for `Self`. If we were
297+ // to apply the substs, and not filter this predicate, we might then falsely
298+ // conclude that e.g. `X: 'x` was a reasonable inferred requirement.
299+ if let UnpackedKind :: Type ( ty) = outlives_predicate. 0 . unpack ( ) {
300+ if ty. is_self ( ) && ignore_self_ty {
301+ debug ! ( "skipping self ty = {:?}" , & ty) ;
302+ continue ;
303+ }
307304 }
305+
306+ let predicate = outlives_predicate. subst ( tcx, substs) ;
307+ debug ! ( "predicate = {:?}" , & predicate) ;
308+ insert_outlives_predicate ( tcx, predicate. 0 . into ( ) , predicate. 1 , required_predicates) ;
308309 }
310+ // }
309311}
0 commit comments