Skip to content

Commit 629a623

Browse files
authored
Retain unsafe in imports (#3302)
1 parent 5b89c29 commit 629a623

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

crates/backend/src/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ pub struct Function {
301301
pub rust_attrs: Vec<syn::Attribute>,
302302
/// The visibility of this function in Rust
303303
pub rust_vis: syn::Visibility,
304+
/// Whether this is an `unsafe` function
305+
pub r#unsafe: bool,
304306
/// Whether this is an `async` function
305307
pub r#async: bool,
306308
/// Whether to generate a typescript definition for this function

crates/backend/src/codegen.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,11 @@ impl TryToTokens for ast::ImportFunction {
11781178
&self.rust_name,
11791179
);
11801180

1181+
let maybe_unsafe = if self.function.r#unsafe {
1182+
Some(quote! {unsafe})
1183+
} else {
1184+
None
1185+
};
11811186
let maybe_async = if self.function.r#async {
11821187
Some(quote! {async})
11831188
} else {
@@ -1190,7 +1195,7 @@ impl TryToTokens for ast::ImportFunction {
11901195
#[allow(clippy::all, clippy::nursery, clippy::pedantic, clippy::restriction)]
11911196
#(#attrs)*
11921197
#[doc = #doc_comment]
1193-
#vis #maybe_async fn #rust_name(#me #(#arguments),*) #ret {
1198+
#vis #maybe_async #maybe_unsafe fn #rust_name(#me #(#arguments),*) #ret {
11941199
#extern_fn
11951200

11961201
unsafe {

crates/macro-support/src/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ fn function_from_decl(
909909
ret,
910910
rust_attrs: attrs,
911911
rust_vis: vis,
912+
r#unsafe: sig.unsafety.is_some(),
912913
r#async: sig.asyncness.is_some(),
913914
generate_typescript: opts.skip_typescript().is_none(),
914915
variadic: opts.variadic().is_some(),

0 commit comments

Comments
 (0)