diff --git a/src/libsyntax/errors/emitter.rs b/src/libsyntax/errors/emitter.rs index c21bf1e6a1f..51013d68930 100644 --- a/src/libsyntax/errors/emitter.rs +++ b/src/libsyntax/errors/emitter.rs @@ -10,7 +10,7 @@ use self::Destination::*; -use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span}; +use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, DUMMY_SP, Pos, Span}; use diagnostics; use errors::{Level, RenderSpan, DiagnosticBuilder}; @@ -109,8 +109,8 @@ fn emit(&mut self, lvl: Level) { let error = match sp { Some(COMMAND_LINE_SP) => self.emit_(FileLine(COMMAND_LINE_SP), msg, code, lvl), + Some(DUMMY_SP) | None => print_diagnostic(&mut self.dst, "", lvl, msg, code), Some(sp) => self.emit_(FullSpan(sp), msg, code, lvl), - None => print_diagnostic(&mut self.dst, "", lvl, msg, code), }; if let Err(e) = error { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index acce6ed87d0..2249faac6d7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2218,6 +2218,12 @@ fn parse_bottom_expr(&mut self) -> PResult<'a, P> { 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 mut db = self.fatal("expected expression, found statement (`let`)"); + db.note("variable declaration using `let` is a statement"); + return Err(db); } else if self.check(&token::ModSep) || self.token.is_ident() && !self.check_keyword(keywords::True) && diff --git a/src/test/run-fail-fulldeps/qquote.rs b/src/test/run-fail-fulldeps/qquote.rs index d42a777a019..41a6fd05c37 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:expected expression, found statement (`let`) #![feature(quote, rustc_private)]