@@ -225,7 +225,7 @@ fn def_id_visibility<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
225
225
let vis = match tcx. hir ( ) . get_by_hir_id ( hir_id) {
226
226
Node :: Item ( item) => & item. vis ,
227
227
Node :: ForeignItem ( foreign_item) => & foreign_item. vis ,
228
- Node :: TraitItem ( ..) | Node :: Variant ( ..) | Node :: Ctor ( hir :: CtorOf :: Variant , .. ) => {
228
+ Node :: TraitItem ( ..) | Node :: Variant ( ..) => {
229
229
return def_id_visibility ( tcx, tcx. hir ( ) . get_parent_did_by_hir_id ( hir_id) ) ;
230
230
}
231
231
Node :: ImplItem ( impl_item) => {
@@ -239,36 +239,48 @@ fn def_id_visibility<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
239
239
node => bug ! ( "unexpected node kind: {:?}" , node) ,
240
240
}
241
241
}
242
- Node :: Ctor ( hir:: CtorOf :: Struct , vdata) => {
243
- let struct_hir_id = tcx. hir ( ) . get_parent_item ( hir_id) ;
244
- let item = match tcx. hir ( ) . get_by_hir_id ( struct_hir_id) {
245
- Node :: Item ( item) => item,
246
- node => bug ! ( "unexpected node kind: {:?}" , node) ,
247
- } ;
248
- let ( mut ctor_vis, mut span, mut descr) =
249
- ( ty:: Visibility :: from_hir ( & item. vis , struct_hir_id, tcx) ,
250
- item. vis . span , item. vis . node . descr ( ) ) ;
251
- for field in vdata. fields ( ) {
252
- let field_vis = ty:: Visibility :: from_hir ( & field. vis , hir_id, tcx) ;
253
- if ctor_vis. is_at_least ( field_vis, tcx) {
254
- ctor_vis = field_vis;
255
- span = field. vis . span ;
256
- descr = field. vis . node . descr ( ) ;
242
+ Node :: Ctor ( vdata) => {
243
+ let parent_hir_id = tcx. hir ( ) . get_parent_node_by_hir_id ( hir_id) ;
244
+ match tcx. hir ( ) . get_by_hir_id ( parent_hir_id) {
245
+ Node :: Variant ( ..) => {
246
+ let parent_did = tcx. hir ( ) . local_def_id_from_hir_id ( parent_hir_id) ;
247
+ return def_id_visibility ( tcx, parent_did) ;
257
248
}
258
- }
249
+ Node :: Item ( ..) => {
250
+ let item = match tcx. hir ( ) . get_by_hir_id ( parent_hir_id) {
251
+ Node :: Item ( item) => item,
252
+ node => bug ! ( "unexpected node kind: {:?}" , node) ,
253
+ } ;
254
+ let ( mut ctor_vis, mut span, mut descr) =
255
+ ( ty:: Visibility :: from_hir ( & item. vis , parent_hir_id, tcx) ,
256
+ item. vis . span , item. vis . node . descr ( ) ) ;
257
+ for field in vdata. fields ( ) {
258
+ let field_vis = ty:: Visibility :: from_hir ( & field. vis , hir_id, tcx) ;
259
+ if ctor_vis. is_at_least ( field_vis, tcx) {
260
+ ctor_vis = field_vis;
261
+ span = field. vis . span ;
262
+ descr = field. vis . node . descr ( ) ;
263
+ }
264
+ }
259
265
260
- // If the structure is marked as non_exhaustive then lower the
261
- // visibility to within the crate.
262
- if ctor_vis == ty:: Visibility :: Public {
263
- let adt_def = tcx. adt_def ( tcx. hir ( ) . get_parent_did_by_hir_id ( hir_id) ) ;
264
- if adt_def. non_enum_variant ( ) . is_field_list_non_exhaustive ( ) {
265
- ctor_vis = ty:: Visibility :: Restricted ( DefId :: local ( CRATE_DEF_INDEX ) ) ;
266
- span = attr:: find_by_name ( & item. attrs , "non_exhaustive" ) . unwrap ( ) . span ;
267
- descr = "crate-visible" ;
266
+ // If the structure is marked as non_exhaustive then lower the
267
+ // visibility to within the crate.
268
+ if ctor_vis == ty:: Visibility :: Public {
269
+ let adt_def =
270
+ tcx. adt_def ( tcx. hir ( ) . get_parent_did_by_hir_id ( hir_id) ) ;
271
+ if adt_def. non_enum_variant ( ) . is_field_list_non_exhaustive ( ) {
272
+ ctor_vis =
273
+ ty:: Visibility :: Restricted ( DefId :: local ( CRATE_DEF_INDEX ) ) ;
274
+ span = attr:: find_by_name ( & item. attrs , "non_exhaustive" )
275
+ . unwrap ( ) . span ;
276
+ descr = "crate-visible" ;
277
+ }
278
+ }
279
+
280
+ return ( ctor_vis, span, descr) ;
268
281
}
282
+ node => bug ! ( "unexpected node kind: {:?}" , node) ,
269
283
}
270
-
271
- return ( ctor_vis, span, descr) ;
272
284
}
273
285
Node :: Expr ( expr) => {
274
286
return ( ty:: Visibility :: Restricted (
0 commit comments