1
+ use proc_macro2:: Span ;
1
2
use quote:: ToTokens ;
2
3
use syn:: spanned:: Spanned ;
3
- use proc_macro2:: Span ;
4
4
5
5
// do not derive debug since this needs "extra-traits"
6
6
// feature for crate `syn`, which slows compile time
7
7
// too much, and is not needed as this struct is not
8
8
// public.
9
+ #[ derive( Default ) ]
9
10
pub struct Attribute {
10
11
pub help : Option < syn:: LitStr > ,
11
12
pub unit : Option < syn:: LitStr > ,
12
13
pub rename : Option < syn:: LitStr > ,
13
14
pub skip : bool ,
14
15
}
15
16
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
-
27
17
impl Attribute {
28
18
fn with_help ( mut self , doc : syn:: LitStr ) -> Self {
29
19
self . help = Some ( doc) ;
@@ -39,10 +29,11 @@ impl Attribute {
39
29
let mut acc = merged
40
30
. help
41
31
. unwrap_or_else ( || syn:: LitStr :: new ( "" , doc. span ( ) ) )
42
- . value ( ) . trim ( )
32
+ . value ( )
33
+ . trim ( )
43
34
. to_string ( ) ;
44
35
acc. push ( ' ' ) ;
45
- acc. push_str ( & doc. value ( ) . trim ( ) ) ;
36
+ acc. push_str ( doc. value ( ) . trim ( ) ) ;
46
37
merged. help = Some ( syn:: LitStr :: new ( & acc, Span :: call_site ( ) ) ) ;
47
38
}
48
39
if let Some ( unit) = other. unit {
@@ -82,12 +73,12 @@ impl syn::parse::Parse for Attribute {
82
73
syn:: Meta :: NameValue ( meta) if meta. path . is_ident ( "doc" ) => {
83
74
if let syn:: Expr :: Lit ( lit) = meta. value {
84
75
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) )
86
77
} else {
87
- return Err ( syn:: Error :: new_spanned (
78
+ Err ( syn:: Error :: new_spanned (
88
79
meta. value ,
89
80
"Expected a string literal for doc attribute" ,
90
- ) ) ;
81
+ ) )
91
82
}
92
83
}
93
84
syn:: Meta :: List ( meta) if meta. path . is_ident ( "registrant" ) => {
@@ -135,12 +126,10 @@ impl syn::parse::Parse for Attribute {
135
126
} ) ?;
136
127
Ok ( attr)
137
128
}
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
+ ) ) ,
144
133
}
145
134
}
146
135
}
0 commit comments