Remove span in generated field getter#3725
Merged
Liamolucko merged 4 commits intowasm-bindgen:mainfrom Nov 29, 2023
Merged
Conversation
Member
|
Ah, could you add a note to the changelog as well? |
Fixes wasm-bindgen#3707 Previously, `(*js).borrow().#rust_name` was being given the span of `rust_name`, which seems like a fairly harmless thing to do at first glance. However, it turns out that the span of a token also affects its hygiene - turns out proc macros have hygiene too, not just declarative macros! This caused a problem because the declaration of `js` had a span of `Span::call_site()`, but it was being accessed with `rust_name`'s span, which might be a different context where `js` doesn't exist. Usually this is fine because `Span::call_site()` is in the same context as the struct definition: normal code. However, when you put `#[wasm_bindgen]` inside a `macro_rules!`, `Span::call_site()` is now in the context of that `macro_rules!`, while `rust_name`'s span is still in normal code which can't access variables from inside `macro_rules!`. To fix that I've just removed the span from `(*js).borrow().#rust_name`, making it `Span::call_site()`. I don't think this should have any effect on diagnostics anyway, since I don't see how that code could ever cause a compile error.
87ef336 to
3bed9d2
Compare
daxpedda
approved these changes
Nov 29, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3707
Previously,
(*js).borrow().#rust_namewas being given the span ofrust_name, which seems like a fairly harmless thing to do at first glance. However, it turns out that the span of a token also affects its hygiene - turns out proc macros have hygiene too, not just declarative macros!This caused a problem because the declaration of
jshad a span ofSpan::call_site(), but it was being accessed withrust_name's span, which might be a different context wherejsdoesn't exist.Usually this is fine because
Span::call_site()is in the same context as the struct definition: normal code. However, when you put#[wasm_bindgen]inside amacro_rules!,Span::call_site()is now in the context of thatmacro_rules!, whilerust_name's span is still in normal code which can't access variables from insidemacro_rules!.To fix that I've just removed the span fromTurns out it was used, so I just got rid of the span on(*js).borrow().#rust_name, making itSpan::call_site(). I don't think this should have any effect on diagnostics anyway, since I don't see how that code could ever cause a compile error.jsinstead of the whole thing.