@@ -274,36 +274,36 @@ closure:
274
274
types of all its upvars must outlive ` 'r ` .
275
275
2 . Parameters must outlive the region of any fn that they are passed to.
276
276
277
- Therefore, we can -- sort of -- assume that when we are asked to
278
- compare a region ` 'a ` from a closure with a region ` 'b ` from the fn
279
- that encloses it, in fact ` 'b ` is the larger region. And that is
280
- precisely what we do: when building the region hierarchy, each region
281
- lives in its own distinct subtree, but if we are asked to compute the
282
- ` LUB(r1, r2) ` of two regions, and those regions are in disjoint
283
- subtrees, we compare the lexical nesting of the two regions.
284
-
285
- * Ideas for improving the situation:* The correct argument here is
286
- subtle and a bit hand-wavy. The ideal, as stated earlier, would be to
287
- model things in such a way that it corresponds more closely to the
288
- desugared code. The best approach for doing this is a bit unclear: it
289
- may in fact be possible to * actually* desugar before we start, but I
290
- don't think so. The main option that I've been thinking through is
291
- imposing a "view shift" as we enter the fn body, so that regions
292
- appearing in the types of fn parameters and upvars are translated from
293
- being regions in the outer fn into free region parameters, just as
294
- they would be if we applied the desugaring. The challenge here is that
295
- type inference may not have fully run, so the types may not be fully
296
- known: we could probably do this translation lazilly, as type
297
- variables are instantiated. We would also have to apply a kind of
298
- inverse translation to the return value. This would be a good idea
299
- anyway, as right now it is possible for free regions instantiated
300
- within the closure to leak into the parent: this currently leads to
301
- type errors, since those regions cannot outlive any expressions within
302
- the parent hierarchy. Much like the current handling of closures,
303
- there are no known cases where this leads to a type-checking accepting
304
- incorrect code (though it sometimes rejects what might be considered
305
- correct code; see rust-lang/rust #22557 ), but it still doesn't feel
306
- like the right approach.
277
+ Therefore, we can -- sort of -- assume that any region from an
278
+ enclosing fns is larger than any region from one of its enclosed
279
+ fn. And that is precisely what we do: when building the region
280
+ hierarchy, each region lives in its own distinct subtree, but if we
281
+ are asked to compute the ` LUB(r1, r2) ` of two regions, and those
282
+ regions are in disjoint subtrees, we compare the lexical nesting of
283
+ the two regions.
284
+
285
+ * Ideas for improving the situation:* (FIXME # 3696 ) The correctness
286
+ argument here is subtle and a bit hand-wavy. The ideal, as stated
287
+ earlier, would be to model things in such a way that it corresponds
288
+ more closely to the desugared code. The best approach for doing this
289
+ is a bit unclear: it may in fact be possible to * actually* desugar
290
+ before we start, but I don't think so. The main option that I've been
291
+ thinking through is imposing a "view shift" as we enter the fn body,
292
+ so that regions appearing in the types of fn parameters and upvars are
293
+ translated from being regions in the outer fn into free region
294
+ parameters, just as they would be if we applied the desugaring. The
295
+ challenge here is that type inference may not have fully run, so the
296
+ types may not be fully known: we could probably do this translation
297
+ lazilly, as type variables are instantiated. We would also have to
298
+ apply a kind of inverse translation to the return value. This would be
299
+ a good idea anyway, as right now it is possible for free regions
300
+ instantiated within the closure to leak into the parent: this
301
+ currently leads to type errors, since those regions cannot outlive any
302
+ expressions within the parent hierarchy. Much like the current
303
+ handling of closures, there are no known cases where this leads to a
304
+ type-checking accepting incorrect code (though it sometimes rejects
305
+ what might be considered correct code; see rust-lang/rust #22557 ), but
306
+ it still doesn't feel like the right approach.
307
307
308
308
### Skolemization
309
309
0 commit comments