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