Skip to content

libsyntax: note that let a = (let b = something) is invalid #30765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2211,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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message needs some work: why single let out here? Rather than other keywords, it seems oddly specific. You probably mean that "a let statement is not an expression", not that let it self is not. It is not clear what "this way" means.

Maybe better, something like: expected expression, found statement; variable declaration usingletis a statement. Perhaps the bit after the semicolon should be a note.

Note that neither then before or after message fit the let let x = ... case, where we expect an identifier, not a keyword, so the original error is better, and the new one (either as well as or instead of) is wrong.

return Err(self.fatal(&msg));
} else if self.check(&token::ModSep) ||
self.token.is_ident() &&
!self.check_keyword(keywords::True) &&
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-fail-fulldeps/qquote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down