diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-07-12 14:01:23 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-07-13 10:20:50 -0700 |
| commit | a2f60651f1f7beb246fee92666f7b168a2ff2c6f (patch) | |
| tree | 7d4f2b3c8cc8db7cb2d919ea0eeaf226161a30e6 | |
| parent | 90e435e8082105f86f45a11186450ffb50653ffd (diff) | |
| download | rust-a2f60651f1f7beb246fee92666f7b168a2ff2c6f.tar.gz rust-a2f60651f1f7beb246fee92666f7b168a2ff2c6f.zip | |
add comments to region inference
| -rw-r--r-- | src/rustc/middle/region.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/rustc/middle/region.rs b/src/rustc/middle/region.rs index ff8377fa374..87640b5824e 100644 --- a/src/rustc/middle/region.rs +++ b/src/rustc/middle/region.rs @@ -434,7 +434,11 @@ type determine_rp_ctxt = @{ dep_map: dep_map, worklist: dvec<ast::node_id>, + // the innermost enclosing item id mut item_id: ast::node_id, + + // true when we are within an item but not within a method. + // see long discussion on region_is_relevant() mut anon_implies_rp: bool }; @@ -466,6 +470,38 @@ impl methods for determine_rp_ctxt { if !vec.contains(to) { vec.push(to); } } + // Determines whether a reference to a region that appears in the + // AST implies that the enclosing type is region-parameterized. + // + // This point is subtle. Here are four examples to make it more + // concrete. + // + // 1. impl foo for &int { ... } + // 2. impl foo for &self/int { ... } + // 3. impl foo for bar { fn m() -> &self/int { ... } } + // 4. impl foo for bar { fn m() -> &int { ... } } + // + // In case 1, the anonymous region is being referenced, + // but it appears in a context where the anonymous region + // resolves to self, so the impl foo is region-parameterized. + // + // In case 2, the self parameter is written explicitly. + // + // In case 3, the method refers to self, so that implies that the + // impl must be region parameterized. (If the type bar is not + // region parameterized, that is an error, because the self region + // is effectively unconstrained, but that is detected elsewhere). + // + // In case 4, the anonymous region is referenced, but it + // bound by the method, so it does not refer to self. This impl + // need not be region parameterized. + // + // So the rules basically are: the `self` region always implies + // that the enclosing type is region parameterized. The anonymous + // region also does, unless it appears within a method, in which + // case it is bound. We handle this by setting a flag + // (anon_implies_rp) to true when we enter an item and setting + // that flag to false when we enter a method. fn region_is_relevant(r: @ast::region) -> bool { alt r.node { ast::re_anon {self.anon_implies_rp} |
