diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5141af6f2d1..9027a5b1074 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -574,9 +574,12 @@ impl<'a> Parser<'a> { self.bug("ident interpolation not converted to real token"); } _ => { - let token_str = self.this_token_to_string(); - Err(self.fatal(&format!("expected ident, found `{}`", - token_str))) + let mut err = self.fatal(&format!("expected identifier, found `{}`", + self.this_token_to_string())); + if self.token == token::Underscore { + err.fileline_note(self.span, "`_` is a wildcard pattern, not an identifier"); + } + Err(err) } } } @@ -3782,12 +3785,6 @@ impl<'a> Parser<'a> { fn parse_pat_ident(&mut self, binding_mode: ast::BindingMode) -> PResult<'a, PatKind> { - if !self.token.is_plain_ident() { - let span = self.span; - let tok_str = self.this_token_to_string(); - return Err(self.span_fatal(span, - &format!("expected identifier, found `{}`", tok_str))) - } let ident = self.parse_ident()?; let last_span = self.last_span; let name = codemap::Spanned{span: last_span, node: ident}; @@ -3847,9 +3844,6 @@ impl<'a> Parser<'a> { Visibility::Inherited => self.span.lo, Visibility::Public => self.last_span.lo, }; - if !self.token.is_plain_ident() { - return Err(self.fatal("expected ident")); - } let name = self.parse_ident()?; self.expect(&token::Colon)?; let ty = self.parse_ty_sum()?; diff --git a/src/test/compile-fail/cfg-empty-codemap.rs b/src/test/compile-fail/cfg-empty-codemap.rs index 4c27d57008d..8868a5a9549 100644 --- a/src/test/compile-fail/cfg-empty-codemap.rs +++ b/src/test/compile-fail/cfg-empty-codemap.rs @@ -12,7 +12,7 @@ // compile-flags: --cfg "" -// error-pattern: expected ident, found +// error-pattern: expected identifier, found pub fn main() { } diff --git a/src/test/compile-fail/issue-20616-8.rs b/src/test/compile-fail/issue-20616-8.rs index 07ced7a97ba..d6cf9acae9b 100644 --- a/src/test/compile-fail/issue-20616-8.rs +++ b/src/test/compile-fail/issue-20616-8.rs @@ -40,7 +40,7 @@ type Type_5_<'a> = Type_1_<'a, ()>; //type Type_7 = Box<(),,>; // error: expected type, found `,` -type Type_8<'a,,> = &'a (); //~ error: expected ident, found `,` +type Type_8<'a,,> = &'a (); //~ error: expected identifier, found `,` -//type Type_9<T,,> = Box<T>; // error: expected ident, found `,` +//type Type_9<T,,> = Box<T>; // error: expected identifier, found `,` diff --git a/src/test/compile-fail/issue-20616-9.rs b/src/test/compile-fail/issue-20616-9.rs index 7847dea69ef..d64cec446ef 100644 --- a/src/test/compile-fail/issue-20616-9.rs +++ b/src/test/compile-fail/issue-20616-9.rs @@ -40,7 +40,7 @@ type Type_5_<'a> = Type_1_<'a, ()>; //type Type_7 = Box<(),,>; // error: expected type, found `,` -//type Type_8<'a,,> = &'a (); // error: expected ident, found `,` +//type Type_8<'a,,> = &'a (); // error: expected identifier, found `,` -type Type_9<T,,> = Box<T>; //~ error: expected ident, found `,` +type Type_9<T,,> = Box<T>; //~ error: expected identifier, found `,` diff --git a/src/test/parse-fail/issue-32501.rs b/src/test/parse-fail/issue-32501.rs new file mode 100644 index 00000000000..10df093423c --- /dev/null +++ b/src/test/parse-fail/issue-32501.rs @@ -0,0 +1,21 @@ +// Copyright 2016 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z parse-only + +fn main() { + let a = 0; + let _b = 0; + let _ = 0; + let mut b = 0; + let mut _b = 0; + let mut _ = 0; //~ ERROR expected identifier, found `_` + //~^ NOTE `_` is a wildcard pattern, not an identifier +} diff --git a/src/test/parse-fail/paamayim-nekudotayim.rs b/src/test/parse-fail/paamayim-nekudotayim.rs index 63d9e941469..3466fc6e71a 100644 --- a/src/test/parse-fail/paamayim-nekudotayim.rs +++ b/src/test/parse-fail/paamayim-nekudotayim.rs @@ -13,5 +13,5 @@ // http://phpsadness.com/sad/1 fn main() { - ::; //~ ERROR expected ident, found `;` + ::; //~ ERROR expected identifier, found `;` } diff --git a/src/test/parse-fail/unboxed-closure-sugar-used-on-struct-3.rs b/src/test/parse-fail/unboxed-closure-sugar-used-on-struct-3.rs index ad2710e91e2..58564dc8621 100644 --- a/src/test/parse-fail/unboxed-closure-sugar-used-on-struct-3.rs +++ b/src/test/parse-fail/unboxed-closure-sugar-used-on-struct-3.rs @@ -24,7 +24,7 @@ fn bar() { let b = Box::Bar::<isize,usize>::new(); // OK let b = Box::Bar::()::new(); - //~^ ERROR expected ident, found `(` + //~^ ERROR expected identifier, found `(` } fn main() { }