@@ -15,12 +15,15 @@ use syntax::source_map::Spanned;
15
15
use syntax:: symbol:: keywords;
16
16
use syntax:: ptr:: P ;
17
17
use syntax:: visit:: { self , Visitor } ;
18
+ use syntax_ext:: proc_macro_decls:: is_proc_macro_attr;
18
19
use syntax_pos:: Span ;
19
20
use errors;
20
21
use errors:: Applicability ;
21
22
22
23
struct AstValidator < ' a > {
23
24
session : & ' a Session ,
25
+ has_proc_macro_decls : bool ,
26
+ has_global_allocator : bool ,
24
27
25
28
// Used to ban nested `impl Trait`, e.g., `impl Into<impl Debug>`.
26
29
// Nested `impl Trait` _is_ allowed in associated type position,
@@ -367,6 +370,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
367
370
}
368
371
369
372
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
+
370
381
match item. node {
371
382
ItemKind :: Impl ( unsafety, polarity, _, _, Some ( ..) , ref ty, ref impl_items) => {
372
383
self . invalid_visibility ( & item. vis , None ) ;
@@ -590,10 +601,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
590
601
}
591
602
}
592
603
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 {
595
606
session,
607
+ has_proc_macro_decls : false ,
608
+ has_global_allocator : false ,
596
609
outer_impl_trait : None ,
597
610
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 )
599
615
}
0 commit comments