about summary refs log tree commit diff
path: root/src/rustc/syntax
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-03-28 14:17:41 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-03-28 14:19:00 -0700
commitca6636d6b689fe209a210b0eda51e368f01cdb0f (patch)
tree7c979884781d3179bb918045f414426eb6158cea /src/rustc/syntax
parentc141e7a068e3fbb1a5d24dcd000567b7731910bb (diff)
downloadrust-ca6636d6b689fe209a210b0eda51e368f01cdb0f.tar.gz
rust-ca6636d6b689fe209a210b0eda51e368f01cdb0f.zip
Allow references to "self" within classes
Allow writing self.f within a class that has a field f. Currently,
the compiler accepts either self.f or f. In a future commit I'll
require writing self.f and not f.

Not sure whether self.f() works if f is a method (making sure that
works next).
Diffstat (limited to 'src/rustc/syntax')
-rw-r--r--src/rustc/syntax/ast.rs1
-rw-r--r--src/rustc/syntax/parse/parser.rs4
2 files changed, 4 insertions, 1 deletions
diff --git a/src/rustc/syntax/ast.rs b/src/rustc/syntax/ast.rs
index 95c5b607cd4..447d754895e 100644
--- a/src/rustc/syntax/ast.rs
+++ b/src/rustc/syntax/ast.rs
@@ -684,6 +684,7 @@ type class_ctor = spanned<class_ctor_>;
 
 #[auto_serialize]
 type class_ctor_ = {id: node_id,
+                    self_id: node_id,
                     dec: fn_decl,
                     body: blk};
 
diff --git a/src/rustc/syntax/parse/parser.rs b/src/rustc/syntax/parse/parser.rs
index 3ca2e6a588b..61cc675c492 100644
--- a/src/rustc/syntax/parse/parser.rs
+++ b/src/rustc/syntax/parse/parser.rs
@@ -2092,10 +2092,12 @@ fn parse_item_class(p: parser, attrs: [ast::attribute]) -> @ast::item {
     }
     p.bump();
     alt the_ctor {
-      some((ct_d, ct_b, ct_s)) { ret mk_item(p, lo, p.last_span.hi,
+      some((ct_d, ct_b, ct_s)) {
+          ret mk_item(p, lo, p.last_span.hi,
                                              class_name,
          ast::item_class(ty_params, items,
                          {node: {id: ctor_id,
+                                 self_id: p.get_id(),
                                  dec: ct_d,
                                  body: ct_b},
                           span: ct_s}), attrs); }