From 423c2e1f6a5e59792970405800125add48ac0079 Mon Sep 17 00:00:00 2001 From: Sean Cribbs Date: Sun, 14 Jan 2024 17:08:59 -0600 Subject: [PATCH] Filter attributes on bindgen/descriptor functions to safe ones. Refer to #3315 --- crates/backend/src/codegen.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index bbcbc9cea14..36fe3026b72 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -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::>(); let start_check = if self.start { quote! { const _ASSERT: fn() = || -> #projection::Abi { loop {} }; } @@ -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, @@ -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);