-
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
[edition 2024] missing_unsafe_on_extern
in macros with older editions
#132425
Comments
cc @spastorino Do you by chance know what is happening? Is it possible that wasm-bindgen is using the wrong hygiene? Or maybe the validation is looking at a span injected from the user's code? |
Just gave it a very quick look ... this error is emitted in https://github.com/spastorino/rust/blob/2dece5bb62f234f5622a08289c5a3d1555cd7843/compiler/rustc_ast_passes/src/ast_validation.rs#L964-L977. |
I believe the problem is here. wasm-bindgen is modifying the tokens of the generated extern block to use the span of the identifier from the input. That identifier will have the 2024 hygiene. Thus the entire extern block will have 2024 hygiene, and thus the validation will think it is a 2024 extern block. I think this might need to be fixed on the wasm-bindgen side. I don't know how the edition hygiene of the item span is computed if the item is built from a mix of tokens, but I'm wondering if wasm-bindgen could not modify the span of the |
Another alternative solution is for wasm-bindgen to include the |
@ehuss should we close this issue then? |
I'm not sure, yet. We'll discuss in our call today. Not working with wasm-bindgen I think is a pretty big deal, and will want to at least follow up to see if we can fix it on their side. I was also wondering if it is in the realm of possibility to check the |
I'm going to close this particular issue as resolved by rustwasm/wasm-bindgen#4259. As for the general problem of proc-macros re-spanning their output (particularly with |
I tried this code:
I expected to see this happen: it should compile.
Instead, this happened: it fails to compile.
Meta
rustc --version --verbose
:Compile Error
Basically the problem is that the
#[wasm-bindgen]
proc-macro generatesextern "C"
blocks which aren't prefixed with theunsafe
keyword.However, my understanding is that proc-macros should carry the edition from the crate they are coming from, which in this case is edition 2021. The rules of edition 2024 should not be applied to the generated code from this edition 2021 proc-macro.
That said, this is easily fixable in
wasm-bindgen
, but the bug will probably break other libraries as well.Cc rustwasm/wasm-bindgen#4218.
The text was updated successfully, but these errors were encountered: