@@ -34,7 +34,8 @@ pub struct FunctionData {
3434
3535impl FunctionData {
3636 pub ( crate ) fn fn_data_query ( db : & impl DefDatabase , func : FunctionId ) -> Arc < FunctionData > {
37- let src = func. lookup ( db) . source ( db) ;
37+ let loc = func. lookup ( db) ;
38+ let src = loc. source ( db) ;
3839 let name = src. value . name ( ) . map ( |n| n. as_name ( ) ) . unwrap_or_else ( Name :: missing) ;
3940 let mut params = Vec :: new ( ) ;
4041 let mut has_self_param = false ;
@@ -76,7 +77,9 @@ impl FunctionData {
7677 ret_type
7778 } ;
7879
79- let visibility = RawVisibility :: from_ast ( db, src. map ( |s| s. visibility ( ) ) ) ;
80+ let vis_default = RawVisibility :: default_for_container ( loc. container ) ;
81+ let visibility =
82+ RawVisibility :: from_ast_with_default ( db, vis_default, src. map ( |s| s. visibility ( ) ) ) ;
8083
8184 let sig = FunctionData { name, params, ret_type, has_self_param, visibility } ;
8285 Arc :: new ( sig)
@@ -105,10 +108,13 @@ impl TypeAliasData {
105108 db : & impl DefDatabase ,
106109 typ : TypeAliasId ,
107110 ) -> Arc < TypeAliasData > {
108- let node = typ. lookup ( db) . source ( db) ;
111+ let loc = typ. lookup ( db) ;
112+ let node = loc. source ( db) ;
109113 let name = node. value . name ( ) . map_or_else ( Name :: missing, |n| n. as_name ( ) ) ;
110114 let type_ref = node. value . type_ref ( ) . map ( TypeRef :: from_ast) ;
111- let visibility = RawVisibility :: from_ast ( db, node. map ( |n| n. visibility ( ) ) ) ;
115+ let vis_default = RawVisibility :: default_for_container ( loc. container ) ;
116+ let visibility =
117+ RawVisibility :: from_ast_with_default ( db, vis_default, node. map ( |n| n. visibility ( ) ) ) ;
112118 Arc :: new ( TypeAliasData { name, type_ref, visibility } )
113119 }
114120}
@@ -230,22 +236,26 @@ pub struct ConstData {
230236
231237impl ConstData {
232238 pub ( crate ) fn const_data_query ( db : & impl DefDatabase , konst : ConstId ) -> Arc < ConstData > {
233- let node = konst. lookup ( db) . source ( db) ;
234- Arc :: new ( ConstData :: new ( db, node) )
239+ let loc = konst. lookup ( db) ;
240+ let node = loc. source ( db) ;
241+ let vis_default = RawVisibility :: default_for_container ( loc. container ) ;
242+ Arc :: new ( ConstData :: new ( db, vis_default, node) )
235243 }
236244
237245 pub ( crate ) fn static_data_query ( db : & impl DefDatabase , konst : StaticId ) -> Arc < ConstData > {
238246 let node = konst. lookup ( db) . source ( db) ;
239- Arc :: new ( ConstData :: new ( db, node) )
247+ Arc :: new ( ConstData :: new ( db, RawVisibility :: private ( ) , node) )
240248 }
241249
242250 fn new < N : NameOwner + TypeAscriptionOwner + VisibilityOwner > (
243251 db : & impl DefDatabase ,
252+ vis_default : RawVisibility ,
244253 node : InFile < N > ,
245254 ) -> ConstData {
246255 let name = node. value . name ( ) . map ( |n| n. as_name ( ) ) ;
247256 let type_ref = TypeRef :: from_ast_opt ( node. value . ascribed_type ( ) ) ;
248- let visibility = RawVisibility :: from_ast ( db, node. map ( |n| n. visibility ( ) ) ) ;
257+ let visibility =
258+ RawVisibility :: from_ast_with_default ( db, vis_default, node. map ( |n| n. visibility ( ) ) ) ;
249259 ConstData { name, type_ref, visibility }
250260 }
251261}
0 commit comments