Skip to content

Commit 8183c74

Browse files
committed
auto merge of #8940 : pnkfelix/rust/fsk-8468-allow-underscore-paramname-in-trait-default-method, r=alexcrichton
Fix #8468. (Though the right answer in the end, as noted on the dialogue on the ticket, might be to just require trait methods to name their parameters, regardless of whether they have a default method implementation or not.)
2 parents 58decdd + 1b3cd96 commit 8183c74

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ impl Drop for Parser {
347347
fn drop(&self) {}
348348
}
349349

350+
fn is_plain_ident_or_underscore(t: &token::Token) -> bool {
351+
is_plain_ident(t) || *t == token::UNDERSCORE
352+
}
353+
350354
impl Parser {
351355
// convert a token to a string using self's reader
352356
pub fn token_to_str(&self, token: &token::Token) -> ~str {
@@ -1242,11 +1246,13 @@ impl Parser {
12421246
_ => 0
12431247
};
12441248

1249+
debug!("parser is_named_argument offset:%u", offset);
1250+
12451251
if offset == 0 {
1246-
is_plain_ident(&*self.token)
1252+
is_plain_ident_or_underscore(&*self.token)
12471253
&& self.look_ahead(1, |t| *t == token::COLON)
12481254
} else {
1249-
self.look_ahead(offset, |t| is_plain_ident(t))
1255+
self.look_ahead(offset, |t| is_plain_ident_or_underscore(t))
12501256
&& self.look_ahead(offset + 1, |t| *t == token::COLON)
12511257
}
12521258
}
@@ -1256,6 +1262,8 @@ impl Parser {
12561262
pub fn parse_arg_general(&self, require_name: bool) -> arg {
12571263
let is_mutbl = self.eat_keyword(keywords::Mut);
12581264
let pat = if require_name || self.is_named_argument() {
1265+
debug!("parse_arg_general parse_pat (require_name:%?)",
1266+
require_name);
12591267
self.parse_arg_mode();
12601268
let pat = self.parse_pat();
12611269

@@ -1266,6 +1274,7 @@ impl Parser {
12661274
self.expect(&token::COLON);
12671275
pat
12681276
} else {
1277+
debug!("parse_arg_general ident_to_pat");
12691278
ast_util::ident_to_pat(self.get_id(),
12701279
*self.last_span,
12711280
special_idents::invalid)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Foo {
12+
fn m(&self, _:int) { }
13+
}
14+
15+
fn main() { }

0 commit comments

Comments
 (0)