-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Incorrect diagnostic span on syntax error in macro invoc inside trait, impl, extern blocks #54841
Comments
This is because when looking for the prior span in the current context in order to check wether the prior span is in a different line the code doesn't account for the case where we're in a macro context, making
to
|
@estebank that will just print "unexpected token", no? |
@abonander correct. If the parser kept track of macro scopes in an ideal way, the output could be
but having the output be
should be enough to sidestep the issue at hand. There are two big problems in general with diagnostics: incorrect and confusing. The former (like this one) needs to be fixed immediately. The later, we can take our time to design 1) a better explanation and 2) how to surface more information that we don't currently have. In this case I would really like to remove the blatantly incorrect output. |
@estebank something I'm not sure on is why we print "unexpected token" at all and not just the "expected ... here" bit, or actually vice-versa. Is it for syntax errors spanning multiple tokens/lines? |
Hi this sounds like a chance for me to do my first contribution, do you mind if I take it? |
@holmgr please do! If you need help just let me know. |
Sorry for the time taken but I have managed to implement the change suggested by @estebank here and confirm that the output matches:
I did modify the only test affected. |
Yes go ahead and file a pr with your change. Thanks for fixing this! |
Remove incorrect span for second label inner macro invocation A fix for issue rust-lang#54841
Remove incorrect span for second label inner macro invocation A fix for issue rust-lang#54841
The PR is now merged, so I guess we could go ahead and close this issue now |
A syntax error produced by a macro invocation in a
trait {}
orimpl {}
block will have an incorrect span for its second label:Playground
Produces this error:
The "expected one of ... here" line is pointing to line 1 but it should be elaborating on the "unexpected token" label, or just replacing it. The behavior is identical for
impl {}
blocks.This appears to be due to some faulty logic in
Parser::expect_one_of()
which isn't robust in the face of macro invocations. If it can't get lines for either span from the sourcemap it should assume they're the same (in fact I'm not sure why it emits a separate "unexpected token" label).Discovered in #54833 but not introduced by it; when that's merged
extern {}
blocks will show this behavior too (as seen inissue-54441.stderr
on that PR).I'll try to look into this sometime this weekend but I'm also willing to mentor on it, though like I mentioned I'm not sure why the error handling logic in
Parser::expect_one_of()
is so complex to begin with.cc @petrochenkov
The text was updated successfully, but these errors were encountered: