libsyntax: move check for keyword Let to a more logical spot

This commit is contained in:
Daan Sprenkels 2016-01-08 00:01:59 +01:00 committed by Manish Goregaokar
parent 082c03b078
commit 79f2cff44e

View File

@ -2134,6 +2134,12 @@ impl<'a> Parser<'a> {
}
hi = self.last_span.hi;
}
_ if self.token.is_keyword(keywords::Let) => {
// Catch this syntax error here, instead of in `check_strict_keywords`, so that
// we can explicitly mention that let is not to be used as an expression
let msg = "`let` is not an expression, so it cannot be used in this way";
return Err(self.diagnostic().struct_span_err(self.span, &msg));
},
_ => {
if self.eat_lt() {
let (qself, path) =
@ -2199,12 +2205,6 @@ impl<'a> Parser<'a> {
UnsafeBlock(ast::UserProvided),
attrs);
}
if self.eat_keyword(keywords::Let) {
return Err(self.span_fatal(self.span,
"`let` is not an expression, so it cannot \
be used in this way"))
}
if self.eat_keyword(keywords::Return) {
if self.token.can_begin_expr() {
let e = try!(self.parse_expr());