@@ -86,7 +86,7 @@ macro_rules! ast_fragments {
86
86
// mention some macro variable from those arguments even if it's not used.
87
87
#[ cfg_attr( bootstrap, allow( unused_macros) ) ]
88
88
macro _repeating( $flat_map_ast_elt) { }
89
- placeholder( AstFragmentKind :: $Kind, * id) . $make_ast( )
89
+ placeholder( AstFragmentKind :: $Kind, * id, None ) . $make_ast( )
90
90
} ) ) , ) ?) *
91
91
_ => panic!( "unexpected AST fragment kind" )
92
92
}
@@ -275,6 +275,23 @@ pub enum InvocationKind {
275
275
} ,
276
276
}
277
277
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
+
278
295
impl Invocation {
279
296
pub fn span ( & self ) -> Span {
280
297
match & self . kind {
@@ -931,6 +948,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
931
948
_ => None ,
932
949
} ;
933
950
let expn_id = ExpnId :: fresh ( expn_data) ;
951
+ let vis = kind. placeholder_visibility ( ) ;
934
952
self . invocations . push ( Invocation {
935
953
kind,
936
954
fragment_kind,
@@ -940,7 +958,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
940
958
..self . cx . current_expansion . clone ( )
941
959
} ,
942
960
} ) ;
943
- placeholder ( fragment_kind, NodeId :: placeholder_from_expn_id ( expn_id) )
961
+ placeholder ( fragment_kind, NodeId :: placeholder_from_expn_id ( expn_id) , vis )
944
962
}
945
963
946
964
fn collect_bang ( & mut self , mac : ast:: Mac , span : Span , kind : AstFragmentKind ) -> AstFragment {
0 commit comments