Skip to content

Commit 4cb8dc3

Browse files
committed
---
yaml --- r: 22499 b: refs/heads/master c: a2f6065 h: refs/heads/master i: 22497: 0aefe57 22495: 1c0aa97 v: v3
1 parent c74797f commit 4cb8dc3

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 90e435e8082105f86f45a11186450ffb50653ffd
2+
refs/heads/master: a2f60651f1f7beb246fee92666f7b168a2ff2c6f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/rustc/middle/region.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,11 @@ type determine_rp_ctxt = @{
434434
dep_map: dep_map,
435435
worklist: dvec<ast::node_id>,
436436

437+
// the innermost enclosing item id
437438
mut item_id: ast::node_id,
439+
440+
// true when we are within an item but not within a method.
441+
// see long discussion on region_is_relevant()
438442
mut anon_implies_rp: bool
439443
};
440444

@@ -466,6 +470,38 @@ impl methods for determine_rp_ctxt {
466470
if !vec.contains(to) { vec.push(to); }
467471
}
468472

473+
// Determines whether a reference to a region that appears in the
474+
// AST implies that the enclosing type is region-parameterized.
475+
//
476+
// This point is subtle. Here are four examples to make it more
477+
// concrete.
478+
//
479+
// 1. impl foo for &int { ... }
480+
// 2. impl foo for &self/int { ... }
481+
// 3. impl foo for bar { fn m() -> &self/int { ... } }
482+
// 4. impl foo for bar { fn m() -> &int { ... } }
483+
//
484+
// In case 1, the anonymous region is being referenced,
485+
// but it appears in a context where the anonymous region
486+
// resolves to self, so the impl foo is region-parameterized.
487+
//
488+
// In case 2, the self parameter is written explicitly.
489+
//
490+
// In case 3, the method refers to self, so that implies that the
491+
// impl must be region parameterized. (If the type bar is not
492+
// region parameterized, that is an error, because the self region
493+
// is effectively unconstrained, but that is detected elsewhere).
494+
//
495+
// In case 4, the anonymous region is referenced, but it
496+
// bound by the method, so it does not refer to self. This impl
497+
// need not be region parameterized.
498+
//
499+
// So the rules basically are: the `self` region always implies
500+
// that the enclosing type is region parameterized. The anonymous
501+
// region also does, unless it appears within a method, in which
502+
// case it is bound. We handle this by setting a flag
503+
// (anon_implies_rp) to true when we enter an item and setting
504+
// that flag to false when we enter a method.
469505
fn region_is_relevant(r: @ast::region) -> bool {
470506
alt r.node {
471507
ast::re_anon {self.anon_implies_rp}

0 commit comments

Comments
 (0)