mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
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 @@ impl<'a> Parser<'a> {
|
|||||||
self.bug("ident interpolation not converted to real token");
|
self.bug("ident interpolation not converted to real token");
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let token_str = self.this_token_to_string();
|
let mut err = self.fatal(&format!("expected identifier, found `{}`",
|
||||||
Err(self.fatal(&format!("expected ident, found `{}`",
|
self.this_token_to_string()));
|
||||||
token_str)))
|
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,
|
fn parse_pat_ident(&mut self,
|
||||||
binding_mode: ast::BindingMode)
|
binding_mode: ast::BindingMode)
|
||||||
-> PResult<'a, PatKind> {
|
-> 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 ident = self.parse_ident()?;
|
||||||
let last_span = self.last_span;
|
let last_span = self.last_span;
|
||||||
let name = codemap::Spanned{span: last_span, node: ident};
|
let name = codemap::Spanned{span: last_span, node: ident};
|
||||||
@ -3847,9 +3844,6 @@ impl<'a> Parser<'a> {
|
|||||||
Visibility::Inherited => self.span.lo,
|
Visibility::Inherited => self.span.lo,
|
||||||
Visibility::Public => self.last_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()?;
|
let name = self.parse_ident()?;
|
||||||
self.expect(&token::Colon)?;
|
self.expect(&token::Colon)?;
|
||||||
let ty = self.parse_ty_sum()?;
|
let ty = self.parse_ty_sum()?;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
// compile-flags: --cfg ""
|
// compile-flags: --cfg ""
|
||||||
|
|
||||||
// error-pattern: expected ident, found
|
// error-pattern: expected identifier, found
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ type Type_5_<'a> = Type_1_<'a, ()>;
|
|||||||
//type Type_7 = Box<(),,>; // error: expected type, found `,`
|
//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_5_<'a> = Type_1_<'a, ()>;
|
|||||||
//type Type_7 = Box<(),,>; // error: expected type, found `,`
|
//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
|
// http://phpsadness.com/sad/1
|
||||||
|
|
||||||
fn main() {
|
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::<isize,usize>::new(); // OK
|
||||||
|
|
||||||
let b = Box::Bar::()::new();
|
let b = Box::Bar::()::new();
|
||||||
//~^ ERROR expected ident, found `(`
|
//~^ ERROR expected identifier, found `(`
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
Loading…
Reference in New Issue
Block a user