@@ -108,6 +108,8 @@ impl<'a> CollectCustomDerives<'a> {
108108
109109impl < ' a > Visitor < ' a > for CollectCustomDerives < ' a > {
110110 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+
111113 // First up, make sure we're checking a bare function. If we're not then
112114 // we're just not interested in this item.
113115 //
@@ -117,10 +119,7 @@ impl<'a> Visitor<'a> for CollectCustomDerives<'a> {
117119 ast:: ItemKind :: Fn ( ..) => { }
118120 _ => {
119121 // 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 ( ) {
124123 self . handler . span_err ( attr. span ( ) ,
125124 "the `#[proc_macro_derive]` \
126125 attribute may only be used \
@@ -132,8 +131,6 @@ impl<'a> Visitor<'a> for CollectCustomDerives<'a> {
132131 }
133132 }
134133
135- let mut attrs = item. attrs . iter ( )
136- . filter ( |a| a. check_name ( "proc_macro_derive" ) ) ;
137134 let attr = match attrs. next ( ) {
138135 Some ( attr) => attr,
139136 None => {
@@ -227,16 +224,20 @@ impl<'a> Visitor<'a> for CollectCustomDerives<'a> {
227224 Vec :: new ( )
228225 } ;
229226
230- if self . in_root {
227+ if self . in_root && item . vis == ast :: Visibility :: Public {
231228 self . derives . push ( CustomDerive {
232229 span : item. span ,
233230 trait_name : trait_name,
234231 function_name : item. ident ,
235232 attrs : proc_attrs,
236233 } ) ;
237234 } 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+ } ;
240241 self . handler . span_err ( item. span , msg) ;
241242 }
242243
0 commit comments