-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
"associated function without body" error suggestion has incorrect span #83104
Comments
Probably the "free function without body" variant has this bug as well. |
The code at issue: rust/compiler/rustc_ast_passes/src/ast_validation.rs Lines 409 to 419 in acca818
|
I think I'll take a shot at this. |
That was... an easy fix. error: expected one of `->`, `;`, `where`, or `{`, found `}`
--> <anon>:5:1
|
4 | fn foo()
| --- - expected one of `->`, `;`, `where`, or `{`
| |
| while parsing this `fn`
5 | }
| ^ unexpected token
error: associated function in `impl` without body
--> <anon>:4:5
|
4 | fn foo()
| ^^^^^^^^- help: provide a definition for the function: `{ <body> }`
error: aborting due to 2 previous errors which isn't entirely satisfactory imo cause the suggestion span is directly after the |
It appears that it has a similar bug: fn foo();
Looks like this can probably be fixed similarly. |
Oh wait, that bug was caused by me. It looks like I'll probably have to implement a better solution. |
Okay, so it appears that this bug is triggered in inherent impls with and without a semicolon, and in free functions with a semicolon. I'll have to find some kind of way to change the span depending on if it had a semicolon or not. |
Okay, so it looks like in 99% of cases that trigger the same code path as this error:
the existing code is already correct, as in those cases a semicolon is (usually) required. Either we can modify the parser to give some kind of indication to the AST validator that an inherent fn/const/type has no semicolon at the end, or we can just use a hack to check if there's a semicolon at the end of the span |
I'm not quite sure how this should be fixed :/ |
@ThePuzzlemaker I would suggest asking in |
…micolon, r=Dylan-DPC diagnostics: do not suggest `fn foo({ <body> }` Instead of suggesting that the body always replace the last character on the line, presuming it must be a semicolon, the parser should instead check what the last character is, and append the body if it is anything else. Fixes rust-lang#83104
It suggests
when it should suggest
or at least suggest
(Playground)
Errors:
The text was updated successfully, but these errors were encountered: