diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index edb1f7eb926..f3809455fe0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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());