@@ -337,24 +337,36 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
337
337
}
338
338
339
339
ty:: TyGenerator ( ..) => {
340
- // the types in a closure or generator are always the types of
341
- // local variables (or possibly references to local
342
- // variables), we'll walk those.
343
- //
344
- // (Though, local variables are probably not
345
- // needed, as they are separately checked w/r/t
346
- // WFedness.)
340
+ // Walk ALL the types in the generator: this will
341
+ // include the upvar types as well as the yield
342
+ // type. Note that this is mildly distinct from
343
+ // the closure case, where we have to be careful
344
+ // about the signature of the closure. We don't
345
+ // have the problem of implied bounds here since
346
+ // generators don't take arguments.
347
347
}
348
348
349
349
ty:: TyClosure ( def_id, substs) => {
350
- // Just check the upvar types for WF. This is
351
- // needed because we capture the signature and it
352
- // may not be WF without the implied
353
- // bounds. Consider a closure like `|x: &'a T|` --
354
- // it may be that `T: 'a` is not known to hold in
355
- // the creator's context (and indeed the closure
356
- // may not be invoked by its creator, but rather
357
- // turned to someone who *can* verify that).
350
+ // Only check the upvar types for WF, not the rest
351
+ // of the types within. This is needed because we
352
+ // capture the signature and it may not be WF
353
+ // without the implied bounds. Consider a closure
354
+ // like `|x: &'a T|` -- it may be that `T: 'a` is
355
+ // not known to hold in the creator's context (and
356
+ // indeed the closure may not be invoked by its
357
+ // creator, but rather turned to someone who *can*
358
+ // verify that).
359
+ //
360
+ // The special treatment of closures here really
361
+ // ought not to be necessary either; the problem
362
+ // is related to #25860 -- there is no way for us
363
+ // to express a fn type complete with the implied
364
+ // bounds that it is assuming. I think in reality
365
+ // the WF rules around fn are a bit messed up, and
366
+ // that is the rot problem: `fn(&'a T)` should
367
+ // probably always be WF, because it should be
368
+ // shorthand for something like `where(T: 'a) {
369
+ // fn(&'a T) }`, as discussed in #25860.
358
370
subtys. skip_current_subtree ( ) ; // subtree handled by compute_projection
359
371
for upvar_ty in substs. upvar_tys ( def_id, self . infcx . tcx ) {
360
372
self . compute ( upvar_ty) ;
0 commit comments