@@ -31,7 +31,7 @@ use syntax::ast::{Name, Ident};
31
31
use syntax:: attr;
32
32
33
33
use syntax:: ast:: { self , Block , ForeignItem , ForeignItemKind , Item , ItemKind , NodeId } ;
34
- use syntax:: ast:: { MetaItemKind , StmtKind , TraitItem , TraitItemKind , Variant } ;
34
+ use syntax:: ast:: { MetaItemKind , StmtKind , TraitItem , TraitItemKind } ;
35
35
use syntax:: ext:: base:: { MacroKind , SyntaxExtension } ;
36
36
use syntax:: ext:: expand:: AstFragment ;
37
37
use syntax:: ext:: hygiene:: ExpnId ;
@@ -580,7 +580,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
580
580
}
581
581
582
582
/// Constructs the reduced graph for one item.
583
- fn build_reduced_graph_for_item ( & mut self , item : & Item ) {
583
+ fn build_reduced_graph_for_item ( & mut self , item : & ' b Item ) {
584
584
let parent_scope = & self . parent_scope ;
585
585
let parent = parent_scope. module ;
586
586
let expansion = parent_scope. expansion ;
@@ -716,23 +716,17 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
716
716
self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
717
717
}
718
718
719
- ItemKind :: Enum ( ref enum_definition, _) => {
720
- let module_kind = ModuleKind :: Def (
721
- DefKind :: Enum ,
722
- self . r . definitions . local_def_id ( item. id ) ,
723
- ident. name ,
724
- ) ;
719
+ ItemKind :: Enum ( _, _) => {
720
+ let def_id = self . r . definitions . local_def_id ( item. id ) ;
721
+ self . r . variant_vis . insert ( def_id, vis) ;
722
+ let module_kind = ModuleKind :: Def ( DefKind :: Enum , def_id, ident. name ) ;
725
723
let module = self . r . new_module ( parent,
726
724
module_kind,
727
725
parent. normal_ancestor_id ,
728
726
expansion,
729
727
item. span ) ;
730
728
self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
731
729
self . parent_scope . module = module;
732
-
733
- for variant in & ( * enum_definition) . variants {
734
- self . build_reduced_graph_for_variant ( variant, vis) ;
735
- }
736
730
}
737
731
738
732
ItemKind :: TraitAlias ( ..) => {
@@ -817,38 +811,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
817
811
}
818
812
}
819
813
820
- // Constructs the reduced graph for one variant. Variants exist in the
821
- // type and value namespaces.
822
- fn build_reduced_graph_for_variant ( & mut self , variant : & Variant , vis : ty:: Visibility ) {
823
- let parent = self . parent_scope . module ;
824
- let expn_id = self . parent_scope . expansion ;
825
- let ident = variant. ident ;
826
-
827
- // Define a name in the type namespace.
828
- let def_id = self . r . definitions . local_def_id ( variant. id ) ;
829
- let res = Res :: Def ( DefKind :: Variant , def_id) ;
830
- self . r . define ( parent, ident, TypeNS , ( res, vis, variant. span , expn_id) ) ;
831
-
832
- // If the variant is marked as non_exhaustive then lower the visibility to within the
833
- // crate.
834
- let mut ctor_vis = vis;
835
- let has_non_exhaustive = attr:: contains_name ( & variant. attrs , sym:: non_exhaustive) ;
836
- if has_non_exhaustive && vis == ty:: Visibility :: Public {
837
- ctor_vis = ty:: Visibility :: Restricted ( DefId :: local ( CRATE_DEF_INDEX ) ) ;
838
- }
839
-
840
- // Define a constructor name in the value namespace.
841
- // Braced variants, unlike structs, generate unusable names in
842
- // value namespace, they are reserved for possible future use.
843
- // It's ok to use the variant's id as a ctor id since an
844
- // error will be reported on any use of such resolution anyway.
845
- let ctor_node_id = variant. data . ctor_id ( ) . unwrap_or ( variant. id ) ;
846
- let ctor_def_id = self . r . definitions . local_def_id ( ctor_node_id) ;
847
- let ctor_kind = CtorKind :: from_ast ( & variant. data ) ;
848
- let ctor_res = Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , ctor_kind) , ctor_def_id) ;
849
- self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, variant. span , expn_id) ) ;
850
- }
851
-
852
814
/// Constructs the reduced graph for one foreign item.
853
815
fn build_reduced_graph_for_foreign_item ( & mut self , item : & ForeignItem ) {
854
816
let ( res, ns) = match item. node {
@@ -1188,7 +1150,6 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
1188
1150
ItemKind :: Mod ( ..) => self . contains_macro_use ( & item. attrs ) ,
1189
1151
_ => false ,
1190
1152
} ;
1191
-
1192
1153
let orig_current_module = self . parent_scope . module ;
1193
1154
let orig_current_legacy_scope = self . parent_scope . legacy ;
1194
1155
self . build_reduced_graph_for_item ( item) ;
@@ -1271,4 +1232,92 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
1271
1232
}
1272
1233
visit:: walk_attribute ( self , attr) ;
1273
1234
}
1235
+
1236
+ fn visit_arm ( & mut self , arm : & ' b ast:: Arm ) {
1237
+ if arm. is_placeholder {
1238
+ self . visit_invoc ( arm. id ) ;
1239
+ } else {
1240
+ visit:: walk_arm ( self , arm) ;
1241
+ }
1242
+ }
1243
+
1244
+ fn visit_field ( & mut self , f : & ' b ast:: Field ) {
1245
+ if f. is_placeholder {
1246
+ self . visit_invoc ( f. id ) ;
1247
+ } else {
1248
+ visit:: walk_field ( self , f) ;
1249
+ }
1250
+ }
1251
+
1252
+ fn visit_field_pattern ( & mut self , fp : & ' b ast:: FieldPat ) {
1253
+ if fp. is_placeholder {
1254
+ self . visit_invoc ( fp. id ) ;
1255
+ } else {
1256
+ visit:: walk_field_pattern ( self , fp) ;
1257
+ }
1258
+ }
1259
+
1260
+ fn visit_generic_param ( & mut self , param : & ' b ast:: GenericParam ) {
1261
+ if param. is_placeholder {
1262
+ self . visit_invoc ( param. id ) ;
1263
+ } else {
1264
+ visit:: walk_generic_param ( self , param) ;
1265
+ }
1266
+ }
1267
+
1268
+ fn visit_param ( & mut self , p : & ' b ast:: Param ) {
1269
+ if p. is_placeholder {
1270
+ self . visit_invoc ( p. id ) ;
1271
+ } else {
1272
+ visit:: walk_param ( self , p) ;
1273
+ }
1274
+ }
1275
+
1276
+ fn visit_struct_field ( & mut self , sf : & ' b ast:: StructField ) {
1277
+ if sf. is_placeholder {
1278
+ self . visit_invoc ( sf. id ) ;
1279
+ } else {
1280
+ visit:: walk_struct_field ( self , sf) ;
1281
+ }
1282
+ }
1283
+
1284
+ // Constructs the reduced graph for one variant. Variants exist in the
1285
+ // type and value namespaces.
1286
+ fn visit_variant ( & mut self , variant : & ' b ast:: Variant ) {
1287
+ if variant. is_placeholder {
1288
+ self . visit_invoc ( variant. id ) ;
1289
+ return ;
1290
+ }
1291
+
1292
+ let parent = self . parent_scope . module ;
1293
+ let vis = self . r . variant_vis [ & parent. def_id ( ) . expect ( "enum without def-id" ) ] ;
1294
+ let expn_id = self . parent_scope . expansion ;
1295
+ let ident = variant. ident ;
1296
+
1297
+ // Define a name in the type namespace.
1298
+ let def_id = self . r . definitions . local_def_id ( variant. id ) ;
1299
+ let res = Res :: Def ( DefKind :: Variant , def_id) ;
1300
+ self . r . define ( parent, ident, TypeNS , ( res, vis, variant. span , expn_id) ) ;
1301
+
1302
+ // If the variant is marked as non_exhaustive then lower the visibility to within the
1303
+ // crate.
1304
+ let mut ctor_vis = vis;
1305
+ let has_non_exhaustive = attr:: contains_name ( & variant. attrs , sym:: non_exhaustive) ;
1306
+ if has_non_exhaustive && vis == ty:: Visibility :: Public {
1307
+ ctor_vis = ty:: Visibility :: Restricted ( DefId :: local ( CRATE_DEF_INDEX ) ) ;
1308
+ }
1309
+
1310
+ // Define a constructor name in the value namespace.
1311
+ // Braced variants, unlike structs, generate unusable names in
1312
+ // value namespace, they are reserved for possible future use.
1313
+ // It's ok to use the variant's id as a ctor id since an
1314
+ // error will be reported on any use of such resolution anyway.
1315
+ let ctor_node_id = variant. data . ctor_id ( ) . unwrap_or ( variant. id ) ;
1316
+ let ctor_def_id = self . r . definitions . local_def_id ( ctor_node_id) ;
1317
+ let ctor_kind = CtorKind :: from_ast ( & variant. data ) ;
1318
+ let ctor_res = Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , ctor_kind) , ctor_def_id) ;
1319
+ self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, variant. span , expn_id) ) ;
1320
+
1321
+ visit:: walk_variant ( self , variant) ;
1322
+ }
1274
1323
}
0 commit comments