-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Closed
Labels
A-edition-2024Area: The 2024 editionArea: The 2024 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.F-unsafe_extern_blocks`#![feature(unsafe_extern_blocks)]``#![feature(unsafe_extern_blocks)]`L-missing_unsafe_on_externLint: missing_unsafe_on_externLint: missing_unsafe_on_extern
Description
I tried this code:
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
unsafe extern {
pub fn test();
}I expected to see this happen: it should compile.
Instead, this happened: it fails to compile.
Meta
rustc --version --verbose:
rustc 1.84.0-nightly (1e4f10ba6 2024-10-29)
binary: rustc
commit-hash: 1e4f10ba6476e48a42a79b9f846a2d9366525b9e
commit-date: 2024-10-29
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1
Compile Error
error: extern blocks must be unsafe
--> src/main.rs:5:12
|
5 | pub fn test();
| ^^^^
Basically the problem is that the #[wasm-bindgen] proc-macro generates extern "C" blocks which aren't prefixed with the unsafe 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.
Metadata
Metadata
Assignees
Labels
A-edition-2024Area: The 2024 editionArea: The 2024 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.F-unsafe_extern_blocks`#![feature(unsafe_extern_blocks)]``#![feature(unsafe_extern_blocks)]`L-missing_unsafe_on_externLint: missing_unsafe_on_externLint: missing_unsafe_on_extern