Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply only allowed attributes to generated functions #3784

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions crates/backend/src/codegen.rs
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,
daxpedda marked this conversation as resolved.
Show resolved Hide resolved
wasm_bindgen: &self.wasm_bindgen,
}
.to_tokens(into);
Expand Down