Skip to content

Retain unsafe in imports #3302

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

Merged
merged 1 commit into from
Feb 16, 2023
Merged

Conversation

daxpedda
Copy link
Collaborator

@daxpedda daxpedda commented Feb 13, 2023

I noticed that unsafe wasn't transferred when I specified it in imports, meaning the generated functions didn't have an unsafe specifier on them.

#[wasm_bindgen]
extern "C" {
	type Foo;

	#[wasm_bindgen(method, js_name = foo)]
	unsafe fn foo(&Test);
}

let foo: Foo = ...;
// Can be called without an `unsafe` block.
foo.foo();

This was particularly helpful when I was importing functions that were messing with this instances memory, which is actually unsafe.

@alexcrichton alexcrichton merged commit 629a623 into rustwasm:main Feb 16, 2023
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.

2 participants