Poor recovery from pub let x = ...
#101622
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given the following code:
The current output is:
The latter two errors are redundant and confusing given the first. It seems like the compiler is trying to recover by parsing the tokens following
pub
as an expression, thus disallowinglet
, but there's no obvious reason to do that. whereas parsing them as a statement would be more useful and more analogous to the item syntax.I propose one or both of the following improvements:
pub
not followed by an item, try recovery by parsing as a statement, as if thepub
token was absent. (This should be sufficient to produce only one, meaningful, error message in this situation.)pub let
specifically, and suggest eitherlet
orpub static/const
. (This might be part of a general improvement to handling confusion between items and statements — Provide a better error when code is put outside of a function #92615.)Possible output would be:
rustc version: 1.63.0 stable. On nightly, a fourth error related to the let-expression interpretation is emitted.
The text was updated successfully, but these errors were encountered: