@@ -688,7 +688,7 @@ pub fn check_for_pushpop_syntax(f: Option<&Features>, diag: &Handler, span: Span
688688}
689689
690690struct Context < ' a > {
691- features : Features ,
691+ features : & ' a Features ,
692692 span_handler : & ' a Handler ,
693693 cm : & ' a CodeMap ,
694694 plugin_attributes : & ' a [ ( String , AttributeType ) ] ,
@@ -739,9 +739,7 @@ impl<'a> Context<'a> {
739739 with the prefix `rustc_` \
740740 are reserved for internal compiler diagnostics") ;
741741 } else if name. starts_with ( "derive_" ) {
742- gate_feature ! ( self , custom_derive, attr. span,
743- "attributes of the form `#[derive_*]` are reserved \
744- for the compiler") ;
742+ gate_feature ! ( self , custom_derive, attr. span, EXPLAIN_DERIVE_UNDERSCORE ) ;
745743 } else {
746744 // Only run the custom attribute lint during regular
747745 // feature gate checking. Macro gating runs
@@ -759,6 +757,15 @@ impl<'a> Context<'a> {
759757 }
760758}
761759
760+ pub fn check_attribute ( attr : & ast:: Attribute , handler : & Handler ,
761+ cm : & CodeMap , features : & Features ) {
762+ let cx = Context {
763+ features : features, span_handler : handler,
764+ cm : cm, plugin_attributes : & [ ]
765+ } ;
766+ cx. check_attribute ( attr, true ) ;
767+ }
768+
762769fn find_lang_feature_issue ( feature : & str ) -> Option < u32 > {
763770 if let Some ( info) = ACTIVE_FEATURES . iter ( ) . find ( |t| t. 0 == feature) {
764771 let issue = info. 2 ;
@@ -819,64 +826,8 @@ pub const EXPLAIN_ALLOW_INTERNAL_UNSTABLE: &'static str =
819826pub const EXPLAIN_CUSTOM_DERIVE : & ' static str =
820827 "`#[derive]` for custom traits is not stable enough for use and is subject to change" ;
821828
822- struct MacroVisitor < ' a > {
823- context : & ' a Context < ' a >
824- }
825-
826- impl < ' a , ' v > Visitor < ' v > for MacroVisitor < ' a > {
827- fn visit_mac ( & mut self , mac : & ast:: Mac ) {
828- let path = & mac. node . path ;
829- let name = path. segments . last ( ) . unwrap ( ) . identifier . name . as_str ( ) ;
830-
831- // Issue 22234: If you add a new case here, make sure to also
832- // add code to catch the macro during or after expansion.
833- //
834- // We still keep this MacroVisitor (rather than *solely*
835- // relying on catching cases during or after expansion) to
836- // catch uses of these macros within conditionally-compiled
837- // code, e.g. `#[cfg]`-guarded functions.
838-
839- if name == "asm" {
840- gate_feature ! ( self . context, asm, path. span, EXPLAIN_ASM ) ;
841- }
842-
843- else if name == "log_syntax" {
844- gate_feature ! ( self . context, log_syntax, path. span, EXPLAIN_LOG_SYNTAX ) ;
845- }
846-
847- else if name == "trace_macros" {
848- gate_feature ! ( self . context, trace_macros, path. span, EXPLAIN_TRACE_MACROS ) ;
849- }
850-
851- else if name == "concat_idents" {
852- gate_feature ! ( self . context, concat_idents, path. span, EXPLAIN_CONCAT_IDENTS ) ;
853- }
854- }
855-
856- fn visit_attribute ( & mut self , attr : & ' v ast:: Attribute ) {
857- self . context . check_attribute ( attr, true ) ;
858- }
859-
860- fn visit_expr ( & mut self , e : & ast:: Expr ) {
861- // Issue 22181: overloaded-`box` and placement-`in` are
862- // implemented via a desugaring expansion, so their feature
863- // gates go into MacroVisitor since that works pre-expansion.
864- //
865- // Issue 22234: we also check during expansion as well.
866- // But we keep these checks as a pre-expansion check to catch
867- // uses in e.g. conditionalized code.
868-
869- if let ast:: ExprKind :: Box ( _) = e. node {
870- gate_feature ! ( self . context, box_syntax, e. span, EXPLAIN_BOX_SYNTAX ) ;
871- }
872-
873- if let ast:: ExprKind :: InPlace ( ..) = e. node {
874- gate_feature ! ( self . context, placement_in_syntax, e. span, EXPLAIN_PLACEMENT_IN ) ;
875- }
876-
877- visit:: walk_expr ( self , e) ;
878- }
879- }
829+ pub const EXPLAIN_DERIVE_UNDERSCORE : & ' static str =
830+ "attributes of the form `#[derive_*]` are reserved for the compiler" ;
880831
881832struct PostExpansionVisitor < ' a > {
882833 context : & ' a Context < ' a > ,
@@ -1177,13 +1128,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
11771128 }
11781129}
11791130
1180- fn check_crate_inner < F > ( cm : & CodeMap , span_handler : & Handler ,
1181- krate : & ast:: Crate ,
1182- plugin_attributes : & [ ( String , AttributeType ) ] ,
1183- check : F )
1184- -> Features
1185- where F : FnOnce ( & mut Context , & ast:: Crate )
1186- {
1131+ pub fn get_features ( span_handler : & Handler , krate : & ast:: Crate ) -> Features {
11871132 let mut features = Features :: new ( ) ;
11881133
11891134 for attr in & krate. attrs {
@@ -1226,32 +1171,24 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &Handler,
12261171 }
12271172 }
12281173
1229- let mut cx = Context {
1230- features : features,
1231- span_handler : span_handler,
1232- cm : cm,
1233- plugin_attributes : plugin_attributes,
1234- } ;
1235-
1236- check ( & mut cx, krate) ;
1237- cx. features
1238- }
1239-
1240- pub fn check_crate_macros ( cm : & CodeMap , span_handler : & Handler , krate : & ast:: Crate )
1241- -> Features {
1242- check_crate_inner ( cm, span_handler, krate, & [ ] as & ' static [ _ ] ,
1243- |ctx, krate| visit:: walk_crate ( & mut MacroVisitor { context : ctx } , krate) )
1174+ features
12441175}
12451176
12461177pub fn check_crate ( cm : & CodeMap , span_handler : & Handler , krate : & ast:: Crate ,
12471178 plugin_attributes : & [ ( String , AttributeType ) ] ,
1248- unstable : UnstableFeatures ) -> Features
1249- {
1179+ unstable : UnstableFeatures ) -> Features {
12501180 maybe_stage_features ( span_handler, krate, unstable) ;
1251-
1252- check_crate_inner ( cm, span_handler, krate, plugin_attributes,
1253- |ctx, krate| visit:: walk_crate ( & mut PostExpansionVisitor { context : ctx } ,
1254- krate) )
1181+ let features = get_features ( span_handler, krate) ;
1182+ {
1183+ let ctx = Context {
1184+ features : & features,
1185+ span_handler : span_handler,
1186+ cm : cm,
1187+ plugin_attributes : plugin_attributes,
1188+ } ;
1189+ visit:: walk_crate ( & mut PostExpansionVisitor { context : & ctx } , krate) ;
1190+ }
1191+ features
12551192}
12561193
12571194#[ derive( Clone , Copy ) ]
0 commit comments