From 4fa28a2e855fc47cea8475000a15e2df24799e12 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 3 Sep 2013 01:58:12 +0200 Subject: [PATCH 1/3] Allow _ param name in trait default method for #8468. --- src/libsyntax/parse/parser.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 02af6d23b4415..b939ac109315f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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 { @@ -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) } } @@ -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(); @@ -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) From ba1f44d24fd740bf9f74f99ffcd4733151b84fab Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 3 Sep 2013 01:58:36 +0200 Subject: [PATCH 2/3] Regression test for #8468. --- src/test/run-pass/default-method-parsing.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/test/run-pass/default-method-parsing.rs diff --git a/src/test/run-pass/default-method-parsing.rs b/src/test/run-pass/default-method-parsing.rs new file mode 100644 index 0000000000000..ec607102566aa --- /dev/null +++ b/src/test/run-pass/default-method-parsing.rs @@ -0,0 +1,15 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + fn m(&self, _:int) { } +} + +fn main() { } From 1b3cd960decbaad3fc585c4ac4e5ec4dd8ceabc9 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 3 Sep 2013 11:15:41 +0200 Subject: [PATCH 3/3] Incorporate review feedback. Fix #8468. --- src/libsyntax/parse/parser.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b939ac109315f..14b133b43798c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -348,10 +348,7 @@ impl Drop for Parser { } fn is_plain_ident_or_underscore(t: &token::Token) -> bool { - match *t { - token::IDENT(_, false) | token::UNDERSCORE => true, - _ => false, - } + is_plain_ident(t) || *t == token::UNDERSCORE } impl Parser {