@@ -15,6 +15,7 @@ use rustc::ty::subst::{Kind, Subst, UnpackedKind};
15
15
use rustc:: ty:: { self , Ty , TyCtxt } ;
16
16
use rustc:: util:: nodemap:: FxHashMap ;
17
17
18
+ use super :: explicit:: ExplicitPredicatesMap ;
18
19
use super :: utils:: * ;
19
20
20
21
/// Infer predicates for the items in the crate.
@@ -24,7 +25,7 @@ use super::utils::*;
24
25
/// now be filled with inferred predicates.
25
26
pub fn infer_predicates < ' tcx > (
26
27
tcx : TyCtxt < ' _ , ' tcx , ' tcx > ,
27
- explicit_map : & FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
28
+ explicit_map : & mut ExplicitPredicatesMap < ' tcx > ,
28
29
) -> FxHashMap < DefId , RequiredPredicates < ' tcx > > {
29
30
debug ! ( "infer_predicates" ) ;
30
31
@@ -55,7 +56,7 @@ pub struct InferVisitor<'cx, 'tcx: 'cx> {
55
56
tcx : TyCtxt < ' cx , ' tcx , ' tcx > ,
56
57
global_inferred_outlives : & ' cx mut FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
57
58
predicates_added : & ' cx mut bool ,
58
- explicit_map : & ' cx FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
59
+ explicit_map : & ' cx mut ExplicitPredicatesMap < ' tcx > ,
59
60
}
60
61
61
62
impl < ' cx , ' tcx > ItemLikeVisitor < ' tcx > for InferVisitor < ' cx , ' tcx > {
@@ -93,7 +94,7 @@ impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> {
93
94
field_ty,
94
95
self . global_inferred_outlives ,
95
96
& mut item_required_predicates,
96
- self . explicit_map ,
97
+ & mut self . explicit_map ,
97
98
) ;
98
99
}
99
100
}
@@ -129,7 +130,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
129
130
field_ty : Ty < ' tcx > ,
130
131
global_inferred_outlives : & FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
131
132
required_predicates : & mut RequiredPredicates < ' tcx > ,
132
- explicit_map : & FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
133
+ explicit_map : & mut ExplicitPredicatesMap < ' tcx > ,
133
134
) {
134
135
for ty in field_ty. walk ( ) {
135
136
match ty. sty {
@@ -257,53 +258,54 @@ pub fn check_explicit_predicates<'tcx>(
257
258
def_id : & DefId ,
258
259
substs : & [ Kind < ' tcx > ] ,
259
260
required_predicates : & mut RequiredPredicates < ' tcx > ,
260
- explicit_map : & FxHashMap < DefId , RequiredPredicates < ' tcx > > ,
261
+ explicit_map : & mut ExplicitPredicatesMap < ' tcx > ,
261
262
ignore_self_ty : bool ,
262
263
) {
263
264
debug ! ( "def_id = {:?}" , & def_id) ;
264
265
debug ! ( "substs = {:?}" , & substs) ;
265
266
debug ! ( "explicit_map = {:?}" , explicit_map) ;
266
267
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) ;
270
269
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) ;
303
272
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
+ }
307
304
}
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) ;
308
309
}
310
+ // }
309
311
}
0 commit comments