@@ -15,12 +15,15 @@ use syntax::source_map::Spanned;
1515use syntax:: symbol:: keywords;
1616use syntax:: ptr:: P ;
1717use syntax:: visit:: { self , Visitor } ;
18+ use syntax_ext:: proc_macro_decls:: is_proc_macro_attr;
1819use syntax_pos:: Span ;
1920use errors;
2021use errors:: Applicability ;
2122
2223struct AstValidator < ' a > {
2324 session : & ' a Session ,
25+ has_proc_macro_decls : bool ,
26+ has_global_allocator : bool ,
2427
2528 // Used to ban nested `impl Trait`, e.g., `impl Into<impl Debug>`.
2629 // Nested `impl Trait` _is_ allowed in associated type position,
@@ -367,6 +370,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
367370 }
368371
369372 fn visit_item ( & mut self , item : & ' a Item ) {
373+ if item. attrs . iter ( ) . any ( |attr| is_proc_macro_attr ( attr) ) {
374+ self . has_proc_macro_decls = true ;
375+ }
376+
377+ if attr:: contains_name ( & item. attrs , "global_allocator" ) {
378+ self . has_global_allocator = true ;
379+ }
380+
370381 match item. node {
371382 ItemKind :: Impl ( unsafety, polarity, _, _, Some ( ..) , ref ty, ref impl_items) => {
372383 self . invalid_visibility ( & item. vis , None ) ;
@@ -590,10 +601,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
590601 }
591602}
592603
593- pub fn check_crate ( session : & Session , krate : & Crate ) {
594- visit :: walk_crate ( & mut AstValidator {
604+ pub fn check_crate ( session : & Session , krate : & Crate ) -> ( bool , bool ) {
605+ let mut validator = AstValidator {
595606 session,
607+ has_proc_macro_decls : false ,
608+ has_global_allocator : false ,
596609 outer_impl_trait : None ,
597610 is_impl_trait_banned : false ,
598- } , krate)
611+ } ;
612+ visit:: walk_crate ( & mut validator, krate) ;
613+
614+ ( validator. has_proc_macro_decls , validator. has_global_allocator )
599615}
0 commit comments