@@ -51,45 +51,44 @@ pub fn rename_my_lifetimes(_args: TokenStream, input: TokenStream) -> TokenStrea
51
51
52
52
fn mut_receiver_of ( sig : & mut Signature ) -> Option < & mut FnArg > {
53
53
let arg = sig. inputs . first_mut ( ) ?;
54
- if let FnArg :: Typed ( PatType { pat, .. } ) = arg {
55
- if let Pat :: Ident ( PatIdent { ident, .. } ) = & * * pat {
56
- if ident == "self" {
57
- return Some ( arg) ;
58
- }
59
- }
54
+ if let FnArg :: Typed ( PatType { pat, .. } ) = arg
55
+ && let Pat :: Ident ( PatIdent { ident, .. } ) = & * * pat
56
+ && ident == "self"
57
+ {
58
+ Some ( arg)
59
+ } else {
60
+ None
60
61
}
61
- None
62
62
}
63
63
64
64
let mut elided = 0 ;
65
65
let mut item = parse_macro_input ! ( input as ItemImpl ) ;
66
66
67
67
// Look for methods having arbitrary self type taken by &mut ref
68
68
for inner in & mut item. items {
69
- if let ImplItem :: Fn ( method) = inner {
70
- if let Some ( FnArg :: Typed ( pat_type) ) = mut_receiver_of ( & mut method. sig ) {
71
- if let box Type :: Reference ( reference) = & mut pat_type. ty {
72
- // Target only unnamed lifetimes
73
- let name = match & reference. lifetime {
74
- Some ( lt) if lt. ident == "_" => make_name ( elided) ,
75
- None => make_name ( elided) ,
76
- _ => continue ,
77
- } ;
78
- elided += 1 ;
79
-
80
- // HACK: Syn uses `Span` from the proc_macro2 crate, and does not seem to reexport it.
81
- // In order to avoid adding the dependency, get a default span from a nonexistent token.
82
- // A default span is needed to mark the code as coming from expansion.
83
- let span = Star :: default ( ) . span ( ) ;
84
-
85
- // Replace old lifetime with the named one
86
- let lifetime = Lifetime :: new ( & name, span) ;
87
- reference. lifetime = Some ( parse_quote ! ( #lifetime) ) ;
88
-
89
- // Add lifetime to the generics of the method
90
- method. sig . generics . params . push ( parse_quote ! ( #lifetime) ) ;
91
- }
92
- }
69
+ if let ImplItem :: Fn ( method) = inner
70
+ && let Some ( FnArg :: Typed ( pat_type) ) = mut_receiver_of ( & mut method. sig )
71
+ && let box Type :: Reference ( reference) = & mut pat_type. ty
72
+ {
73
+ // Target only unnamed lifetimes
74
+ let name = match & reference. lifetime {
75
+ Some ( lt) if lt. ident == "_" => make_name ( elided) ,
76
+ None => make_name ( elided) ,
77
+ _ => continue ,
78
+ } ;
79
+ elided += 1 ;
80
+
81
+ // HACK: Syn uses `Span` from the proc_macro2 crate, and does not seem to reexport it.
82
+ // In order to avoid adding the dependency, get a default span from a nonexistent token.
83
+ // A default span is needed to mark the code as coming from expansion.
84
+ let span = Star :: default ( ) . span ( ) ;
85
+
86
+ // Replace old lifetime with the named one
87
+ let lifetime = Lifetime :: new ( & name, span) ;
88
+ reference. lifetime = Some ( parse_quote ! ( #lifetime) ) ;
89
+
90
+ // Add lifetime to the generics of the method
91
+ method. sig . generics . params . push ( parse_quote ! ( #lifetime) ) ;
93
92
}
94
93
}
95
94
@@ -129,15 +128,15 @@ pub fn fake_desugar_await(_args: TokenStream, input: TokenStream) -> TokenStream
129
128
let mut async_fn = parse_macro_input ! ( input as syn:: ItemFn ) ;
130
129
131
130
for stmt in & mut async_fn. block . stmts {
132
- if let syn:: Stmt :: Expr ( syn:: Expr :: Match ( syn:: ExprMatch { expr : scrutinee, .. } ) , _) = stmt {
133
- if let syn:: Expr :: Await ( syn:: ExprAwait { base, await_token, .. } ) = scrutinee. as_mut ( ) {
134
- let blc = quote_spanned ! ( await_token . span => {
135
- # [ allow ( clippy :: let_and_return ) ]
136
- let __pinned = #base ;
137
- __pinned
138
- } ) ;
139
- * scrutinee = parse_quote ! ( #blc ) ;
140
- }
131
+ if let syn:: Stmt :: Expr ( syn:: Expr :: Match ( syn:: ExprMatch { expr : scrutinee, .. } ) , _) = stmt
132
+ && let syn:: Expr :: Await ( syn:: ExprAwait { base, await_token, .. } ) = scrutinee. as_mut ( )
133
+ {
134
+ let blc = quote_spanned ! ( await_token . span => {
135
+ # [ allow ( clippy :: let_and_return ) ]
136
+ let __pinned = #base ;
137
+ __pinned
138
+ } ) ;
139
+ * scrutinee = parse_quote ! ( #blc ) ;
141
140
}
142
141
}
143
142
0 commit comments