about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorLindsey Kuper <lindsey@rockstargirl.org>2012-07-13 15:27:21 -0700
committerLindsey Kuper <lindsey@rockstargirl.org>2012-07-13 15:31:39 -0700
commit78d11b899b6ec4d2ed8c18499c1213fecd3c6424 (patch)
tree287e005e4a9ae8c2c40420d5e30827414dbad40f /src/libsyntax/parse/parser.rs
parent5a63b2100ed69b14e929671430101cc786f41ea7 (diff)
downloadrust-78d11b899b6ec4d2ed8c18499c1213fecd3c6424.tar.gz
rust-78d11b899b6ec4d2ed8c18499c1213fecd3c6424.zip
Clean up various bugs with trait parsing.
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 54c268722c8..5effab94397 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -279,41 +279,46 @@ class parser {
         do self.parse_unspanned_seq(token::LBRACE, token::RBRACE,
                                     seq_sep_none()) |p| {
             let attrs = p.parse_outer_attributes();
-            let flo = p.span.lo;
+            let lo = p.span.lo;
             let pur = p.parse_fn_purity();
+            // NB: at the moment, trait methods are public by default; this
+            // could change.
+            let vis = p.parse_visibility(public);
             let ident = p.parse_method_name();
             let tps = p.parse_ty_params();
-            let d = p.parse_ty_fn_decl(pur), fhi = p.last_span.hi;
-            #debug["parse_trait_methods(): trait method ends in %s",
-                   token_to_str(self.reader, self.token)];
-            alt self.token {
+            let d = p.parse_ty_fn_decl(pur);
+            let hi = p.last_span.hi;
+            #debug["parse_trait_methods(): trait method signature ends in \
+                    `%s`",
+                   token_to_str(p.reader, p.token)];
+            alt p.token {
               token::SEMI {
-                self.bump();
+                p.bump();
+                #debug["parse_trait_methods(): parsing required method"];
+                // NB: at the moment, visibility annotations on required
+                // methods are ignored; this could change.
                 required({ident: ident, attrs: attrs,
                           decl: {purity: pur with d}, tps: tps,
-                          span: mk_sp(flo, fhi)})
+                          span: mk_sp(lo, hi)})
               }
               token::LBRACE {
-                self.bump();
+                #debug["parse_trait_methods(): parsing provided method"];
                 let (inner_attrs, body) =
-                    self.parse_inner_attrs_and_block(true);
+                    p.parse_inner_attrs_and_block(true);
                 let attrs = vec::append(attrs, inner_attrs);
-                self.eat(token::RBRACE);
                 provided(@{ident: ident,
                            attrs: attrs,
                            tps: tps,
                            decl: d,
                            body: body,
-                           id: self.get_id(),
-                           span: mk_sp(flo, fhi),
-                           self_id: self.get_id(),
-                           // Provided traits methods always public for now
-                           vis: public})
+                           id: p.get_id(),
+                           span: mk_sp(lo, hi),
+                           self_id: p.get_id(),
+                           vis: vis})
               }
 
-              _ { self.fatal("expected `;` or `}` \
-                              but found `"
-                             + token_to_str(self.reader, self.token) + "`");
+              _ { p.fatal("expected `;` or `}` but found `" +
+                          token_to_str(p.reader, p.token) + "`");
                 }
             }
         }