diff --git a/turbopack/crates/turbo-tasks-macros/src/func.rs b/turbopack/crates/turbo-tasks-macros/src/func.rs index 6ebf4f4479df2..0d1ee842a11c0 100644 --- a/turbopack/crates/turbo-tasks-macros/src/func.rs +++ b/turbopack/crates/turbo-tasks-macros/src/func.rs @@ -10,9 +10,9 @@ use syn::{ spanned::Spanned, token::Paren, visit_mut::VisitMut, - AngleBracketedGenericArguments, Block, Expr, ExprBlock, ExprPath, FnArg, GenericArgument, - Local, Meta, Pat, PatIdent, PatType, Path, PathArguments, PathSegment, Receiver, ReturnType, - Signature, Stmt, Token, Type, TypeGroup, TypePath, TypeTuple, + AngleBracketedGenericArguments, Attribute, Block, Expr, ExprBlock, ExprPath, FnArg, + GenericArgument, Local, Meta, Pat, PatIdent, PatType, Path, PathArguments, PathSegment, + Receiver, ReturnType, Signature, Stmt, Token, Type, TypeGroup, TypePath, TypeTuple, }; #[derive(Debug)] @@ -1020,3 +1020,13 @@ impl NativeFn { } } } + +pub fn filter_inline_attributes<'a>( + attrs: impl IntoIterator, +) -> Vec<&'a Attribute> { + // inline functions use #[doc(hidden)], so it's not useful to preserve/duplicate docs + attrs + .into_iter() + .filter(|attr| attr.path.get_ident().is_none_or(|id| id != "doc")) + .collect() +} diff --git a/turbopack/crates/turbo-tasks-macros/src/function_macro.rs b/turbopack/crates/turbo-tasks-macros/src/function_macro.rs index 419ce56517987..33599492b8213 100644 --- a/turbopack/crates/turbo-tasks-macros/src/function_macro.rs +++ b/turbopack/crates/turbo-tasks-macros/src/function_macro.rs @@ -3,7 +3,9 @@ use quote::quote; use syn::{parse_macro_input, parse_quote, ItemFn}; use turbo_tasks_macros_shared::{get_native_function_id_ident, get_native_function_ident}; -use crate::func::{DefinitionContext, FunctionArguments, NativeFn, TurboFn}; +use crate::func::{ + filter_inline_attributes, DefinitionContext, FunctionArguments, NativeFn, TurboFn, +}; /// This macro generates the virtual function that powers turbo tasks. /// An annotated task is replaced with a stub function that returns a @@ -50,6 +52,7 @@ pub fn function(args: TokenStream, input: TokenStream) -> TokenStream { let inline_function_ident = turbo_fn.inline_ident(); let (inline_signature, inline_block) = turbo_fn.inline_signature_and_block(&block); + let inline_attrs = filter_inline_attributes(&attrs[..]); let native_fn = NativeFn::new( &ident.to_string(), @@ -72,7 +75,7 @@ pub fn function(args: TokenStream, input: TokenStream) -> TokenStream { #(#attrs)* #vis #exposed_signature #exposed_block - #(#attrs)* + #(#inline_attrs)* #[doc(hidden)] #inline_signature #inline_block diff --git a/turbopack/crates/turbo-tasks-macros/src/value_impl_macro.rs b/turbopack/crates/turbo-tasks-macros/src/value_impl_macro.rs index bfef52b365768..6663306886b65 100644 --- a/turbopack/crates/turbo-tasks-macros/src/value_impl_macro.rs +++ b/turbopack/crates/turbo-tasks-macros/src/value_impl_macro.rs @@ -15,7 +15,10 @@ use turbo_tasks_macros_shared::{ get_trait_impl_function_ident, get_type_ident, }; -use crate::func::{DefinitionContext, FunctionArguments, MaybeParenthesized, NativeFn, TurboFn}; +use crate::func::{ + filter_inline_attributes, DefinitionContext, FunctionArguments, MaybeParenthesized, NativeFn, + TurboFn, +}; fn is_attribute(attr: &Attribute, name: &str) -> bool { let path = &attr.path; @@ -130,6 +133,7 @@ pub fn value_impl(args: TokenStream, input: TokenStream) -> TokenStream { }; let inline_function_ident = turbo_fn.inline_ident(); let (inline_signature, inline_block) = turbo_fn.inline_signature_and_block(block); + let inline_attrs = filter_inline_attributes(attrs.iter().copied()); let native_fn = NativeFn::new( &format!("{ty}::{ident}", ty = ty.to_token_stream()), @@ -160,7 +164,7 @@ pub fn value_impl(args: TokenStream, input: TokenStream) -> TokenStream { // By declaring the native function's body within an `impl` block, we ensure // that `Self` refers to `#ty`. This is necessary because the function's // body is originally declared within an `impl` block already. - #(#attrs)* + #(#inline_attrs)* #[doc(hidden)] #[deprecated(note = "This function is only exposed for use in macros. Do not call it directly.")] pub(self) #inline_signature #inline_block @@ -233,6 +237,7 @@ pub fn value_impl(args: TokenStream, input: TokenStream) -> TokenStream { ident.span(), ); let (inline_signature, inline_block) = turbo_fn.inline_signature_and_block(block); + let inline_attrs = filter_inline_attributes(attrs.iter().copied()); let native_fn = NativeFn::new( &format!( @@ -270,14 +275,14 @@ pub fn value_impl(args: TokenStream, input: TokenStream) -> TokenStream { #[doc(hidden)] #[allow(non_camel_case_types)] trait #inline_extension_trait_ident: std::marker::Send { - #(#attrs)* + #(#inline_attrs)* #[doc(hidden)] #inline_signature; } #[doc(hidden)] impl #impl_generics #inline_extension_trait_ident for #ty #where_clause { - #(#attrs)* + #(#inline_attrs)* #[doc(hidden)] #[deprecated(note = "This function is only exposed for use in macros. Do not call it directly.")] #inline_signature #inline_block diff --git a/turbopack/crates/turbo-tasks-macros/src/value_trait_macro.rs b/turbopack/crates/turbo-tasks-macros/src/value_trait_macro.rs index 3212a7d3321ad..63a896fef8b20 100644 --- a/turbopack/crates/turbo-tasks-macros/src/value_trait_macro.rs +++ b/turbopack/crates/turbo-tasks-macros/src/value_trait_macro.rs @@ -9,7 +9,9 @@ use turbo_tasks_macros_shared::{ get_trait_type_id_ident, get_trait_type_ident, ValueTraitArguments, }; -use crate::func::{DefinitionContext, FunctionArguments, NativeFn, TurboFn}; +use crate::func::{ + filter_inline_attributes, DefinitionContext, FunctionArguments, NativeFn, TurboFn, +}; pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream { let ValueTraitArguments { @@ -114,6 +116,7 @@ pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream { let inline_extension_trait_ident = Ident::new(&format!("{}_{}_inline", trait_ident, ident), ident.span()); let (inline_signature, inline_block) = turbo_fn.inline_signature_and_block(default); + let inline_attrs = filter_inline_attributes(&attrs[..]); let native_function = NativeFn::new( &format!("{trait_ident}::{ident}"), @@ -146,7 +149,7 @@ pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream { #[doc(hidden)] #[allow(non_camel_case_types)] trait #inline_extension_trait_ident: std::marker::Send { - #(#attrs)* + #(#inline_attrs)* #inline_signature; } @@ -155,7 +158,7 @@ pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream { // in the inline signature. impl #inline_extension_trait_ident for Box { // put the function body here so that `Self` points to `Box` - #(#attrs)* + #(#inline_attrs)* #inline_signature #inline_block }