@@ -108,6 +108,8 @@ impl<'a> CollectCustomDerives<'a> {
108
108
109
109
impl < ' a > Visitor < ' a > for CollectCustomDerives < ' a > {
110
110
fn visit_item ( & mut self , item : & ' a ast:: Item ) {
111
+ let mut attrs = item. attrs . iter ( ) . filter ( |a| a. check_name ( "proc_macro_derive" ) ) ;
112
+
111
113
// First up, make sure we're checking a bare function. If we're not then
112
114
// we're just not interested in this item.
113
115
//
@@ -117,10 +119,7 @@ impl<'a> Visitor<'a> for CollectCustomDerives<'a> {
117
119
ast:: ItemKind :: Fn ( ..) => { }
118
120
_ => {
119
121
// Check for invalid use of proc_macro_derive
120
- let attr = item. attrs . iter ( )
121
- . filter ( |a| a. check_name ( "proc_macro_derive" ) )
122
- . next ( ) ;
123
- if let Some ( attr) = attr {
122
+ if let Some ( attr) = attrs. next ( ) {
124
123
self . handler . span_err ( attr. span ( ) ,
125
124
"the `#[proc_macro_derive]` \
126
125
attribute may only be used \
@@ -132,8 +131,6 @@ impl<'a> Visitor<'a> for CollectCustomDerives<'a> {
132
131
}
133
132
}
134
133
135
- let mut attrs = item. attrs . iter ( )
136
- . filter ( |a| a. check_name ( "proc_macro_derive" ) ) ;
137
134
let attr = match attrs. next ( ) {
138
135
Some ( attr) => attr,
139
136
None => {
@@ -227,16 +224,20 @@ impl<'a> Visitor<'a> for CollectCustomDerives<'a> {
227
224
Vec :: new ( )
228
225
} ;
229
226
230
- if self . in_root {
227
+ if self . in_root && item . vis == ast :: Visibility :: Public {
231
228
self . derives . push ( CustomDerive {
232
229
span : item. span ,
233
230
trait_name : trait_name,
234
231
function_name : item. ident ,
235
232
attrs : proc_attrs,
236
233
} ) ;
237
234
} else {
238
- let msg = "functions tagged with `#[proc_macro_derive]` must \
239
- currently reside in the root of the crate";
235
+ let msg = if !self . in_root {
236
+ "functions tagged with `#[proc_macro_derive]` must \
237
+ currently reside in the root of the crate"
238
+ } else {
239
+ "functions tagged with `#[proc_macro_derive]` must be `pub`"
240
+ } ;
240
241
self . handler . span_err ( item. span , msg) ;
241
242
}
242
243
0 commit comments