@@ -15,11 +15,33 @@ pub trait ItemLike: Stability {
15
15
fn is_public ( & self ) -> bool {
16
16
matches ! ( self . visibility( ) , Visibility :: Public ( _) )
17
17
}
18
+
19
+ fn allowed_lints ( & self ) -> Vec < syn:: Ident > ;
18
20
}
19
21
20
- macro_rules! impl_has_visibility {
21
- ( $( $ty: ty) ,+ $( , ) ?) => {
22
- $(
22
+ /// Implement `ItemLike` for the given type.
23
+ ///
24
+ /// This makes each of the syn::Item* types implement our `ItemLike` trait to make it possible to
25
+ /// work with them in a more uniform way.
26
+ ///
27
+ /// A single type can be passed to this macro, or multiple types can be passed at once.
28
+ /// Each type can be passed with a list of lints that are allowed for that type (defaulting to
29
+ /// `dead_code` if not specified).
30
+ macro_rules! impl_item_like {
31
+ // run impl_item_like for each item in a list of items
32
+ ( $( $( #[ allow( $( $lint: ident) ,* ) ] ) ? $ty: ty ) ,+ , ) => {
33
+ $(
34
+ impl_item_like!( $( #[ allow( $( $lint) ,* ) ] ) ? $ty ) ;
35
+ ) *
36
+ } ;
37
+
38
+ // run impl_item_like for a single item without any lints
39
+ ( $ty: ty) => {
40
+ impl_item_like!( #[ allow( dead_code) ] $ty ) ;
41
+ } ;
42
+
43
+ // Implement `ItemLike` for the given type.
44
+ ( #[ allow( $( $lint: ident) ,* ) ] $ty: ty) => {
23
45
impl Stability for $ty {
24
46
fn attrs( & self ) -> & [ syn:: Attribute ] {
25
47
& self . attrs
@@ -38,19 +60,26 @@ macro_rules! impl_has_visibility {
38
60
fn set_visibility( & mut self , visibility: Visibility ) {
39
61
self . vis = visibility;
40
62
}
63
+
64
+ fn allowed_lints( & self ) -> Vec <syn:: Ident > {
65
+ vec![
66
+ $( syn:: Ident :: new( stringify!( $lint) , proc_macro2:: Span :: call_site( ) ) , ) *
67
+ ]
68
+ }
41
69
}
42
- ) *
43
- } ;
70
+ } ;
71
+
44
72
}
45
73
46
- impl_has_visibility ! (
74
+ impl_item_like ! (
47
75
syn:: ItemType ,
48
76
syn:: ItemEnum ,
49
77
syn:: ItemFn ,
50
78
syn:: ItemMod ,
51
79
syn:: ItemTrait ,
52
80
syn:: ItemConst ,
53
81
syn:: ItemStatic ,
82
+ #[ allow( unused_imports) ]
54
83
syn:: ItemUse ,
55
84
) ;
56
85
@@ -79,6 +108,10 @@ impl ItemLike for syn::ItemStruct {
79
108
80
109
self . vis = visibility;
81
110
}
111
+
112
+ fn allowed_lints ( & self ) -> Vec < syn:: Ident > {
113
+ vec ! [ syn:: Ident :: new( "dead_code" , proc_macro2:: Span :: call_site( ) ) ]
114
+ }
82
115
}
83
116
84
117
impl Stability for syn:: ItemImpl {
0 commit comments