-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Give a better error message for functions in struct { ... }
#76421
Comments
By the way, the second error about |
What are the chances we can also provide a mechanically applicable suggestion here that adds an impl block? |
For a while I've been thinking about writing a generic "item muncher" to be used as a fall-through parser to have a very rudimentary check for "item-like" blocks. If we had something like that, we could get a reasonable span for the incorrectly nested item, to recover the parse state for the I was sure there was a ticket for this already, but I cannot find it :)
|
I’d like to try to do the first step of changing the current diagnostic |
…struct, r=jackh726 Improve diagnostics for functions in `struct` definitions Tries to implement rust-lang#76421. This is probably going to need unit tests, but I wanted to hear from review all the cases tests should cover. I'd like to follow up with the "mechanically applicable suggestion here that adds an impl block" step, but I'd need guidance. My idea for now would be to try to parse a function, and if that succeeds, create a dummy `ast::Item` impl block to then format it using `pprust`. Would that be a viable approach? Is there a better alternative? r? `@matklad` cc `@estebank`
Current output:
I think we can close this ticket. We also detect when someone uses a |
Thought of this while reading https://fasterthanli.me/articles/i-am-a-java-csharp-c-or-cplusplus-dev-time-to-do-some-rust (thank you @fasterthanlime !). Currently putting a function in a struct definition is a syntax error without much hint of what went wrong (playground):
Instead it should say something like
The text was updated successfully, but these errors were encountered: