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