Skip to content

Commit b6faae1

Browse files
committed
Rollup merge of #31211 - Manishearth:pr-30765, r=nrc
r? @eddyb or @nrc
2 parents ef96037 + 065e47e commit b6faae1

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/libsyntax/errors/emitter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use self::Destination::*;
1212

13-
use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span};
13+
use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, DUMMY_SP, Pos, Span};
1414
use diagnostics;
1515

1616
use errors::{Level, RenderSpan, DiagnosticBuilder};
@@ -109,8 +109,8 @@ impl Emitter for EmitterWriter {
109109
lvl: Level) {
110110
let error = match sp {
111111
Some(COMMAND_LINE_SP) => self.emit_(FileLine(COMMAND_LINE_SP), msg, code, lvl),
112+
Some(DUMMY_SP) | None => print_diagnostic(&mut self.dst, "", lvl, msg, code),
112113
Some(sp) => self.emit_(FullSpan(sp), msg, code, lvl),
113-
None => print_diagnostic(&mut self.dst, "", lvl, msg, code),
114114
};
115115

116116
if let Err(e) = error {

src/libsyntax/parse/parser.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2218,6 +2218,12 @@ impl<'a> Parser<'a> {
22182218
ex = ExprBreak(None);
22192219
}
22202220
hi = self.last_span.hi;
2221+
} else if self.token.is_keyword(keywords::Let) {
2222+
// Catch this syntax error here, instead of in `check_strict_keywords`, so
2223+
// that we can explicitly mention that let is not to be used as an expression
2224+
let mut db = self.fatal("expected expression, found statement (`let`)");
2225+
db.note("variable declaration using `let` is a statement");
2226+
return Err(db);
22212227
} else if self.check(&token::ModSep) ||
22222228
self.token.is_ident() &&
22232229
!self.check_keyword(keywords::True) &&

src/test/run-fail-fulldeps/qquote.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-cross-compile
1212

13-
// error-pattern:expected identifier, found keyword `let`
13+
// error-pattern:expected expression, found statement (`let`)
1414

1515
#![feature(quote, rustc_private)]
1616

0 commit comments

Comments
 (0)