Skip to content
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

Reconstruct span information lost by compiler #87

Merged
merged 4 commits into from May 15, 2020
Merged

Reconstruct span information lost by compiler #87

merged 4 commits into from May 15, 2020

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented May 15, 2020

Fixes #86.

This is a workaround for rust-lang/rust#43081. The tokens were coming in with all spans erased (#0 bytes(0..0)) due to the compiler bug, and so the call_site spans that we used in the generated match expression in the Display impl were not resolving the same as identifiers generated from the macro input. The workaround is to grab a fairly arbitrary span from the macro input (I chose the span of the format string) and use that for all new bindings in match. This way, ordinarily that span is going to have the same hygiene context as call_site, but if rust-lang/rust#43081 is happening then it will be #0 hygiene the same as the input tokens.

    error[E0425]: cannot find value `_0` in this scope
       --> tests/test_display.rs:208:29
        |
    208 |             #[derive(Debug, Error)]
        |                             ^^^^^ not found in this scope
@dtolnay dtolnay merged commit 72aaea5 into master May 15, 2020
@dtolnay dtolnay deleted the span branch May 15, 2020 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E0425 deriving Error for an enum declared in a macro
1 participant