@@ -85,7 +85,7 @@ macro_rules! ast_fragments {
8585 // mention some macro variable from those arguments even if it's not used.
8686 #[ cfg_attr( bootstrap, allow( unused_macros) ) ]
8787 macro _repeating( $flat_map_ast_elt) { }
88- placeholder( AstFragmentKind :: $Kind, * id) . $make_ast( )
88+ placeholder( AstFragmentKind :: $Kind, * id, None ) . $make_ast( )
8989 } ) ) , ) ?) *
9090 _ => panic!( "unexpected AST fragment kind" )
9191 }
@@ -274,6 +274,23 @@ pub enum InvocationKind {
274274 } ,
275275}
276276
277+ impl InvocationKind {
278+ fn placeholder_visibility ( & self ) -> Option < ast:: Visibility > {
279+ // HACK: For unnamed fields placeholders should have the same visibility as the actual
280+ // fields because for tuple structs/variants resolve determines visibilities of their
281+ // constructor using these field visibilities before attributes on them are are expanded.
282+ // The assumption is that the attribute expansion cannot change field visibilities,
283+ // and it holds because only inert attributes are supported in this position.
284+ match self {
285+ InvocationKind :: Attr { item : Annotatable :: StructField ( field) , .. } |
286+ InvocationKind :: Derive { item : Annotatable :: StructField ( field) , .. } |
287+ InvocationKind :: DeriveContainer { item : Annotatable :: StructField ( field) , .. }
288+ if field. ident . is_none ( ) => Some ( field. vis . clone ( ) ) ,
289+ _ => None ,
290+ }
291+ }
292+ }
293+
277294impl Invocation {
278295 pub fn span ( & self ) -> Span {
279296 match & self . kind {
@@ -941,6 +958,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
941958 _ => None ,
942959 } ;
943960 let expn_id = ExpnId :: fresh ( expn_data) ;
961+ let vis = kind. placeholder_visibility ( ) ;
944962 self . invocations . push ( Invocation {
945963 kind,
946964 fragment_kind,
@@ -950,7 +968,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
950968 ..self . cx . current_expansion . clone ( )
951969 } ,
952970 } ) ;
953- placeholder ( fragment_kind, NodeId :: placeholder_from_expn_id ( expn_id) )
971+ placeholder ( fragment_kind, NodeId :: placeholder_from_expn_id ( expn_id) , vis )
954972 }
955973
956974 fn collect_bang ( & mut self , mac : ast:: Mac , span : Span , kind : AstFragmentKind ) -> AstFragment {
0 commit comments