-
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
Bad suggestion dyn pub
on proc macro (#61963 regressed)
#74043
Comments
I don't think this is actually an issue anymore. The original issue was caused by the compiler losing span information, causing tokens emitted by a proc-macro to end up with a span (the proc-macro attribute) that the author did not intend. However, the test is explicitly setting the span of the token in question: rust/src/test/ui/suggestions/auxiliary/issue-61963-1.rs Lines 13 to 15 in 0cd7ff7
However, the first token in the stream no longer has a dummy span, so this proc-macro ends up explicitly spanning the trait object token with the span of the I don't think this is a bug - when a proc-macro explicitly sets the span of a token, I don't think the compiler should be trying to second-guess that decision. There are legitimate use cases that involve causing an error to be displayed to be displayed in a unusual location - e.g. pointing to a field definition for a trait bound that the field type fails to meet. We might want to alter the test documentation to better explain its current behavior (while still guarding for regressions to the original behavior). |
So this is different from the original situation in #61963? There was discussion there about whether the problem was a bug in the proc macros or the compiler.
This I understand, but should the compiler then emit suggestions that produce invalid syntax? They at least shouldn't be reported as |
Yes - there is no longer any implicit respanning occuring, which was the root of the original issue.
I think this is unsolvable in the general case - the span could point to a token However, I think it would be fine to add in some special cases (e.g. only suggest I think the blame for the bad suggestion lies with the proc macro doing the explicit re-spanning. |
Marking it as p-medium based on the discussion |
Do not provide suggestions when the spans come from expanded code that doesn't point at user code Hide invalid proc-macro suggestions and track spans coming from proc-macros pointing at attribute. Effectively, unless the proc-macro keeps user spans, suggestions will not be produced for the code they produce. r? `@ghost` Fix rust-lang#107113, fix rust-lang#107976, fix rust-lang#107977, fix rust-lang#108748, fix rust-lang#106720, fix rust-lang#90557. Could potentially address rust-lang#50141, rust-lang#67373, rust-lang#55146, rust-lang#78862, rust-lang#74043, rust-lang#88514, rust-lang#83320, rust-lang#91520, rust-lang#104071. CC rust-lang#50122, rust-lang#76360.
Do not provide suggestions when the spans come from expanded code that doesn't point at user code Hide invalid proc-macro suggestions and track spans coming from proc-macros pointing at attribute. Effectively, unless the proc-macro keeps user spans, suggestions will not be produced for the code they produce. r? ``@ghost`` Fix rust-lang#107113, fix rust-lang#107976, fix rust-lang#107977, fix rust-lang#108748, fix rust-lang#106720, fix rust-lang#90557. Could potentially address rust-lang#50141, rust-lang#67373, rust-lang#55146, rust-lang#78862, rust-lang#74043, rust-lang#88514, rust-lang#83320, rust-lang#91520, rust-lang#104071. CC rust-lang#50122, rust-lang#76360.
#72306 causes the compiler to emit (and blessed) this bad suggestion in the test for #61963 (output):
This is the behaviour the test is supposed to guard against (almost - the original bad suggestion was to insert
dyn
before the proc macro attribute), so the issue is regressed.The issue was originally fixed nearly a year ago, so this is a regression from stable.
The text was updated successfully, but these errors were encountered: