10
10
//! See [`serde_closure`](https://docs.rs/serde_closure) for
11
11
//! documentation.
12
12
13
- #![ doc( html_root_url = "https://docs.rs/serde_closure_derive/0.3.2" ) ]
13
+ #![ doc( html_root_url = "https://docs.rs/serde_closure_derive/0.3.3" ) ]
14
+ #![ allow(
15
+ unknown_lints,
16
+ clippy:: default_trait_access,
17
+ clippy:: unused_self,
18
+ clippy:: if_not_else,
19
+ clippy:: manual_let_else
20
+ ) ]
14
21
15
22
use proc_macro2:: { Span , TokenStream } ;
16
23
use quote:: { quote, ToTokens } ;
17
- use std:: { collections:: HashSet , iter, iter:: successors, mem:: take, str} ;
24
+ use std:: { collections:: HashSet , convert :: TryInto , iter, iter:: successors, mem:: take, str} ;
18
25
use syn:: {
19
26
parse2, parse_macro_input, visit_mut:: { self , VisitMut } , Arm , AttributeArgs , Block , Error , Expr , ExprArray , ExprAssign , ExprAssignOp , ExprAsync , ExprAwait , ExprBinary , ExprBlock , ExprBox , ExprBreak , ExprCall , ExprCast , ExprClosure , ExprField , ExprForLoop , ExprGroup , ExprIf , ExprIndex , ExprLet , ExprLoop , ExprMacro , ExprMatch , ExprMethodCall , ExprParen , ExprPath , ExprRange , ExprReference , ExprRepeat , ExprReturn , ExprStruct , ExprTry , ExprTryBlock , ExprTuple , ExprType , ExprUnary , ExprUnsafe , ExprWhile , ExprYield , FieldValue , GenericParam , Ident , ImplItem , Item , ItemImpl , Lifetime , LifetimeDef , Local , Member , Pat , PatBox , PatIdent , PatReference , PatSlice , PatTuple , PatTupleStruct , PatType , Path , PathArguments , PathSegment , ReturnType , Stmt , TraitBound , Type , TypeInfer , TypeReference , TypeTuple , UnOp
20
27
} ;
@@ -87,16 +94,16 @@ impl Desugar {
87
94
inputs. push_punct ( Default :: default ( ) ) ;
88
95
}
89
96
let output = match & args. output {
90
- ReturnType :: Type ( _, type_) => ( & * * type_) . clone ( ) ,
97
+ ReturnType :: Type ( _, type_) => ( * * type_) . clone ( ) ,
91
98
ReturnType :: Default => Type :: Tuple ( TypeTuple {
92
99
paren_token : Default :: default ( ) ,
93
100
elems : Default :: default ( ) ,
94
101
} ) ,
95
102
} ;
96
103
* arg = PathArguments :: AngleBracketed ( if !return_output {
97
- syn :: parse2 ( quote ! { <( #inputs) , Output = #output> } ) . unwrap ( )
104
+ parse2 ( quote ! { <( #inputs) , Output = #output> } ) . unwrap ( )
98
105
} else {
99
- syn :: parse2 ( quote ! { <( #inputs) > } ) . unwrap ( )
106
+ parse2 ( quote ! { <( #inputs) > } ) . unwrap ( )
100
107
} ) ;
101
108
( lifetimes, if return_output { Some ( output) } else { None } )
102
109
} else {
@@ -112,7 +119,7 @@ impl VisitMut for Desugar {
112
119
. 0 ;
113
120
if lifetimes > 0 {
114
121
let span = Span :: call_site ( ) ;
115
- let empty = syn :: parse2 ( quote ! { for <>} ) . unwrap ( ) ;
122
+ let empty = parse2 ( quote ! { for <>} ) . unwrap ( ) ;
116
123
i. lifetimes = Some ( i. lifetimes . clone ( ) . unwrap_or ( empty) ) ;
117
124
i. lifetimes
118
125
. as_mut ( )
@@ -125,7 +132,7 @@ impl VisitMut for Desugar {
125
132
) )
126
133
} ) ) ;
127
134
}
128
- visit_mut:: visit_trait_bound_mut ( self , i)
135
+ visit_mut:: visit_trait_bound_mut ( self , i) ;
129
136
}
130
137
fn visit_item_impl_mut ( & mut self , i : & mut ItemImpl ) {
131
138
if let Some ( ( _, path, _) ) = & mut i. trait_ {
@@ -146,12 +153,12 @@ impl VisitMut for Desugar {
146
153
if path. segments . last ( ) . unwrap ( ) . ident == "FnOnce" {
147
154
if let Some ( output) = output {
148
155
i. items . push ( ImplItem :: Type (
149
- syn :: parse2 ( quote ! { type Output = #output; } ) . unwrap ( ) ,
156
+ parse2 ( quote ! { type Output = #output; } ) . unwrap ( ) ,
150
157
) ) ;
151
158
}
152
159
}
153
160
}
154
- visit_mut:: visit_item_impl_mut ( self , i)
161
+ visit_mut:: visit_item_impl_mut ( self , i) ;
155
162
}
156
163
}
157
164
@@ -171,7 +178,11 @@ impl Kind {
171
178
}
172
179
}
173
180
174
- #[ allow( clippy:: cognitive_complexity) ]
181
+ #[ allow(
182
+ clippy:: cognitive_complexity,
183
+ clippy:: unnecessary_wraps,
184
+ clippy:: too_many_lines
185
+ ) ]
175
186
fn impl_closure ( mut closure : ExprClosure , kind : Kind ) -> Result < TokenStream , Error > {
176
187
let span = Span :: call_site ( ) ; // TODO: def_site() https://github.com/rust-lang/rust/issues/54724
177
188
let name_string = kind. name ( ) ;
@@ -214,7 +225,7 @@ fn impl_closure(mut closure: ExprClosure, kind: Kind) -> Result<TokenStream, Err
214
225
let env_variables = & env_variables;
215
226
let env_variable_names = & env_variables
216
227
. iter ( )
217
- . map ( |ident| ident . to_string ( ) )
228
+ . map ( ToString :: to_string)
218
229
. collect :: < Vec < _ > > ( ) ;
219
230
let closure = if let Expr :: Closure ( closure) = closure {
220
231
closure
@@ -261,8 +272,7 @@ fn impl_closure(mut closure: ExprClosure, kind: Kind) -> Result<TokenStream, Err
261
272
} )
262
273
. unwrap ( ) ;
263
274
let env_deref: Expr = parse2 ( match kind {
264
- Kind :: Fn => quote ! { * #env_name } ,
265
- Kind :: FnMut => quote ! { * #env_name } ,
275
+ Kind :: Fn | Kind :: FnMut => quote ! { * #env_name } ,
266
276
Kind :: FnOnce => quote ! { #env_name } ,
267
277
} )
268
278
. unwrap ( ) ;
@@ -582,7 +592,7 @@ fn pat_to_type(pat: &Pat) -> Type {
582
592
match pat {
583
593
Pat :: Type ( pat_type) => {
584
594
if let Type :: Infer ( _) = * pat_type. ty {
585
- pat_to_type ( & * pat_type. pat )
595
+ pat_to_type ( & pat_type. pat )
586
596
} else {
587
597
( * pat_type. ty ) . clone ( )
588
598
}
@@ -651,7 +661,7 @@ impl<'a> State<'a> {
651
661
| Pat :: Type ( PatType { pat, .. } ) => self . pat ( & mut * pat) ,
652
662
Pat :: Or ( pat_or) => {
653
663
for case in & mut pat_or. cases {
654
- self . pat ( case)
664
+ self . pat ( case) ;
655
665
}
656
666
}
657
667
Pat :: Slice ( PatSlice { elems, .. } )
@@ -661,7 +671,7 @@ impl<'a> State<'a> {
661
671
..
662
672
} ) => {
663
673
for elem in elems {
664
- self . pat ( elem)
674
+ self . pat ( elem) ;
665
675
}
666
676
}
667
677
Pat :: Range ( pat_range) => {
@@ -670,7 +680,7 @@ impl<'a> State<'a> {
670
680
}
671
681
Pat :: Struct ( pat_struct) => {
672
682
for field in & mut pat_struct. fields {
673
- self . pat ( & mut * field. pat )
683
+ self . pat ( & mut field. pat ) ;
674
684
}
675
685
}
676
686
_ => ( ) ,
@@ -707,6 +717,7 @@ impl<'a> State<'a> {
707
717
. collect ( ) ;
708
718
}
709
719
720
+ #[ allow( clippy:: too_many_lines) ]
710
721
fn expr ( & mut self , expr : & mut Expr , is_func : bool ) {
711
722
match expr {
712
723
Expr :: Array ( ExprArray { elems, .. } ) | Expr :: Tuple ( ExprTuple { elems, .. } ) => {
@@ -763,7 +774,7 @@ impl<'a> State<'a> {
763
774
Expr :: Path ( ExprPath { path, .. } )
764
775
if path. leading_colon . is_none ( ) && path. segments . len ( ) == 1 =>
765
776
{
766
- self . expr ( func, true )
777
+ self . expr ( func, true ) ;
767
778
}
768
779
_ => self . expr ( func, false ) ,
769
780
}
@@ -944,7 +955,7 @@ fn bijective_base(n: u64, base: u64, digits: impl Fn(u8) -> u8) -> String {
944
955
. iter_mut ( )
945
956
. rev ( )
946
957
. zip ( divided)
947
- . map ( |( c, n) | * c = digits ( ( n % base) as u8 ) )
958
+ . map ( |( c, n) | * c = digits ( ( n % base) . try_into ( ) . unwrap ( ) ) )
948
959
. count ( ) ;
949
960
let index = BUF_SIZE - written;
950
961
0 commit comments