Skip to content

Commit

Permalink
Retain unsafe in imports (rustwasm#3302)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Feb 16, 2023
1 parent 5b89c29 commit 629a623
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/backend/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ pub struct Function {
pub rust_attrs: Vec<syn::Attribute>,
/// The visibility of this function in Rust
pub rust_vis: syn::Visibility,
/// Whether this is an `unsafe` function
pub r#unsafe: bool,
/// Whether this is an `async` function
pub r#async: bool,
/// Whether to generate a typescript definition for this function
Expand Down
7 changes: 6 additions & 1 deletion crates/backend/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,11 @@ impl TryToTokens for ast::ImportFunction {
&self.rust_name,
);

let maybe_unsafe = if self.function.r#unsafe {
Some(quote! {unsafe})
} else {
None
};
let maybe_async = if self.function.r#async {
Some(quote! {async})
} else {
Expand All @@ -1190,7 +1195,7 @@ impl TryToTokens for ast::ImportFunction {
#[allow(clippy::all, clippy::nursery, clippy::pedantic, clippy::restriction)]
#(#attrs)*
#[doc = #doc_comment]
#vis #maybe_async fn #rust_name(#me #(#arguments),*) #ret {
#vis #maybe_async #maybe_unsafe fn #rust_name(#me #(#arguments),*) #ret {
#extern_fn

unsafe {
Expand Down
1 change: 1 addition & 0 deletions crates/macro-support/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ fn function_from_decl(
ret,
rust_attrs: attrs,
rust_vis: vis,
r#unsafe: sig.unsafety.is_some(),
r#async: sig.asyncness.is_some(),
generate_typescript: opts.skip_typescript().is_none(),
variadic: opts.variadic().is_some(),
Expand Down

0 comments on commit 629a623

Please sign in to comment.