@@ -688,7 +688,7 @@ pub fn check_for_pushpop_syntax(f: Option<&Features>, diag: &Handler, span: Span
688
688
}
689
689
690
690
struct Context < ' a > {
691
- features : Features ,
691
+ features : & ' a Features ,
692
692
span_handler : & ' a Handler ,
693
693
cm : & ' a CodeMap ,
694
694
plugin_attributes : & ' a [ ( String , AttributeType ) ] ,
@@ -739,9 +739,7 @@ impl<'a> Context<'a> {
739
739
with the prefix `rustc_` \
740
740
are reserved for internal compiler diagnostics") ;
741
741
} 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 ) ;
745
743
} else {
746
744
// Only run the custom attribute lint during regular
747
745
// feature gate checking. Macro gating runs
@@ -759,6 +757,15 @@ impl<'a> Context<'a> {
759
757
}
760
758
}
761
759
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
+
762
769
fn find_lang_feature_issue ( feature : & str ) -> Option < u32 > {
763
770
if let Some ( info) = ACTIVE_FEATURES . iter ( ) . find ( |t| t. 0 == feature) {
764
771
let issue = info. 2 ;
@@ -819,64 +826,8 @@ pub const EXPLAIN_ALLOW_INTERNAL_UNSTABLE: &'static str =
819
826
pub const EXPLAIN_CUSTOM_DERIVE : & ' static str =
820
827
"`#[derive]` for custom traits is not stable enough for use and is subject to change" ;
821
828
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" ;
880
831
881
832
struct PostExpansionVisitor < ' a > {
882
833
context : & ' a Context < ' a > ,
@@ -1177,13 +1128,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
1177
1128
}
1178
1129
}
1179
1130
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 {
1187
1132
let mut features = Features :: new ( ) ;
1188
1133
1189
1134
for attr in & krate. attrs {
@@ -1226,32 +1171,24 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &Handler,
1226
1171
}
1227
1172
}
1228
1173
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
1244
1175
}
1245
1176
1246
1177
pub fn check_crate ( cm : & CodeMap , span_handler : & Handler , krate : & ast:: Crate ,
1247
1178
plugin_attributes : & [ ( String , AttributeType ) ] ,
1248
- unstable : UnstableFeatures ) -> Features
1249
- {
1179
+ unstable : UnstableFeatures ) -> Features {
1250
1180
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
1255
1192
}
1256
1193
1257
1194
#[ derive( Clone , Copy ) ]
0 commit comments