@@ -1089,63 +1089,32 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1089
1089
// Iterate over all children.
1090
1090
if let Some ( children) = self . root . tables . children . get ( self , id) {
1091
1091
for child_index in children. decode ( ( self , sess) ) {
1092
- if let Some ( ident) = self . opt_item_ident ( child_index, sess) {
1093
- let kind = self . def_kind ( child_index) ;
1094
- let def_id = self . local_def_id ( child_index) ;
1095
- let res = Res :: Def ( kind, def_id) ;
1096
- let vis = self . get_visibility ( child_index) ;
1097
- let span = self . get_span ( child_index, sess) ;
1098
- let macro_rules = match kind {
1099
- DefKind :: Macro ( ..) => match self . kind ( child_index) {
1100
- EntryKind :: MacroDef ( _, macro_rules) => macro_rules,
1101
- _ => unreachable ! ( ) ,
1102
- } ,
1103
- _ => false ,
1104
- } ;
1105
-
1106
- callback ( ModChild { ident, res, vis, span, macro_rules } ) ;
1107
-
1108
- // For non-re-export structs and variants add their constructors to children.
1109
- // Re-export lists automatically contain constructors when necessary.
1110
- match kind {
1111
- DefKind :: Struct => {
1112
- if let Some ( ( ctor_def_id, ctor_kind) ) =
1113
- self . get_ctor_def_id_and_kind ( child_index)
1114
- {
1115
- let ctor_res =
1116
- Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ctor_kind) , ctor_def_id) ;
1117
- let vis = self . get_visibility ( ctor_def_id. index ) ;
1118
- callback ( ModChild {
1119
- ident,
1120
- res : ctor_res,
1121
- vis,
1122
- span,
1123
- macro_rules : false ,
1124
- } ) ;
1125
- }
1126
- }
1127
- DefKind :: Variant => {
1128
- // Braced variants, unlike structs, generate unusable names in
1129
- // value namespace, they are reserved for possible future use.
1130
- // It's ok to use the variant's id as a ctor id since an
1131
- // error will be reported on any use of such resolution anyway.
1132
- let ( ctor_def_id, ctor_kind) = self
1133
- . get_ctor_def_id_and_kind ( child_index)
1134
- . unwrap_or ( ( def_id, CtorKind :: Fictive ) ) ;
1092
+ let ident = self . item_ident ( child_index, sess) ;
1093
+ let kind = self . def_kind ( child_index) ;
1094
+ let def_id = self . local_def_id ( child_index) ;
1095
+ let res = Res :: Def ( kind, def_id) ;
1096
+ let vis = self . get_visibility ( child_index) ;
1097
+ let span = self . get_span ( child_index, sess) ;
1098
+ let macro_rules = match kind {
1099
+ DefKind :: Macro ( ..) => match self . kind ( child_index) {
1100
+ EntryKind :: MacroDef ( _, macro_rules) => macro_rules,
1101
+ _ => unreachable ! ( ) ,
1102
+ } ,
1103
+ _ => false ,
1104
+ } ;
1105
+
1106
+ callback ( ModChild { ident, res, vis, span, macro_rules } ) ;
1107
+
1108
+ // For non-re-export structs and variants add their constructors to children.
1109
+ // Re-export lists automatically contain constructors when necessary.
1110
+ match kind {
1111
+ DefKind :: Struct => {
1112
+ if let Some ( ( ctor_def_id, ctor_kind) ) =
1113
+ self . get_ctor_def_id_and_kind ( child_index)
1114
+ {
1135
1115
let ctor_res =
1136
- Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , ctor_kind) , ctor_def_id) ;
1137
- let mut vis = self . get_visibility ( ctor_def_id. index ) ;
1138
- if ctor_def_id == def_id && vis. is_public ( ) {
1139
- // For non-exhaustive variants lower the constructor visibility to
1140
- // within the crate. We only need this for fictive constructors,
1141
- // for other constructors correct visibilities
1142
- // were already encoded in metadata.
1143
- let mut attrs = self . get_item_attrs ( def_id. index , sess) ;
1144
- if attrs. any ( |item| item. has_name ( sym:: non_exhaustive) ) {
1145
- let crate_def_id = self . local_def_id ( CRATE_DEF_INDEX ) ;
1146
- vis = ty:: Visibility :: Restricted ( crate_def_id) ;
1147
- }
1148
- }
1116
+ Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ctor_kind) , ctor_def_id) ;
1117
+ let vis = self . get_visibility ( ctor_def_id. index ) ;
1149
1118
callback ( ModChild {
1150
1119
ident,
1151
1120
res : ctor_res,
@@ -1154,8 +1123,32 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1154
1123
macro_rules : false ,
1155
1124
} ) ;
1156
1125
}
1157
- _ => { }
1158
1126
}
1127
+ DefKind :: Variant => {
1128
+ // Braced variants, unlike structs, generate unusable names in
1129
+ // value namespace, they are reserved for possible future use.
1130
+ // It's ok to use the variant's id as a ctor id since an
1131
+ // error will be reported on any use of such resolution anyway.
1132
+ let ( ctor_def_id, ctor_kind) = self
1133
+ . get_ctor_def_id_and_kind ( child_index)
1134
+ . unwrap_or ( ( def_id, CtorKind :: Fictive ) ) ;
1135
+ let ctor_res =
1136
+ Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , ctor_kind) , ctor_def_id) ;
1137
+ let mut vis = self . get_visibility ( ctor_def_id. index ) ;
1138
+ if ctor_def_id == def_id && vis. is_public ( ) {
1139
+ // For non-exhaustive variants lower the constructor visibility to
1140
+ // within the crate. We only need this for fictive constructors,
1141
+ // for other constructors correct visibilities
1142
+ // were already encoded in metadata.
1143
+ let mut attrs = self . get_item_attrs ( def_id. index , sess) ;
1144
+ if attrs. any ( |item| item. has_name ( sym:: non_exhaustive) ) {
1145
+ let crate_def_id = self . local_def_id ( CRATE_DEF_INDEX ) ;
1146
+ vis = ty:: Visibility :: Restricted ( crate_def_id) ;
1147
+ }
1148
+ }
1149
+ callback ( ModChild { ident, res : ctor_res, vis, span, macro_rules : false } ) ;
1150
+ }
1151
+ _ => { }
1159
1152
}
1160
1153
}
1161
1154
}
0 commit comments