Skip to content

Commit

Permalink
Expand #[expect] attributes into #[allow]
Browse files Browse the repository at this point in the history
An `#[expect]` outer attribute must not be kept in the
`#[automatically_derived]` code, as the expanded code will probably not
meet the expectations. Transforming it into the equivalent `#[allow]`
attribute is the safest way to ensure that expected attributes will not
trigger a warning.

Noticed through a bug report entered at the Clippy repository at
<rust-lang/rust-clippy#14008>.
  • Loading branch information
samueltardieu committed Jan 16, 2025
1 parent c35cc93 commit b83e0d9
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions crates/backend/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use syn::parse_quote;
use syn::spanned::Spanned;
use syn::{Attribute, Meta, MetaList};
use wasm_bindgen_shared as shared;

/// A trait for converting AST structs into Tokens and adding them to a TokenStream,
Expand Down Expand Up @@ -792,7 +793,24 @@ impl TryToTokens for ast::Export {
<#inner_ret_ty as WasmDescribe>::describe();
};
let nargs = self.function.arguments.len() as u32;
let attrs = &self.function.rust_attrs;
let attrs = self
.function
.rust_attrs
.iter()
.map(|attr| match &attr.meta {
Meta::List(list @ MetaList { path, .. }) if path.is_ident("expect") => {
let list = MetaList {
path: parse_quote!(allow),
..list.clone()
};
Attribute {
meta: Meta::List(list),
..*attr
}
}
_ => attr.clone(),
})
.collect::<Vec<_>>();

let mut checks = Vec::new();
if self.start {
Expand Down Expand Up @@ -905,7 +923,7 @@ impl TryToTokens for ast::Export {
#describe_args
#describe_ret
},
attrs: attrs.clone(),
attrs,
wasm_bindgen: &self.wasm_bindgen,
}
.to_tokens(into);
Expand Down

0 comments on commit b83e0d9

Please sign in to comment.