Skip to content

Commit 4fa28a2

Browse files
committed
Allow _ param name in trait default method for rust-lang#8468.
1 parent 7ff102a commit 4fa28a2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/libsyntax/parse/parser.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ impl Drop for Parser {
347347
fn drop(&self) {}
348348
}
349349

350+
fn is_plain_ident_or_underscore(t: &token::Token) -> bool {
351+
match *t {
352+
token::IDENT(_, false) | token::UNDERSCORE => true,
353+
_ => false,
354+
}
355+
}
356+
350357
impl Parser {
351358
// convert a token to a string using self's reader
352359
pub fn token_to_str(&self, token: &token::Token) -> ~str {
@@ -1242,11 +1249,13 @@ impl Parser {
12421249
_ => 0
12431250
};
12441251

1252+
debug!("parser is_named_argument offset:%u", offset);
1253+
12451254
if offset == 0 {
1246-
is_plain_ident(&*self.token)
1255+
is_plain_ident_or_underscore(&*self.token)
12471256
&& self.look_ahead(1, |t| *t == token::COLON)
12481257
} else {
1249-
self.look_ahead(offset, |t| is_plain_ident(t))
1258+
self.look_ahead(offset, |t| is_plain_ident_or_underscore(t))
12501259
&& self.look_ahead(offset + 1, |t| *t == token::COLON)
12511260
}
12521261
}
@@ -1256,6 +1265,8 @@ impl Parser {
12561265
pub fn parse_arg_general(&self, require_name: bool) -> arg {
12571266
let is_mutbl = self.eat_keyword(keywords::Mut);
12581267
let pat = if require_name || self.is_named_argument() {
1268+
debug!("parse_arg_general parse_pat (require_name:%?)",
1269+
require_name);
12591270
self.parse_arg_mode();
12601271
let pat = self.parse_pat();
12611272

@@ -1266,6 +1277,7 @@ impl Parser {
12661277
self.expect(&token::COLON);
12671278
pat
12681279
} else {
1280+
debug!("parse_arg_general ident_to_pat");
12691281
ast_util::ident_to_pat(self.get_id(),
12701282
*self.last_span,
12711283
special_idents::invalid)

0 commit comments

Comments
 (0)