1+ use proc_macro2:: Span ;
12use quote:: ToTokens ;
23use syn:: spanned:: Spanned ;
3- use proc_macro2:: Span ;
44
55// do not derive debug since this needs "extra-traits"
66// feature for crate `syn`, which slows compile time
77// too much, and is not needed as this struct is not
88// public.
9+ #[ derive( Default ) ]
910pub struct Attribute {
1011 pub help : Option < syn:: LitStr > ,
1112 pub unit : Option < syn:: LitStr > ,
1213 pub rename : Option < syn:: LitStr > ,
1314 pub skip : bool ,
1415}
1516
16- impl Default for Attribute {
17- fn default ( ) -> Self {
18- Attribute {
19- help : None ,
20- unit : None ,
21- rename : None ,
22- skip : false ,
23- }
24- }
25- }
26-
2717impl Attribute {
2818 fn with_help ( mut self , doc : syn:: LitStr ) -> Self {
2919 self . help = Some ( doc) ;
@@ -39,10 +29,11 @@ impl Attribute {
3929 let mut acc = merged
4030 . help
4131 . unwrap_or_else ( || syn:: LitStr :: new ( "" , doc. span ( ) ) )
42- . value ( ) . trim ( )
32+ . value ( )
33+ . trim ( )
4334 . to_string ( ) ;
4435 acc. push ( ' ' ) ;
45- acc. push_str ( & doc. value ( ) . trim ( ) ) ;
36+ acc. push_str ( doc. value ( ) . trim ( ) ) ;
4637 merged. help = Some ( syn:: LitStr :: new ( & acc, Span :: call_site ( ) ) ) ;
4738 }
4839 if let Some ( unit) = other. unit {
@@ -82,12 +73,12 @@ impl syn::parse::Parse for Attribute {
8273 syn:: Meta :: NameValue ( meta) if meta. path . is_ident ( "doc" ) => {
8374 if let syn:: Expr :: Lit ( lit) = meta. value {
8475 let lit_str = syn:: parse2 :: < syn:: LitStr > ( lit. lit . to_token_stream ( ) ) ?;
85- return Ok ( Attribute :: default ( ) . with_help ( lit_str) ) ;
76+ Ok ( Attribute :: default ( ) . with_help ( lit_str) )
8677 } else {
87- return Err ( syn:: Error :: new_spanned (
78+ Err ( syn:: Error :: new_spanned (
8879 meta. value ,
8980 "Expected a string literal for doc attribute" ,
90- ) ) ;
81+ ) )
9182 }
9283 }
9384 syn:: Meta :: List ( meta) if meta. path . is_ident ( "registrant" ) => {
@@ -135,12 +126,10 @@ impl syn::parse::Parse for Attribute {
135126 } ) ?;
136127 Ok ( attr)
137128 }
138- _ => {
139- return Err ( syn:: Error :: new (
140- span,
141- r#"Unknown attribute, expected `#[doc(...)]` or `#[registrant(<key>[=value], ...)]`"# ,
142- ) )
143- }
129+ _ => Err ( syn:: Error :: new (
130+ span,
131+ r#"Unknown attribute, expected `#[doc(...)]` or `#[registrant(<key>[=value], ...)]`"# ,
132+ ) ) ,
144133 }
145134 }
146135}
0 commit comments