@@ -194,6 +194,14 @@ impl<'a> AsMut<Resolver<'a>> for BuildReducedGraphVisitor<'a, '_> {
194194
195195impl < ' a , ' b > BuildReducedGraphVisitor < ' a , ' b > {
196196 fn resolve_visibility ( & mut self , vis : & ast:: Visibility ) -> ty:: Visibility {
197+ self . resolve_visibility_speculative ( vis, false )
198+ }
199+
200+ fn resolve_visibility_speculative (
201+ & mut self ,
202+ vis : & ast:: Visibility ,
203+ speculative : bool ,
204+ ) -> ty:: Visibility {
197205 let parent_scope = & self . parent_scope ;
198206 match vis. node {
199207 ast:: VisibilityKind :: Public => ty:: Visibility :: Public ,
@@ -241,13 +249,15 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
241249 & segments,
242250 Some ( TypeNS ) ,
243251 parent_scope,
244- true ,
252+ !speculative ,
245253 path. span ,
246254 CrateLint :: SimplePath ( id) ,
247255 ) {
248256 PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) => {
249257 let res = module. res ( ) . expect ( "visibility resolved to unnamed block" ) ;
250- self . r . record_partial_res ( id, PartialRes :: new ( res) ) ;
258+ if !speculative {
259+ self . r . record_partial_res ( id, PartialRes :: new ( res) ) ;
260+ }
251261 if module. is_normal ( ) {
252262 if res == Res :: Err {
253263 ty:: Visibility :: Public
@@ -742,7 +752,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
742752
743753 // Record field names for error reporting.
744754 let field_names = struct_def. fields ( ) . iter ( ) . map ( |field| {
745- let field_vis = self . resolve_visibility ( & field. vis ) ;
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_speculative ( & field. vis , true ) ;
746759 if ctor_vis. is_at_least ( field_vis, & * self . r ) {
747760 ctor_vis = field_vis;
748761 }
@@ -769,7 +782,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
769782
770783 // Record field names for error reporting.
771784 let field_names = vdata. fields ( ) . iter ( ) . map ( |field| {
772- self . resolve_visibility ( & field. vis ) ;
773785 respan ( field. span , field. ident . map_or ( kw:: Invalid , |ident| ident. name ) )
774786 } ) . collect ( ) ;
775787 let item_def_id = self . r . definitions . local_def_id ( item. id ) ;
@@ -1279,6 +1291,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
12791291 if sf. is_placeholder {
12801292 self . visit_invoc ( sf. id ) ;
12811293 } else {
1294+ self . resolve_visibility ( & sf. vis ) ;
12821295 visit:: walk_struct_field ( self , sf) ;
12831296 }
12841297 }
0 commit comments