@@ -628,6 +628,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
628
628
let vis = self . resolve_visibility ( & item. vis ) ;
629
629
let local_def_id = self . r . local_def_id ( item. id ) ;
630
630
let def_id = local_def_id. to_def_id ( ) ;
631
+ let def_kind = self . r . tcx . def_kind ( def_id) ;
632
+ let res = Res :: Def ( def_kind, def_id) ;
631
633
632
634
self . r . visibilities . insert ( local_def_id, vis) ;
633
635
@@ -659,7 +661,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
659
661
ItemKind :: Mod ( ..) => {
660
662
let module = self . r . new_module (
661
663
Some ( parent) ,
662
- ModuleKind :: Def ( DefKind :: Mod , def_id, ident. name ) ,
664
+ ModuleKind :: Def ( def_kind , def_id, ident. name ) ,
663
665
expansion. to_expn_id ( ) ,
664
666
item. span ,
665
667
parent. no_implicit_prelude
@@ -672,16 +674,13 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
672
674
}
673
675
674
676
// These items live in the value namespace.
675
- ItemKind :: Static ( box ast:: StaticItem { mutability, .. } ) => {
676
- let res = Res :: Def ( DefKind :: Static ( mutability) , def_id) ;
677
+ ItemKind :: Static ( ..) => {
677
678
self . r . define ( parent, ident, ValueNS , ( res, vis, sp, expansion) ) ;
678
679
}
679
680
ItemKind :: Const ( ..) => {
680
- let res = Res :: Def ( DefKind :: Const , def_id) ;
681
681
self . r . define ( parent, ident, ValueNS , ( res, vis, sp, expansion) ) ;
682
682
}
683
683
ItemKind :: Fn ( ..) => {
684
- let res = Res :: Def ( DefKind :: Fn , def_id) ;
685
684
self . r . define ( parent, ident, ValueNS , ( res, vis, sp, expansion) ) ;
686
685
687
686
// Functions introducing procedural macros reserve a slot
@@ -691,14 +690,13 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
691
690
692
691
// These items live in the type namespace.
693
692
ItemKind :: TyAlias ( ..) => {
694
- let res = Res :: Def ( DefKind :: TyAlias , def_id) ;
695
693
self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
696
694
}
697
695
698
696
ItemKind :: Enum ( _, _) => {
699
697
let module = self . r . new_module (
700
698
Some ( parent) ,
701
- ModuleKind :: Def ( DefKind :: Enum , def_id, ident. name ) ,
699
+ ModuleKind :: Def ( def_kind , def_id, ident. name ) ,
702
700
expansion. to_expn_id ( ) ,
703
701
item. span ,
704
702
parent. no_implicit_prelude ,
@@ -708,14 +706,12 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
708
706
}
709
707
710
708
ItemKind :: TraitAlias ( ..) => {
711
- let res = Res :: Def ( DefKind :: TraitAlias , def_id) ;
712
709
self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
713
710
}
714
711
715
712
// These items live in both the type and value namespaces.
716
713
ItemKind :: Struct ( ref vdata, _) => {
717
714
// Define a name in the type namespace.
718
- let res = Res :: Def ( DefKind :: Struct , def_id) ;
719
715
self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
720
716
721
717
// Record field names for error reporting.
@@ -724,7 +720,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
724
720
725
721
// If this is a tuple or unit struct, define a name
726
722
// in the value namespace as well.
727
- if let Some ( ( ctor_kind , ctor_node_id) ) = CtorKind :: from_ast ( vdata) {
723
+ if let Some ( ctor_node_id) = vdata. ctor_node_id ( ) {
728
724
// If the structure is marked as non_exhaustive then lower the visibility
729
725
// to within the crate.
730
726
let mut ctor_vis = if vis. is_public ( )
@@ -750,8 +746,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
750
746
ret_fields. push ( field_vis. to_def_id ( ) ) ;
751
747
}
752
748
let ctor_def_id = self . r . local_def_id ( ctor_node_id) ;
753
- let ctor_res =
754
- Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ctor_kind ) , ctor_def_id. to_def_id ( ) ) ;
749
+ let ctor_def_kind = self . r . tcx . def_kind ( ctor_def_id ) ;
750
+ let ctor_res = Res :: Def ( ctor_def_kind , ctor_def_id. to_def_id ( ) ) ;
755
751
self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, sp, expansion) ) ;
756
752
self . r . visibilities . insert ( ctor_def_id, ctor_vis) ;
757
753
// We need the field visibility spans also for the constructor for E0603.
@@ -764,7 +760,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
764
760
}
765
761
766
762
ItemKind :: Union ( ref vdata, _) => {
767
- let res = Res :: Def ( DefKind :: Union , def_id) ;
768
763
self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
769
764
770
765
// Record field names for error reporting.
@@ -776,7 +771,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
776
771
// Add all the items within to a new module.
777
772
let module = self . r . new_module (
778
773
Some ( parent) ,
779
- ModuleKind :: Def ( DefKind :: Trait , def_id, ident. name ) ,
774
+ ModuleKind :: Def ( def_kind , def_id, ident. name ) ,
780
775
expansion. to_expn_id ( ) ,
781
776
item. span ,
782
777
parent. no_implicit_prelude ,
@@ -888,16 +883,16 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
888
883
fn build_reduced_graph_for_foreign_item ( & mut self , item : & ForeignItem ) {
889
884
let local_def_id = self . r . local_def_id ( item. id ) ;
890
885
let def_id = local_def_id. to_def_id ( ) ;
891
- let ( def_kind , ns ) = match item. kind {
892
- ForeignItemKind :: Fn ( ..) => ( DefKind :: Fn , ValueNS ) ,
893
- ForeignItemKind :: Static ( _ , mt , _ ) => ( DefKind :: Static ( mt ) , ValueNS ) ,
894
- ForeignItemKind :: TyAlias ( ..) => ( DefKind :: ForeignTy , TypeNS ) ,
895
- ForeignItemKind :: MacCall ( _ ) => unreachable ! ( ) ,
886
+ let ns = match item. kind {
887
+ ForeignItemKind :: Fn ( ..) => ValueNS ,
888
+ ForeignItemKind :: Static ( .. ) => ValueNS ,
889
+ ForeignItemKind :: TyAlias ( ..) => TypeNS ,
890
+ ForeignItemKind :: MacCall ( .. ) => unreachable ! ( ) ,
896
891
} ;
897
892
let parent = self . parent_scope . module ;
898
893
let expansion = self . parent_scope . expansion ;
899
894
let vis = self . resolve_visibility ( & item. vis ) ;
900
- let res = Res :: Def ( def_kind, def_id) ;
895
+ let res = Res :: Def ( self . r . tcx . def_kind ( def_id ) , def_id) ;
901
896
self . r . define ( parent, item. ident , ns, ( res, vis, item. span , expansion) ) ;
902
897
self . r . visibilities . insert ( local_def_id, vis) ;
903
898
}
@@ -1180,24 +1175,21 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1180
1175
let parent_scope = self . parent_scope ;
1181
1176
let expansion = parent_scope. expansion ;
1182
1177
let def_id = self . r . local_def_id ( item. id ) ;
1183
- let ( macro_kind, ident, span, macro_rules) = match & item. kind {
1184
- ItemKind :: MacroDef ( def) => {
1185
- let macro_kind = self . r . macro_map [ & def_id. to_def_id ( ) ] . ext . macro_kind ( ) ;
1186
- ( macro_kind, item. ident , item. span , def. macro_rules )
1187
- }
1178
+ let ( ident, span, macro_rules) = match & item. kind {
1179
+ ItemKind :: MacroDef ( def) => ( item. ident , item. span , def. macro_rules ) ,
1188
1180
ItemKind :: Fn ( ..) => match self . proc_macro_stub ( item) {
1189
1181
Some ( ( macro_kind, ident, span) ) => {
1190
1182
let macro_data = MacroData :: new ( self . r . dummy_ext ( macro_kind) ) ;
1191
1183
self . r . macro_map . insert ( def_id. to_def_id ( ) , macro_data) ;
1192
1184
self . r . proc_macro_stubs . insert ( def_id) ;
1193
- ( macro_kind , ident, span, false )
1185
+ ( ident, span, false )
1194
1186
}
1195
1187
None => return parent_scope. macro_rules ,
1196
1188
} ,
1197
1189
_ => unreachable ! ( ) ,
1198
1190
} ;
1199
1191
1200
- let res = Res :: Def ( DefKind :: Macro ( macro_kind ) , def_id. to_def_id ( ) ) ;
1192
+ let res = Res :: Def ( self . r . tcx . def_kind ( def_id ) , def_id. to_def_id ( ) ) ;
1201
1193
self . r . local_macro_def_scopes . insert ( def_id, parent_scope. module ) ;
1202
1194
1203
1195
if macro_rules {
@@ -1363,21 +1355,21 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1363
1355
}
1364
1356
1365
1357
if ctxt == AssocCtxt :: Trait {
1366
- let ( def_kind , ns ) = match item. kind {
1367
- AssocItemKind :: Const ( ..) => ( DefKind :: AssocConst , ValueNS ) ,
1358
+ let ns = match item. kind {
1359
+ AssocItemKind :: Const ( ..) => ValueNS ,
1368
1360
AssocItemKind :: Fn ( box Fn { ref sig, .. } ) => {
1369
1361
if sig. decl . has_self ( ) {
1370
1362
self . r . has_self . insert ( local_def_id) ;
1371
1363
}
1372
- ( DefKind :: AssocFn , ValueNS )
1364
+ ValueNS
1373
1365
}
1374
- AssocItemKind :: Type ( ..) => ( DefKind :: AssocTy , TypeNS ) ,
1366
+ AssocItemKind :: Type ( ..) => TypeNS ,
1375
1367
AssocItemKind :: MacCall ( _) => bug ! ( ) , // handled above
1376
1368
} ;
1377
1369
1378
1370
let parent = self . parent_scope . module ;
1379
1371
let expansion = self . parent_scope . expansion ;
1380
- let res = Res :: Def ( def_kind, def_id) ;
1372
+ let res = Res :: Def ( self . r . tcx . def_kind ( def_id ) , def_id) ;
1381
1373
self . r . define ( parent, item. ident , ns, ( res, vis, item. span , expansion) ) ;
1382
1374
}
1383
1375
@@ -1457,7 +1449,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1457
1449
1458
1450
// Define a name in the type namespace.
1459
1451
let def_id = self . r . local_def_id ( variant. id ) ;
1460
- let res = Res :: Def ( DefKind :: Variant , def_id. to_def_id ( ) ) ;
1452
+ let res = Res :: Def ( self . r . tcx . def_kind ( def_id ) , def_id. to_def_id ( ) ) ;
1461
1453
let vis = self . resolve_visibility ( & variant. vis ) ;
1462
1454
self . r . define ( parent, ident, TypeNS , ( res, vis, variant. span , expn_id) ) ;
1463
1455
self . r . visibilities . insert ( def_id, vis) ;
@@ -1471,10 +1463,10 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1471
1463
} ;
1472
1464
1473
1465
// Define a constructor name in the value namespace.
1474
- if let Some ( ( ctor_kind , ctor_node_id) ) = CtorKind :: from_ast ( & variant. data ) {
1466
+ if let Some ( ctor_node_id) = variant. data . ctor_node_id ( ) {
1475
1467
let ctor_def_id = self . r . local_def_id ( ctor_node_id) ;
1476
- let ctor_res =
1477
- Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , ctor_kind ) , ctor_def_id. to_def_id ( ) ) ;
1468
+ let ctor_def_kind = self . r . tcx . def_kind ( ctor_def_id ) ;
1469
+ let ctor_res = Res :: Def ( ctor_def_kind , ctor_def_id. to_def_id ( ) ) ;
1478
1470
self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, variant. span , expn_id) ) ;
1479
1471
self . r . visibilities . insert ( ctor_def_id, ctor_vis) ;
1480
1472
}
0 commit comments