From 7229ca9c3446d5cca83c66705833f73fc33838bc Mon Sep 17 00:00:00 2001 From: Daan Sprenkels Date: Wed, 6 Jan 2016 23:58:45 +0100 Subject: [PATCH 1/4] libsyntax: note that `let a = (let b = something)` is invalid in parse_bottom_expr (parser.rs) --- src/libsyntax/parse/parser.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index db746af998d9f..a5dcfa05d008b 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2192,6 +2192,12 @@ impl<'a> Parser<'a> { UnsafeBlock(ast::UserProvided), attrs); } + if try!(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 try!(self.eat_keyword(keywords::Return) ){ if self.token.can_begin_expr() { let e = try!(self.parse_expr()); From a74585ba43c247f039745afbb34c99804b0040e9 Mon Sep 17 00:00:00 2001 From: Daan Sprenkels Date: Fri, 8 Jan 2016 00:01:59 +0100 Subject: [PATCH 2/4] libsyntax: move check for keyword Let to a more logical spot --- src/libsyntax/parse/parser.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a5dcfa05d008b..1a5ea45e264ef 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2127,6 +2127,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 try!(self.eat_lt()){ let (qself, path) = @@ -2192,12 +2198,6 @@ impl<'a> Parser<'a> { UnsafeBlock(ast::UserProvided), attrs); } - if try!(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 try!(self.eat_keyword(keywords::Return) ){ if self.token.can_begin_expr() { let e = try!(self.parse_expr()); From 8c749577701d0fc48442a4f716c49a86d1294891 Mon Sep 17 00:00:00 2001 From: Daan Sprenkels Date: Thu, 14 Jan 2016 16:04:35 +0100 Subject: [PATCH 3/4] Update qquote.rs test case and make unexpected `let` error fatal --- src/libsyntax/parse/parser.rs | 12 ++++++------ src/test/run-fail-fulldeps/qquote.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1a5ea45e264ef..19df3707f5310 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2127,12 +2127,6 @@ 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 try!(self.eat_lt()){ let (qself, path) = @@ -2155,6 +2149,12 @@ impl<'a> Parser<'a> { let lo = self.last_span.lo; return self.parse_while_expr(None, lo, attrs); } + 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"; + self.span_err(self.span, msg); + } if self.token.is_lifetime() { let lifetime = self.get_lifetime(); let lo = self.span.lo; diff --git a/src/test/run-fail-fulldeps/qquote.rs b/src/test/run-fail-fulldeps/qquote.rs index d42a777a019a3..297a1da25b5d7 100644 --- a/src/test/run-fail-fulldeps/qquote.rs +++ b/src/test/run-fail-fulldeps/qquote.rs @@ -10,7 +10,7 @@ // ignore-cross-compile -// error-pattern:expected identifier, found keyword `let` +// error-pattern:`let` is not an expression, so it cannot be used in this way #![feature(quote, rustc_private)] From 740f2f39a9ba4b550a0d4f3e6259f5d4e931ca02 Mon Sep 17 00:00:00 2001 From: Daan Sprenkels Date: Thu, 14 Jan 2016 16:52:24 +0100 Subject: [PATCH 4/4] do not additionally note about unexpected identifier after unexpected let error, by moving unexpected let check into the proper if-else clause --- src/libsyntax/parse/parser.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 19df3707f5310..8b5c2f3f0c763 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2149,12 +2149,6 @@ impl<'a> Parser<'a> { let lo = self.last_span.lo; return self.parse_while_expr(None, lo, attrs); } - 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"; - self.span_err(self.span, msg); - } if self.token.is_lifetime() { let lifetime = self.get_lifetime(); let lo = self.span.lo; @@ -2217,6 +2211,11 @@ impl<'a> Parser<'a> { ex = ExprBreak(None); } hi = self.last_span.hi; + } else 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.fatal(&msg)); } else if self.check(&token::ModSep) || self.token.is_ident() && !self.check_keyword(keywords::True) &&