@@ -12,7 +12,7 @@ use rustc::hir;
12
12
use rustc:: hir:: def_id:: DefId ;
13
13
use rustc:: hir:: itemlikevisit:: ItemLikeVisitor ;
14
14
use rustc:: ty:: subst:: { Kind , Subst , UnpackedKind } ;
15
- use rustc:: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
15
+ use rustc:: ty:: { self , Ty , TyCtxt } ;
16
16
use rustc:: util:: nodemap:: FxHashMap ;
17
17
18
18
use super :: explicit:: ExplicitPredicatesMap ;
@@ -191,43 +191,35 @@ fn insert_required_predicates_to_be_wf<'tcx>(
191
191
substs,
192
192
required_predicates,
193
193
explicit_map,
194
- false ,
194
+ IgnoreSelfTy ( false ) ,
195
195
) ;
196
196
}
197
197
198
198
ty:: Dynamic ( obj, ..) => {
199
199
// This corresponds to `dyn Trait<..>`. In this case, we should
200
200
// use the explicit predicates as well.
201
201
202
- // We are passing type `ty` as a placeholder value with the function
203
- // `with_self_ty`, since there is no concrete type `Self` for a
204
- // `dyn Trait` at this stage. Therefore when checking explicit
205
- // predicates in `check_explicit_predicates` we need to ignore
206
- // checking the explicit_map for Self type.
207
202
debug ! ( "Dynamic" ) ;
208
203
debug ! ( "field_ty = {}" , & field_ty) ;
209
204
debug ! ( "ty in field = {}" , & ty) ;
210
205
if let Some ( ex_trait_ref) = obj. principal ( ) {
211
- // The method `has_escaping_regions` checks if
212
- // there are any late-bound regions, which is
213
- // the lifetime `'r`. It is safe to ignore
214
- // these since `'r` is not in scope for `Foo`.
215
- //
216
- // ```
217
- // struct Foo {
218
- // bar: for<'r> Fn(usize, &'r FnMut())
219
- // }
220
- // ```
221
- if !ty. has_escaping_regions ( ) {
222
- check_explicit_predicates (
223
- tcx,
224
- & ex_trait_ref. skip_binder ( ) . def_id ,
225
- ex_trait_ref. with_self_ty ( tcx, ty) . skip_binder ( ) . substs ,
226
- required_predicates,
227
- explicit_map,
228
- true ,
229
- ) ;
230
- }
206
+ // Here, we are passing the type `usize` as a
207
+ // placeholder value with the function
208
+ // `with_self_ty`, since there is no concrete type
209
+ // `Self` for a `dyn Trait` at this
210
+ // stage. Therefore when checking explicit
211
+ // predicates in `check_explicit_predicates` we
212
+ // need to ignore checking the explicit_map for
213
+ // Self type.
214
+ let substs = ex_trait_ref. with_self_ty ( tcx, tcx. types . usize ) . skip_binder ( ) . substs ;
215
+ check_explicit_predicates (
216
+ tcx,
217
+ & ex_trait_ref. skip_binder ( ) . def_id ,
218
+ substs,
219
+ required_predicates,
220
+ explicit_map,
221
+ IgnoreSelfTy ( true ) ,
222
+ ) ;
231
223
}
232
224
}
233
225
@@ -241,7 +233,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
241
233
obj. substs ,
242
234
required_predicates,
243
235
explicit_map,
244
- false ,
236
+ IgnoreSelfTy ( false ) ,
245
237
) ;
246
238
}
247
239
@@ -250,6 +242,8 @@ fn insert_required_predicates_to_be_wf<'tcx>(
250
242
}
251
243
}
252
244
245
+ pub struct IgnoreSelfTy ( bool ) ;
246
+
253
247
/// We also have to check the explicit predicates
254
248
/// declared on the type.
255
249
///
@@ -271,7 +265,7 @@ pub fn check_explicit_predicates<'tcx>(
271
265
substs : & [ Kind < ' tcx > ] ,
272
266
required_predicates : & mut RequiredPredicates < ' tcx > ,
273
267
explicit_map : & mut ExplicitPredicatesMap < ' tcx > ,
274
- ignore_self_ty : bool ,
268
+ ignore_self_ty : IgnoreSelfTy ,
275
269
) {
276
270
debug ! ( "def_id = {:?}" , & def_id) ;
277
271
debug ! ( "substs = {:?}" , & substs) ;
@@ -309,7 +303,7 @@ pub fn check_explicit_predicates<'tcx>(
309
303
// to apply the substs, and not filter this predicate, we might then falsely
310
304
// conclude that e.g. `X: 'x` was a reasonable inferred requirement.
311
305
if let UnpackedKind :: Type ( ty) = outlives_predicate. 0 . unpack ( ) {
312
- if ty. is_self ( ) && ignore_self_ty {
306
+ if ty. is_self ( ) && ignore_self_ty. 0 {
313
307
debug ! ( "skipping self ty = {:?}" , & ty) ;
314
308
continue ;
315
309
}
@@ -319,5 +313,4 @@ pub fn check_explicit_predicates<'tcx>(
319
313
debug ! ( "predicate = {:?}" , & predicate) ;
320
314
insert_outlives_predicate ( tcx, predicate. 0 . into ( ) , predicate. 1 , required_predicates) ;
321
315
}
322
- // }
323
316
}
0 commit comments