@@ -2,7 +2,6 @@ use std::collections::HashSet;
22
33use syn;
44use syn:: punctuated:: { Pair , Punctuated } ;
5- use syn:: visit:: { self , Visit } ;
65
76use internals:: ast:: { Container , Data } ;
87use internals:: { attr, ungroup} ;
@@ -112,7 +111,8 @@ pub fn with_bound(
112111 // parameters.
113112 associated_type_usage : Vec < & ' ast syn:: TypePath > ,
114113 }
115- impl < ' ast > Visit < ' ast > for FindTyParams < ' ast > {
114+
115+ impl < ' ast > FindTyParams < ' ast > {
116116 fn visit_field ( & mut self , field : & ' ast syn:: Field ) {
117117 if let syn:: Type :: Path ( ty) = ungroup ( & field. ty ) {
118118 if let Some ( Pair :: Punctuated ( t, _) ) = ty. path . segments . pairs ( ) . next ( ) {
@@ -138,7 +138,98 @@ pub fn with_bound(
138138 self . relevant_type_params . insert ( id. clone ( ) ) ;
139139 }
140140 }
141- visit:: visit_path ( self , path) ;
141+ for segment in & path. segments {
142+ self . visit_path_segment ( segment) ;
143+ }
144+ }
145+
146+ // Everything below is simply traversing the syntax tree.
147+
148+ fn visit_type ( & mut self , ty : & ' ast syn:: Type ) {
149+ match ty {
150+ syn:: Type :: Array ( ty) => self . visit_type ( & ty. elem ) ,
151+ syn:: Type :: BareFn ( ty) => {
152+ for arg in & ty. inputs {
153+ self . visit_type ( & arg. ty ) ;
154+ }
155+ self . visit_return_type ( & ty. output ) ;
156+ }
157+ syn:: Type :: Group ( ty) => self . visit_type ( & ty. elem ) ,
158+ syn:: Type :: ImplTrait ( ty) => {
159+ for bound in & ty. bounds {
160+ self . visit_type_param_bound ( bound) ;
161+ }
162+ }
163+ syn:: Type :: Macro ( ty) => self . visit_macro ( & ty. mac ) ,
164+ syn:: Type :: Paren ( ty) => self . visit_type ( & ty. elem ) ,
165+ syn:: Type :: Path ( ty) => {
166+ if let Some ( qself) = & ty. qself {
167+ self . visit_type ( & qself. ty ) ;
168+ }
169+ self . visit_path ( & ty. path ) ;
170+ }
171+ syn:: Type :: Ptr ( ty) => self . visit_type ( & ty. elem ) ,
172+ syn:: Type :: Reference ( ty) => self . visit_type ( & ty. elem ) ,
173+ syn:: Type :: Slice ( ty) => self . visit_type ( & ty. elem ) ,
174+ syn:: Type :: TraitObject ( ty) => {
175+ for bound in & ty. bounds {
176+ self . visit_type_param_bound ( bound) ;
177+ }
178+ }
179+ syn:: Type :: Tuple ( ty) => {
180+ for elem in & ty. elems {
181+ self . visit_type ( elem) ;
182+ }
183+ }
184+
185+ syn:: Type :: Infer ( _) | syn:: Type :: Never ( _) | syn:: Type :: Verbatim ( _) => { }
186+
187+ #[ cfg( test) ]
188+ syn:: Type :: __TestExhaustive( _) => unimplemented ! ( ) ,
189+ #[ cfg( not( test) ) ]
190+ _ => { }
191+ }
192+ }
193+
194+ fn visit_path_segment ( & mut self , segment : & ' ast syn:: PathSegment ) {
195+ self . visit_path_arguments ( & segment. arguments ) ;
196+ }
197+
198+ fn visit_path_arguments ( & mut self , arguments : & ' ast syn:: PathArguments ) {
199+ match arguments {
200+ syn:: PathArguments :: None => { }
201+ syn:: PathArguments :: AngleBracketed ( arguments) => {
202+ for arg in & arguments. args {
203+ match arg {
204+ syn:: GenericArgument :: Type ( arg) => self . visit_type ( arg) ,
205+ syn:: GenericArgument :: Binding ( arg) => self . visit_type ( & arg. ty ) ,
206+ syn:: GenericArgument :: Lifetime ( _)
207+ | syn:: GenericArgument :: Constraint ( _)
208+ | syn:: GenericArgument :: Const ( _) => { }
209+ }
210+ }
211+ }
212+ syn:: PathArguments :: Parenthesized ( arguments) => {
213+ for argument in & arguments. inputs {
214+ self . visit_type ( argument) ;
215+ }
216+ self . visit_return_type ( & arguments. output ) ;
217+ }
218+ }
219+ }
220+
221+ fn visit_return_type ( & mut self , return_type : & ' ast syn:: ReturnType ) {
222+ match return_type {
223+ syn:: ReturnType :: Default => { }
224+ syn:: ReturnType :: Type ( _, output) => self . visit_type ( output) ,
225+ }
226+ }
227+
228+ fn visit_type_param_bound ( & mut self , bound : & ' ast syn:: TypeParamBound ) {
229+ match bound {
230+ syn:: TypeParamBound :: Trait ( bound) => self . visit_path ( & bound. path ) ,
231+ syn:: TypeParamBound :: Lifetime ( _) => { }
232+ }
142233 }
143234
144235 // Type parameter should not be considered used by a macro path.
0 commit comments