Auto merge of #32506 - petrochenkov:use, r=Manishearth
syntax: Extra diagnostics for `_` used in an identifier position Closes https://github.com/rust-lang/rust/issues/32501
This commit is contained in:
commit
e1195c24bb
@ -574,9 +574,12 @@ pub fn parse_ident(&mut self) -> PResult<'a, ast::Ident> {
|
||||
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 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
|
||||
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 @@ fn parse_name_and_ty(&mut self, pr: Visibility,
|
||||
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()?;
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
// compile-flags: --cfg ""
|
||||
|
||||
// error-pattern: expected ident, found
|
||||
// error-pattern: expected identifier, found
|
||||
|
||||
pub fn main() {
|
||||
}
|
||||
|
@ -40,7 +40,7 @@
|
||||
//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 `,`
|
||||
|
@ -40,7 +40,7 @@
|
||||
//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 `,`
|
||||
|
21
src/test/parse-fail/issue-32501.rs
Normal file
21
src/test/parse-fail/issue-32501.rs
Normal file
@ -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
|
||||
}
|
@ -13,5 +13,5 @@
|
||||
// http://phpsadness.com/sad/1
|
||||
|
||||
fn main() {
|
||||
::; //~ ERROR expected ident, found `;`
|
||||
::; //~ ERROR expected identifier, found `;`
|
||||
}
|
||||
|
@ -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() { }
|
||||
|
Loading…
Reference in New Issue
Block a user