Skip to content

Commit d896981

Browse files
committed
comment wf more
1 parent 27bedfa commit d896981

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/librustc/ty/wf.rs

+27-15
Original file line numberDiff line numberDiff line change
@@ -337,24 +337,36 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
337337
}
338338

339339
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.
347347
}
348348

349349
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.
358370
subtys.skip_current_subtree(); // subtree handled by compute_projection
359371
for upvar_ty in substs.upvar_tys(def_id, self.infcx.tcx) {
360372
self.compute(upvar_ty);

0 commit comments

Comments
 (0)