Skip to content

Commit

Permalink
Allow _ param name in trait default method for rust-lang#8468.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Sep 2, 2013
1 parent 7ff102a commit 4fa28a2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ impl Drop for Parser {
fn drop(&self) {}
}

fn is_plain_ident_or_underscore(t: &token::Token) -> bool {
match *t {
token::IDENT(_, false) | token::UNDERSCORE => true,
_ => false,
}
}

impl Parser {
// convert a token to a string using self's reader
pub fn token_to_str(&self, token: &token::Token) -> ~str {
Expand Down Expand Up @@ -1242,11 +1249,13 @@ impl Parser {
_ => 0
};

debug!("parser is_named_argument offset:%u", offset);

if offset == 0 {
is_plain_ident(&*self.token)
is_plain_ident_or_underscore(&*self.token)
&& self.look_ahead(1, |t| *t == token::COLON)
} else {
self.look_ahead(offset, |t| is_plain_ident(t))
self.look_ahead(offset, |t| is_plain_ident_or_underscore(t))
&& self.look_ahead(offset + 1, |t| *t == token::COLON)
}
}
Expand All @@ -1256,6 +1265,8 @@ impl Parser {
pub fn parse_arg_general(&self, require_name: bool) -> arg {
let is_mutbl = self.eat_keyword(keywords::Mut);
let pat = if require_name || self.is_named_argument() {
debug!("parse_arg_general parse_pat (require_name:%?)",
require_name);
self.parse_arg_mode();
let pat = self.parse_pat();

Expand All @@ -1266,6 +1277,7 @@ impl Parser {
self.expect(&token::COLON);
pat
} else {
debug!("parse_arg_general ident_to_pat");
ast_util::ident_to_pat(self.get_id(),
*self.last_span,
special_idents::invalid)
Expand Down

0 comments on commit 4fa28a2

Please sign in to comment.