From 160cde7b48a3efa076c8218e727a5df9638ffb7b Mon Sep 17 00:00:00 2001 From: Gino Valente <49806985+MrGVSV@users.noreply.github.com> Date: Tue, 28 May 2024 11:33:51 -0700 Subject: [PATCH] Make use of `#[doc]` field attributes in `Props` derive macro (#2456) * Support passing docs along to prop fields * Pass along entire doc attribute --- packages/core-macro/src/props/mod.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/core-macro/src/props/mod.rs b/packages/core-macro/src/props/mod.rs index bed4455f0..2ab15b4cc 100644 --- a/packages/core-macro/src/props/mod.rs +++ b/packages/core-macro/src/props/mod.rs @@ -271,7 +271,7 @@ mod field_info { #[derive(Debug, Default, Clone)] pub struct FieldBuilderAttr { pub default: Option, - pub doc: Option, + pub docs: Vec, pub skip: bool, pub auto_into: bool, pub from_displayable: bool, @@ -284,6 +284,11 @@ mod field_info { pub fn with(mut self, attrs: &[syn::Attribute]) -> Result { let mut skip_tokens = None; for attr in attrs { + if attr.path().is_ident("doc") { + self.docs.push(attr.clone()); + continue; + } + if path_to_single_string(attr.path()).as_deref() != Some("props") { continue; } @@ -345,10 +350,6 @@ mod field_info { self.default = Some(*assign.right); Ok(()) } - "doc" => { - self.doc = Some(*assign.right); - Ok(()) - } "default_code" => { if let syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Str(code), @@ -444,10 +445,6 @@ mod field_info { self.default = None; Ok(()) } - "doc" => { - self.doc = None; - Ok(()) - } "skip" => { self.skip = false; Ok(()) @@ -1105,10 +1102,7 @@ Finally, call `.build()` to create the instance of `{name}`. ); let (impl_generics, _, where_clause) = generics.split_for_impl(); - let doc = match field.builder_attr.doc { - Some(ref doc) => quote!(#[doc = #doc]), - None => quote!(), - }; + let docs = &field.builder_attr.docs; let arg_type = field_type; // If the field is auto_into, we need to add a generic parameter to the builder for specialization @@ -1161,7 +1155,7 @@ Finally, call `.build()` to create the instance of `{name}`. Ok(quote! { #[allow(dead_code, non_camel_case_types, missing_docs)] impl #impl_generics #builder_name < #( #ty_generics ),* > #where_clause { - #doc + #( #docs )* #[allow(clippy::type_complexity)] pub fn #field_name < #marker > (self, #field_name: #arg_type) -> #builder_name < #( #target_generics ),* > { let #field_name = (#arg_expr,);