Merge remote-tracking branch 'origin/master' into proc_macro_api

This commit is contained in:
Alex Crichton
2017-07-05 08:42:13 -07:00
605 changed files with 6469 additions and 3681 deletions

View File

@@ -511,14 +511,13 @@ impl<'a> Parser<'a> {
}
pub fn this_token_descr(&self) -> String {
let s = self.this_token_to_string();
if self.token.is_strict_keyword() {
format!("keyword `{}`", s)
} else if self.token.is_reserved_keyword() {
format!("reserved keyword `{}`", s)
} else {
format!("`{}`", s)
}
let prefix = match &self.token {
t if t.is_special_ident() => "reserved identifier ",
t if t.is_used_keyword() => "keyword ",
t if t.is_unused_keyword() => "reserved keyword ",
_ => "",
};
format!("{}`{}`", prefix, self.this_token_to_string())
}
pub fn unexpected_last<T>(&self, t: &token::Token) -> PResult<'a, T> {
@@ -637,10 +636,12 @@ impl<'a> Parser<'a> {
}
pub fn parse_ident(&mut self) -> PResult<'a, ast::Ident> {
self.check_strict_keywords();
self.check_reserved_keywords();
match self.token {
token::Ident(i) => {
if self.token.is_reserved_ident() {
self.span_err(self.span, &format!("expected identifier, found {}",
self.this_token_descr()));
}
self.bump();
Ok(i)
}
@@ -713,25 +714,6 @@ impl<'a> Parser<'a> {
}
}
/// Signal an error if the given string is a strict keyword
pub fn check_strict_keywords(&mut self) {
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));
}
}
/// Signal an error if the current token is a reserved keyword
pub fn check_reserved_keywords(&mut self) {
if self.token.is_reserved_keyword() {
let token_str = self.this_token_to_string();
self.fatal(&format!("`{}` is a reserved keyword", token_str)).emit()
}
}
fn check_ident(&mut self) -> bool {
if self.token.is_ident() {
true
@@ -1659,8 +1641,10 @@ impl<'a> Parser<'a> {
Ok(codemap::Spanned { node: lit, span: lo.to(self.prev_span) })
}
/// matches '-' lit | lit
/// matches '-' lit | lit (cf. ast_validation::AstValidator::check_expr_within_pat)
pub fn parse_pat_literal_maybe_minus(&mut self) -> PResult<'a, P<Expr>> {
maybe_whole_expr!(self);
let minus_lo = self.span;
let minus_present = self.eat(&token::BinOp(token::Minus));
let lo = self.span;
@@ -2299,7 +2283,7 @@ impl<'a> Parser<'a> {
ex = ExprKind::Break(lt, e);
hi = self.prev_span;
} else if self.token.is_keyword(keywords::Let) {
// Catch this syntax error here, instead of in `check_strict_keywords`, so
// Catch this syntax error here, instead of in `parse_ident`, so
// that we can explicitly mention that let is not to be used as an expression
let mut db = self.fatal("expected expression, found statement (`let`)");
db.note("variable declaration using `let` is a statement");
@@ -3541,7 +3525,7 @@ impl<'a> Parser<'a> {
// Parse box pat
let subpat = self.parse_pat()?;
pat = PatKind::Box(subpat);
} else if self.token.is_ident() && !self.token.is_any_keyword() &&
} else if self.token.is_ident() && !self.token.is_reserved_ident() &&
self.parse_as_ident() {
// Parse ident @ pat
// This can give false positives and parse nullary enums,
@@ -3816,7 +3800,7 @@ impl<'a> Parser<'a> {
fn is_union_item(&self) -> bool {
self.token.is_keyword(keywords::Union) &&
self.look_ahead(1, |t| t.is_ident() && !t.is_any_keyword())
self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident())
}
fn is_defaultness(&self) -> bool {