Skip to content

Reconstruct span information lost by compiler#87

Merged
dtolnay merged 4 commits intomasterfrom
span
May 15, 2020
Merged

Reconstruct span information lost by compiler#87
dtolnay merged 4 commits intomasterfrom
span

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.

dtolnay added 4 commits May 15, 2020 16:30
    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
takumi-earth pushed a commit to earthlings-dev/thiserror that referenced this pull request Jan 27, 2026
Reconstruct span information lost by compiler
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