@@ -2,30 +2,28 @@ use proc_macro2::{Span, TokenStream};
22use std:: mem;
33use syn:: visit_mut:: { self , VisitMut } ;
44use syn:: {
5- parse_quote_spanned, token, Expr , GenericArgument , Lifetime , Receiver , ReturnType , Type ,
5+ parse_quote_spanned, token, Expr , GenericArgument , Lifetime , Receiver , ReturnType , Token , Type ,
66 TypeBareFn , TypeImplTrait , TypeParen , TypePtr , TypeReference ,
77} ;
88
99pub struct CollectLifetimes {
1010 pub elided : Vec < Lifetime > ,
1111 pub explicit : Vec < Lifetime > ,
1212 pub name : & ' static str ,
13- pub default_span : Span ,
1413}
1514
1615impl CollectLifetimes {
17- pub fn new ( name : & ' static str , default_span : Span ) -> Self {
16+ pub fn new ( name : & ' static str ) -> Self {
1817 CollectLifetimes {
1918 elided : Vec :: new ( ) ,
2019 explicit : Vec :: new ( ) ,
2120 name,
22- default_span,
2321 }
2422 }
2523
26- fn visit_opt_lifetime ( & mut self , lifetime : & mut Option < Lifetime > ) {
24+ fn visit_opt_lifetime ( & mut self , reference : Token ! [ & ] , lifetime : & mut Option < Lifetime > ) {
2725 match lifetime {
28- None => * lifetime = Some ( self . next_lifetime ( None ) ) ,
26+ None => * lifetime = Some ( self . next_lifetime ( reference . span ) ) ,
2927 Some ( lifetime) => self . visit_lifetime ( lifetime) ,
3028 }
3129 }
@@ -38,9 +36,8 @@ impl CollectLifetimes {
3836 }
3937 }
4038
41- fn next_lifetime < S : Into < Option < Span > > > ( & mut self , span : S ) -> Lifetime {
39+ fn next_lifetime ( & mut self , span : Span ) -> Lifetime {
4240 let name = format ! ( "{}{}" , self . name, self . elided. len( ) ) ;
43- let span = span. into ( ) . unwrap_or ( self . default_span ) ;
4441 let life = Lifetime :: new ( & name, span) ;
4542 self . elided . push ( life. clone ( ) ) ;
4643 life
@@ -49,13 +46,13 @@ impl CollectLifetimes {
4946
5047impl VisitMut for CollectLifetimes {
5148 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) ;
5451 }
5552 }
5653
5754 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 ) ;
5956 visit_mut:: visit_type_reference_mut ( self , ty) ;
6057 }
6158
0 commit comments