Skip to content

Commit

Permalink
Filter attributes on bindgen/descriptor functions to safe ones.
Browse files Browse the repository at this point in the history
Refer to rustwasm#3315
  • Loading branch information
seancribbs committed Jan 14, 2024
1 parent a3332e4 commit 423c2e1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/backend/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,14 @@ impl TryToTokens for ast::Export {
};
let nargs = self.function.arguments.len() as u32;
let attrs = &self.function.rust_attrs;
let safe_attrs = attrs
.iter()
.filter(|a| {
let path = a.path();
path.is_ident("cfg") || path.is_ident("cfg_attr")
})
.cloned()
.collect::<Vec<_>>();

let start_check = if self.start {
quote! { const _ASSERT: fn() = || -> #projection::Abi { loop {} }; }
Expand All @@ -688,7 +696,7 @@ impl TryToTokens for ast::Export {
(quote! {
#[automatically_derived]
const _: () = {
#(#attrs)*
#(#safe_attrs)*
#[cfg_attr(
all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))),
export_name = #export_name,
Expand Down Expand Up @@ -745,7 +753,7 @@ impl TryToTokens for ast::Export {
#describe_args
#describe_ret
},
attrs: attrs.clone(),
attrs: safe_attrs,
wasm_bindgen: &self.wasm_bindgen,
}
.to_tokens(into);
Expand Down

0 comments on commit 423c2e1

Please sign in to comment.