Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libsyntax: stop early enough if keyword is found instead of ident #28444

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl<'a> Parser<'a> {
}

pub fn parse_ident(&mut self) -> PResult<ast::Ident> {
self.check_strict_keywords();
try!(self.check_strict_keywords());
try!(self.check_reserved_keywords());
match self.token {
token::Ident(i, _) => {
Expand Down Expand Up @@ -640,13 +640,13 @@ impl<'a> Parser<'a> {
}

/// Signal an error if the given string is a strict keyword
pub fn check_strict_keywords(&mut self) {
pub fn check_strict_keywords(&mut self) -> PResult<()> {
if self.token.is_strict_keyword() {
let token_str = self.this_token_to_string();
let span = self.span;
self.span_err(span,
&format!("expected identifier, found keyword `{}`",
token_str));
Err(self.fatal(&format!("expected identifier, found keyword `{}`",
token_str)))
} else {
Ok(())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub trait Foo<T> {

fn foo2<I>(x: <I as for<'x> Foo<&'x isize>>::A)
//~^ ERROR expected identifier, found keyword `for`
//~| ERROR expected one of `::` or `>`
{
}

Expand Down
1 change: 0 additions & 1 deletion src/test/parse-fail/keywords-followed-by-double-colon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@

fn main() {
struct::foo(); //~ ERROR expected identifier
mut::baz(); //~ ERROR expected identifier
}
1 change: 0 additions & 1 deletion src/test/parse-fail/removed-syntax-field-let.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
struct s {
let foo: (),
//~^ ERROR expected identifier, found keyword `let`
//~^^ ERROR expected `:`, found `foo`
}
1 change: 0 additions & 1 deletion src/test/parse-fail/removed-syntax-mut-vec-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
fn f() {
let v = [mut 1, 2, 3, 4];
//~^ ERROR expected identifier, found keyword `mut`
//~^^ ERROR expected one of `!`, `,`, `.`, `::`, `;`, `]`, `{`, or an operator, found `1`
}
1 change: 0 additions & 1 deletion src/test/parse-fail/removed-syntax-mut-vec-ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@

type v = [mut isize];
//~^ ERROR expected identifier, found keyword `mut`
//~^^ ERROR expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `]`, found `isize`
1 change: 0 additions & 1 deletion src/test/parse-fail/removed-syntax-uniq-mut-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
fn f() {
let a_box = box mut 42;
//~^ ERROR expected identifier, found keyword `mut`
//~^^ ERROR expected one of `!`, `.`, `::`, `;`, `{`, or an operator, found `42`
}
1 change: 0 additions & 1 deletion src/test/parse-fail/removed-syntax-uniq-mut-ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@

type mut_box = Box<mut isize>;
//~^ ERROR expected identifier, found keyword `mut`
//~^^ ERROR expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `isize`
2 changes: 0 additions & 2 deletions src/test/parse-fail/unsized2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ fn f<X>() {}
pub fn main() {
f<type>();
//~^ ERROR expected identifier, found keyword `type`
//~^^ ERROR: chained comparison
//~^^^ HELP: use `::<
}
1 change: 0 additions & 1 deletion src/test/parse-fail/use-as-where-use-ends-with-mod-sep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
// compile-flags: -Z parse-only

use std::any:: as foo; //~ ERROR expected identifier, found keyword `as`
//~^ ERROR: expected one of `::`, `;`, or `as`, found `foo`