about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-03-31 14:08:44 -0700
committerbors <bors@rust-lang.org>2016-03-31 14:08:44 -0700
commite1195c24bb567019d7cdc65bf5a4c642e38475d1 (patch)
tree07df8569867640934cb2f9617a1a05eff6a5770c /src/libsyntax
parent3399d19a2c9503d991e4a315118b2d6146f66046 (diff)
parent1cbdf4e7d3781ac6f54840df9ee1059ea0f894d3 (diff)
downloadrust-e1195c24bb567019d7cdc65bf5a4c642e38475d1.tar.gz
rust-e1195c24bb567019d7cdc65bf5a4c642e38475d1.zip
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
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/parse/parser.rs18
1 files changed, 6 insertions, 12 deletions
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()?;