@@ -301,6 +301,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
301
301
}
302
302
}
303
303
304
+ fn insert_field_names_local ( & mut self , def_id : DefId , vdata : & ast:: VariantData ) {
305
+ let field_names = vdata. fields ( ) . iter ( ) . map ( |field| {
306
+ respan ( field. span , field. ident . map_or ( kw:: Invalid , |ident| ident. name ) )
307
+ } ) . collect ( ) ;
308
+ self . insert_field_names ( def_id, field_names) ;
309
+ }
310
+
304
311
fn insert_field_names ( & mut self , def_id : DefId , field_names : Vec < Spanned < Name > > ) {
305
312
if !field_names. is_empty ( ) {
306
313
self . r . field_names . insert ( def_id, field_names) ;
@@ -734,58 +741,50 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
734
741
}
735
742
736
743
// These items live in both the type and value namespaces.
737
- ItemKind :: Struct ( ref struct_def , _) => {
744
+ ItemKind :: Struct ( ref vdata , _) => {
738
745
// Define a name in the type namespace.
739
746
let def_id = self . r . definitions . local_def_id ( item. id ) ;
740
747
let res = Res :: Def ( DefKind :: Struct , def_id) ;
741
748
self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
742
749
743
- let mut ctor_vis = vis;
744
-
745
- let has_non_exhaustive = attr:: contains_name ( & item. attrs , sym:: non_exhaustive) ;
746
-
747
- // If the structure is marked as non_exhaustive then lower the visibility
748
- // to within the crate.
749
- if has_non_exhaustive && vis == ty:: Visibility :: Public {
750
- ctor_vis = ty:: Visibility :: Restricted ( DefId :: local ( CRATE_DEF_INDEX ) ) ;
751
- }
752
-
753
750
// Record field names for error reporting.
754
- let field_names = struct_def. fields ( ) . iter ( ) . map ( |field| {
755
- // NOTE: The field may be an expansion placeholder, but expansion sets correct
756
- // visibilities for unnamed field placeholders specifically, so the constructor
757
- // visibility should still be determined correctly.
758
- let field_vis = self . resolve_visibility ( & field. vis ) ;
759
- if ctor_vis. is_at_least ( field_vis, & * self . r ) {
760
- ctor_vis = field_vis;
761
- }
762
- respan ( field. span , field. ident . map_or ( kw:: Invalid , |ident| ident. name ) )
763
- } ) . collect ( ) ;
764
- let item_def_id = self . r . definitions . local_def_id ( item. id ) ;
765
- self . insert_field_names ( item_def_id, field_names) ;
751
+ self . insert_field_names_local ( def_id, vdata) ;
766
752
767
753
// If this is a tuple or unit struct, define a name
768
754
// in the value namespace as well.
769
- if let Some ( ctor_node_id) = struct_def. ctor_id ( ) {
755
+ if let Some ( ctor_node_id) = vdata. ctor_id ( ) {
756
+ let mut ctor_vis = vis;
757
+ // If the structure is marked as non_exhaustive then lower the visibility
758
+ // to within the crate.
759
+ if vis == ty:: Visibility :: Public &&
760
+ attr:: contains_name ( & item. attrs , sym:: non_exhaustive) {
761
+ ctor_vis = ty:: Visibility :: Restricted ( DefId :: local ( CRATE_DEF_INDEX ) ) ;
762
+ }
763
+ for field in vdata. fields ( ) {
764
+ // NOTE: The field may be an expansion placeholder, but expansion sets
765
+ // correct visibilities for unnamed field placeholders specifically, so the
766
+ // constructor visibility should still be determined correctly.
767
+ let field_vis = self . resolve_visibility_speculative ( & field. vis , true ) ;
768
+ if ctor_vis. is_at_least ( field_vis, & * self . r ) {
769
+ ctor_vis = field_vis;
770
+ }
771
+ }
770
772
let ctor_res = Res :: Def (
771
- DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: from_ast ( struct_def ) ) ,
773
+ DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: from_ast ( vdata ) ) ,
772
774
self . r . definitions . local_def_id ( ctor_node_id) ,
773
775
) ;
774
776
self . r . define ( parent, ident, ValueNS , ( ctor_res, ctor_vis, sp, expansion) ) ;
775
- self . r . struct_constructors . insert ( res . def_id ( ) , ( ctor_res, ctor_vis) ) ;
777
+ self . r . struct_constructors . insert ( def_id, ( ctor_res, ctor_vis) ) ;
776
778
}
777
779
}
778
780
779
781
ItemKind :: Union ( ref vdata, _) => {
780
- let res = Res :: Def ( DefKind :: Union , self . r . definitions . local_def_id ( item. id ) ) ;
782
+ let def_id = self . r . definitions . local_def_id ( item. id ) ;
783
+ let res = Res :: Def ( DefKind :: Union , def_id) ;
781
784
self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
782
785
783
786
// Record field names for error reporting.
784
- let field_names = vdata. fields ( ) . iter ( ) . map ( |field| {
785
- respan ( field. span , field. ident . map_or ( kw:: Invalid , |ident| ident. name ) )
786
- } ) . collect ( ) ;
787
- let item_def_id = self . r . definitions . local_def_id ( item. id ) ;
788
- self . insert_field_names ( item_def_id, field_names) ;
787
+ self . insert_field_names_local ( def_id, vdata) ;
789
788
}
790
789
791
790
ItemKind :: Trait ( ..) => {
0 commit comments