No mention of "field init shorthand" #98917
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:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6fd5b067e894e9be655bd28918386f7e
The current output is:
The first message is about an expected comma or closing curly brace, which is not terribly helpful - we do want to initialize more than one member, so why would we be required to end the instantiation after the
id,
?The "missing field
option
" message will perhaps prompt the reader to explicitly name theoption
member, like this:and this will solve the problem, which may trick the reader into believing that only "simple" initializers can be used when instantiating the
Struct
(andSome(1)
would not be considered "simple").Reading the output of
rustc --explain E0063
does not help, because it says "A struct's or struct-like enum variant's field was not provided". The actual problem is that while theid
member can use the "field init shorthand" (because it is called the same as thecreate
's argument), theoption
member cannot, but there's no such hint neither in the compiler messages nor in therustc --explain E0063
.Ideally some mention of the "field init shorthand" should be provided either in the messages, or in the output of
rustc --explain
.The text was updated successfully, but these errors were encountered: