@@ -14,7 +14,7 @@ use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree};
1414use crate :: {
1515 body:: { CfgExpander , LowerCtx } ,
1616 db:: DefDatabase ,
17- item_tree:: { AttrOwner , Field , Fields , ItemTree , ModItem } ,
17+ item_tree:: { AttrOwner , Field , Fields , ItemTree , ModItem , RawVisibilityId } ,
1818 src:: HasChildSource ,
1919 src:: HasSource ,
2020 trace:: Trace ,
@@ -91,7 +91,7 @@ impl StructData {
9191 let cfg_options = db. crate_graph ( ) [ loc. container . module ( db) . krate ] . cfg_options . clone ( ) ;
9292
9393 let strukt = & item_tree[ loc. id . value ] ;
94- let variant_data = lower_fields ( & item_tree, & cfg_options, & strukt. fields ) ;
94+ let variant_data = lower_fields ( & item_tree, & cfg_options, & strukt. fields , None ) ;
9595 Arc :: new ( StructData {
9696 name : strukt. name . clone ( ) ,
9797 variant_data : Arc :: new ( variant_data) ,
@@ -105,7 +105,7 @@ impl StructData {
105105 let cfg_options = db. crate_graph ( ) [ loc. container . module ( db) . krate ] . cfg_options . clone ( ) ;
106106
107107 let union = & item_tree[ loc. id . value ] ;
108- let variant_data = lower_fields ( & item_tree, & cfg_options, & union. fields ) ;
108+ let variant_data = lower_fields ( & item_tree, & cfg_options, & union. fields , None ) ;
109109
110110 Arc :: new ( StructData {
111111 name : union. name . clone ( ) ,
@@ -126,7 +126,8 @@ impl EnumData {
126126 for var_id in enum_. variants . clone ( ) {
127127 if item_tree. attrs ( var_id. into ( ) ) . is_cfg_enabled ( & cfg_options) {
128128 let var = & item_tree[ var_id] ;
129- let var_data = lower_fields ( & item_tree, & cfg_options, & var. fields ) ;
129+ let var_data =
130+ lower_fields ( & item_tree, & cfg_options, & var. fields , Some ( enum_. visibility ) ) ;
130131
131132 variants. alloc ( EnumVariantData {
132133 name : var. name . clone ( ) ,
@@ -296,13 +297,18 @@ fn lower_struct(
296297 }
297298}
298299
299- fn lower_fields ( item_tree : & ItemTree , cfg_options : & CfgOptions , fields : & Fields ) -> VariantData {
300+ fn lower_fields (
301+ item_tree : & ItemTree ,
302+ cfg_options : & CfgOptions ,
303+ fields : & Fields ,
304+ override_visibility : Option < RawVisibilityId > ,
305+ ) -> VariantData {
300306 match fields {
301307 Fields :: Record ( flds) => {
302308 let mut arena = Arena :: new ( ) ;
303309 for field_id in flds. clone ( ) {
304310 if item_tree. attrs ( field_id. into ( ) ) . is_cfg_enabled ( cfg_options) {
305- arena. alloc ( lower_field ( item_tree, & item_tree[ field_id] ) ) ;
311+ arena. alloc ( lower_field ( item_tree, & item_tree[ field_id] , override_visibility ) ) ;
306312 }
307313 }
308314 VariantData :: Record ( arena)
@@ -311,7 +317,7 @@ fn lower_fields(item_tree: &ItemTree, cfg_options: &CfgOptions, fields: &Fields)
311317 let mut arena = Arena :: new ( ) ;
312318 for field_id in flds. clone ( ) {
313319 if item_tree. attrs ( field_id. into ( ) ) . is_cfg_enabled ( cfg_options) {
314- arena. alloc ( lower_field ( item_tree, & item_tree[ field_id] ) ) ;
320+ arena. alloc ( lower_field ( item_tree, & item_tree[ field_id] , override_visibility ) ) ;
315321 }
316322 }
317323 VariantData :: Tuple ( arena)
@@ -320,10 +326,14 @@ fn lower_fields(item_tree: &ItemTree, cfg_options: &CfgOptions, fields: &Fields)
320326 }
321327}
322328
323- fn lower_field ( item_tree : & ItemTree , field : & Field ) -> FieldData {
329+ fn lower_field (
330+ item_tree : & ItemTree ,
331+ field : & Field ,
332+ override_visibility : Option < RawVisibilityId > ,
333+ ) -> FieldData {
324334 FieldData {
325335 name : field. name . clone ( ) ,
326336 type_ref : field. type_ref . clone ( ) ,
327- visibility : item_tree[ field. visibility ] . clone ( ) ,
337+ visibility : item_tree[ override_visibility . unwrap_or ( field. visibility ) ] . clone ( ) ,
328338 }
329339}
0 commit comments