Error when fn
keyword is missing could be more explicit
#125446
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-parser
Area: The parsing of Rust source code to an AST
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
Rationale and extra context
The current error appears to be based entirely on the syntax tree. However, adding a
!
or::
in this case won't provide compilable code by itself.It may be possible to determine that the incorrect code "looks like" a function definition which is missing the
fn
keyword in front of it (the author doesn't have the knowledge to say for sure). Especially in cases where the context doesn't permit calling a function (i.e. not inside another function).This would provide immediately actionable diagnostics.
Other cases
A missing
struct
orenum
keyword could be differentiated by the contents of the braces, or potentially from the case of the first character of the name (assuming it's correct).Missing
struct
:Missing
enum
:A unit struct is somewhat more ambiguous (if the name is capitalized correctly then there is a hint):
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: