Skip to content

Commit 78d11b8

Browse files
committed
Clean up various bugs with trait parsing.
1 parent 5a63b21 commit 78d11b8

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -279,41 +279,46 @@ class parser {
279279
do self.parse_unspanned_seq(token::LBRACE, token::RBRACE,
280280
seq_sep_none()) |p| {
281281
let attrs = p.parse_outer_attributes();
282-
let flo = p.span.lo;
282+
let lo = p.span.lo;
283283
let pur = p.parse_fn_purity();
284+
// NB: at the moment, trait methods are public by default; this
285+
// could change.
286+
let vis = p.parse_visibility(public);
284287
let ident = p.parse_method_name();
285288
let tps = p.parse_ty_params();
286-
let d = p.parse_ty_fn_decl(pur), fhi = p.last_span.hi;
287-
#debug["parse_trait_methods(): trait method ends in %s",
288-
token_to_str(self.reader, self.token)];
289-
alt self.token {
289+
let d = p.parse_ty_fn_decl(pur);
290+
let hi = p.last_span.hi;
291+
#debug["parse_trait_methods(): trait method signature ends in \
292+
`%s`",
293+
token_to_str(p.reader, p.token)];
294+
alt p.token {
290295
token::SEMI {
291-
self.bump();
296+
p.bump();
297+
#debug["parse_trait_methods(): parsing required method"];
298+
// NB: at the moment, visibility annotations on required
299+
// methods are ignored; this could change.
292300
required({ident: ident, attrs: attrs,
293301
decl: {purity: pur with d}, tps: tps,
294-
span: mk_sp(flo, fhi)})
302+
span: mk_sp(lo, hi)})
295303
}
296304
token::LBRACE {
297-
self.bump();
305+
#debug["parse_trait_methods(): parsing provided method"];
298306
let (inner_attrs, body) =
299-
self.parse_inner_attrs_and_block(true);
307+
p.parse_inner_attrs_and_block(true);
300308
let attrs = vec::append(attrs, inner_attrs);
301-
self.eat(token::RBRACE);
302309
provided(@{ident: ident,
303310
attrs: attrs,
304311
tps: tps,
305312
decl: d,
306313
body: body,
307-
id: self.get_id(),
308-
span: mk_sp(flo, fhi),
309-
self_id: self.get_id(),
310-
// Provided traits methods always public for now
311-
vis: public})
314+
id: p.get_id(),
315+
span: mk_sp(lo, hi),
316+
self_id: p.get_id(),
317+
vis: vis})
312318
}
313319
314-
_ { self.fatal("expected `;` or `}` \
315-
but found `"
316-
+ token_to_str(self.reader, self.token) + "`");
320+
_ { p.fatal("expected `;` or `}` but found `" +
321+
token_to_str(p.reader, p.token) + "`");
317322
}
318323
}
319324
}

0 commit comments

Comments
 (0)