Skip to content

Commit 423c2e1

Browse files
committed
Filter attributes on bindgen/descriptor functions to safe ones.
Refer to #3315
1 parent a3332e4 commit 423c2e1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

crates/backend/src/codegen.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,14 @@ impl TryToTokens for ast::Export {
678678
};
679679
let nargs = self.function.arguments.len() as u32;
680680
let attrs = &self.function.rust_attrs;
681+
let safe_attrs = attrs
682+
.iter()
683+
.filter(|a| {
684+
let path = a.path();
685+
path.is_ident("cfg") || path.is_ident("cfg_attr")
686+
})
687+
.cloned()
688+
.collect::<Vec<_>>();
681689

682690
let start_check = if self.start {
683691
quote! { const _ASSERT: fn() = || -> #projection::Abi { loop {} }; }
@@ -688,7 +696,7 @@ impl TryToTokens for ast::Export {
688696
(quote! {
689697
#[automatically_derived]
690698
const _: () = {
691-
#(#attrs)*
699+
#(#safe_attrs)*
692700
#[cfg_attr(
693701
all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))),
694702
export_name = #export_name,
@@ -745,7 +753,7 @@ impl TryToTokens for ast::Export {
745753
#describe_args
746754
#describe_ret
747755
},
748-
attrs: attrs.clone(),
756+
attrs: safe_attrs,
749757
wasm_bindgen: &self.wasm_bindgen,
750758
}
751759
.to_tokens(into);

0 commit comments

Comments
 (0)