missing struct declaration type leads to confusing type ascription diagnostic #73941
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-confusing
Diagnostics: Confusing error or lint that should be reworked.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
While trying to get started with rust, I was attempting to declare a global instance of a struct for various reasons (integrating into a device driver framework). This was based on the nightly toolchain because of some other nightly features. Having written a lot of C, but not a lot of rust, I mistakenly declared a structure leaving out the type on the right hand side of the equals sign. This led to a relatively confusing message about type ascription. Here's a reduced version of the code that generates this as of version
rustc 1.46.0-nightly (16957bd4d 2020-06-30)
though I first encountered this onrustc 1.44.0-nightly (b77aefb76 2020-04-14)
.When building this with a nightly rustc you receive the following error message:
While I now understand that this was trying to use type ascription incidentally, this sent me initially down the path of trying to figure out what type ascription was and a number of wrong paths. I know at one point I did try to add the feature there, as it seems to be suggesting that, but that didn't change anything. Upon better understanding the problem and what I did wrong, I wouldn't expect adding the feature to have changed anything, but when getting started these messages are usually pretty helpful in indicating what to change or what's going on which is what led me to try it.
If there's some way to indicate that someone might have left a type declaration out in this case, that might be useful and help save someone else who's learning some time in the future.
The text was updated successfully, but these errors were encountered: