@@ -7,12 +7,14 @@ use crate::{iter::BoxedIter, param::Param};
77
88pub trait Extractor {
99 fn extract_lifetimes ( & self ) -> Vec < Lifetime > ;
10- fn extract_idents ( & self ) -> Vec < Ident > ;
10+ fn extract_types ( & self ) -> Vec < Ident > ;
11+ fn extract_consts ( & self ) -> Vec < Ident > ;
1112 fn extract_params ( & self ) -> Box < dyn Iterator < Item = Param > > {
1213 self . extract_lifetimes ( )
1314 . into_iter ( )
1415 . map ( Param :: Lifetime )
15- . chain ( self . extract_idents ( ) . into_iter ( ) . map ( Param :: Ident ) )
16+ . chain ( self . extract_types ( ) . into_iter ( ) . map ( Param :: Type ) )
17+ . chain ( self . extract_consts ( ) . into_iter ( ) . map ( Param :: Const ) )
1618 . boxed ( )
1719 }
1820}
@@ -63,11 +65,11 @@ impl Extractor for Type {
6365 }
6466 }
6567
66- fn extract_idents ( & self ) -> Vec < Ident > {
68+ fn extract_types ( & self ) -> Vec < Ident > {
6769 match self {
68- Type :: Array ( a) => a. elem . extract_idents ( ) ,
70+ Type :: Array ( a) => a. elem . extract_types ( ) ,
6971 Type :: BareFn ( _) => Vec :: new ( ) ,
70- Type :: Group ( g) => g. elem . extract_idents ( ) ,
72+ Type :: Group ( g) => g. elem . extract_types ( ) ,
7173 Type :: ImplTrait ( it) => it
7274 . bounds
7375 . iter ( )
@@ -80,18 +82,54 @@ impl Extractor for Type {
8082 Type :: Infer ( _) => Vec :: new ( ) ,
8183 Type :: Macro ( _) => Vec :: new ( ) ,
8284 Type :: Never ( _) => Vec :: new ( ) ,
83- Type :: Paren ( p) => p. elem . extract_idents ( ) ,
85+ Type :: Paren ( p) => p. elem . extract_types ( ) ,
8486 Type :: Path ( p) => p
8587 . path
8688 . get_ident ( )
8789 . map ( ToOwned :: to_owned)
8890 . into_iter ( )
8991 . collect ( ) ,
90- Type :: Ptr ( p) => p. elem . extract_idents ( ) ,
91- Type :: Reference ( r) => r. elem . extract_idents ( ) ,
92- Type :: Slice ( s) => s. elem . extract_idents ( ) ,
92+ Type :: Ptr ( p) => p. elem . extract_types ( ) ,
93+ Type :: Reference ( r) => r. elem . extract_types ( ) ,
94+ Type :: Slice ( s) => s. elem . extract_types ( ) ,
9395 Type :: TraitObject ( _) => Vec :: new ( ) ,
94- Type :: Tuple ( t) => t. elems . iter ( ) . flat_map ( Self :: extract_idents) . collect ( ) ,
96+ Type :: Tuple ( t) => t. elems . iter ( ) . flat_map ( Self :: extract_types) . collect ( ) ,
97+ Type :: Verbatim ( _) => Vec :: new ( ) ,
98+ #[ allow( unknown_lints) ]
99+ #[ cfg_attr( test, deny( non_exhaustive_omitted_patterns) ) ]
100+ _ => Vec :: new ( ) ,
101+ }
102+ }
103+
104+ fn extract_consts ( & self ) -> Vec < Ident > {
105+ match self {
106+ Type :: Array ( a) => a. elem . extract_types ( ) ,
107+ Type :: BareFn ( _) => Vec :: new ( ) ,
108+ Type :: Group ( g) => g. elem . extract_types ( ) ,
109+ Type :: ImplTrait ( it) => it
110+ . bounds
111+ . iter ( )
112+ . cloned ( )
113+ . filter_map ( |b| match b {
114+ TypeParamBound :: Trait ( t) => t. path . get_ident ( ) . map ( ToOwned :: to_owned) ,
115+ TypeParamBound :: Lifetime ( _) => None ,
116+ } )
117+ . collect ( ) ,
118+ Type :: Infer ( _) => Vec :: new ( ) ,
119+ Type :: Macro ( _) => Vec :: new ( ) ,
120+ Type :: Never ( _) => Vec :: new ( ) ,
121+ Type :: Paren ( p) => p. elem . extract_types ( ) ,
122+ Type :: Path ( p) => p
123+ . path
124+ . get_ident ( )
125+ . map ( ToOwned :: to_owned)
126+ . into_iter ( )
127+ . collect ( ) ,
128+ Type :: Ptr ( p) => p. elem . extract_types ( ) ,
129+ Type :: Reference ( r) => r. elem . extract_types ( ) ,
130+ Type :: Slice ( s) => s. elem . extract_types ( ) ,
131+ Type :: TraitObject ( _) => Vec :: new ( ) ,
132+ Type :: Tuple ( t) => t. elems . iter ( ) . flat_map ( Self :: extract_types) . collect ( ) ,
95133 Type :: Verbatim ( _) => Vec :: new ( ) ,
96134 #[ allow( unknown_lints) ]
97135 #[ cfg_attr( test, deny( non_exhaustive_omitted_patterns) ) ]
0 commit comments