@@ -2,30 +2,28 @@ use proc_macro2::{Span, TokenStream};
2
2
use std:: mem;
3
3
use syn:: visit_mut:: { self , VisitMut } ;
4
4
use syn:: {
5
- parse_quote_spanned, token, Expr , GenericArgument , Lifetime , Receiver , ReturnType , Type ,
5
+ parse_quote_spanned, token, Expr , GenericArgument , Lifetime , Receiver , ReturnType , Token , Type ,
6
6
TypeBareFn , TypeImplTrait , TypeParen , TypePtr , TypeReference ,
7
7
} ;
8
8
9
9
pub struct CollectLifetimes {
10
10
pub elided : Vec < Lifetime > ,
11
11
pub explicit : Vec < Lifetime > ,
12
12
pub name : & ' static str ,
13
- pub default_span : Span ,
14
13
}
15
14
16
15
impl CollectLifetimes {
17
- pub fn new ( name : & ' static str , default_span : Span ) -> Self {
16
+ pub fn new ( name : & ' static str ) -> Self {
18
17
CollectLifetimes {
19
18
elided : Vec :: new ( ) ,
20
19
explicit : Vec :: new ( ) ,
21
20
name,
22
- default_span,
23
21
}
24
22
}
25
23
26
- fn visit_opt_lifetime ( & mut self , lifetime : & mut Option < Lifetime > ) {
24
+ fn visit_opt_lifetime ( & mut self , reference : Token ! [ & ] , lifetime : & mut Option < Lifetime > ) {
27
25
match lifetime {
28
- None => * lifetime = Some ( self . next_lifetime ( None ) ) ,
26
+ None => * lifetime = Some ( self . next_lifetime ( reference . span ) ) ,
29
27
Some ( lifetime) => self . visit_lifetime ( lifetime) ,
30
28
}
31
29
}
@@ -38,9 +36,8 @@ impl CollectLifetimes {
38
36
}
39
37
}
40
38
41
- fn next_lifetime < S : Into < Option < Span > > > ( & mut self , span : S ) -> Lifetime {
39
+ fn next_lifetime ( & mut self , span : Span ) -> Lifetime {
42
40
let name = format ! ( "{}{}" , self . name, self . elided. len( ) ) ;
43
- let span = span. into ( ) . unwrap_or ( self . default_span ) ;
44
41
let life = Lifetime :: new ( & name, span) ;
45
42
self . elided . push ( life. clone ( ) ) ;
46
43
life
@@ -49,13 +46,13 @@ impl CollectLifetimes {
49
46
50
47
impl VisitMut for CollectLifetimes {
51
48
fn visit_receiver_mut ( & mut self , arg : & mut Receiver ) {
52
- if let Some ( ( _ , lifetime) ) = & mut arg. reference {
53
- self . visit_opt_lifetime ( lifetime) ;
49
+ if let Some ( ( reference , lifetime) ) = & mut arg. reference {
50
+ self . visit_opt_lifetime ( * reference , lifetime) ;
54
51
}
55
52
}
56
53
57
54
fn visit_type_reference_mut ( & mut self , ty : & mut TypeReference ) {
58
- self . visit_opt_lifetime ( & mut ty. lifetime ) ;
55
+ self . visit_opt_lifetime ( ty . and_token , & mut ty. lifetime ) ;
59
56
visit_mut:: visit_type_reference_mut ( self , ty) ;
60
57
}
61
58
0 commit comments