11use crate :: graph:: CrateId ;
2- use crate :: node_interner:: { FuncId , NodeInterner , StructId } ;
2+ use crate :: node_interner:: { FuncId , NodeInterner , StructId , TraitId } ;
33use crate :: Type ;
44
55use std:: collections:: BTreeMap ;
@@ -79,26 +79,47 @@ pub fn struct_member_is_visible(
7979 visibility : ItemVisibility ,
8080 current_module_id : ModuleId ,
8181 def_maps : & BTreeMap < CrateId , CrateDefMap > ,
82+ ) -> bool {
83+ type_member_is_visible ( struct_id. module_id ( ) , visibility, current_module_id, def_maps)
84+ }
85+
86+ pub fn trait_member_is_visible (
87+ trait_id : TraitId ,
88+ visibility : ItemVisibility ,
89+ current_module_id : ModuleId ,
90+ def_maps : & BTreeMap < CrateId , CrateDefMap > ,
91+ ) -> bool {
92+ type_member_is_visible ( trait_id. 0 , visibility, current_module_id, def_maps)
93+ }
94+
95+ fn type_member_is_visible (
96+ type_module_id : ModuleId ,
97+ visibility : ItemVisibility ,
98+ current_module_id : ModuleId ,
99+ def_maps : & BTreeMap < CrateId , CrateDefMap > ,
82100) -> bool {
83101 match visibility {
84102 ItemVisibility :: Public => true ,
85103 ItemVisibility :: PublicCrate => {
86- struct_id. parent_module_id ( def_maps) . krate == current_module_id. krate
104+ let type_parent_module_id =
105+ type_module_id. parent ( def_maps) . expect ( "Expected parent module to exist" ) ;
106+ type_parent_module_id. krate == current_module_id. krate
87107 }
88108 ItemVisibility :: Private => {
89- let struct_parent_module_id = struct_id. parent_module_id ( def_maps) ;
90- if struct_parent_module_id. krate != current_module_id. krate {
109+ let type_parent_module_id =
110+ type_module_id. parent ( def_maps) . expect ( "Expected parent module to exist" ) ;
111+ if type_parent_module_id. krate != current_module_id. krate {
91112 return false ;
92113 }
93114
94- if struct_parent_module_id . local_id == current_module_id. local_id {
115+ if type_parent_module_id . local_id == current_module_id. local_id {
95116 return true ;
96117 }
97118
98119 let def_map = & def_maps[ & current_module_id. krate ] ;
99120 module_descendent_of_target (
100121 def_map,
101- struct_parent_module_id . local_id ,
122+ type_parent_module_id . local_id ,
102123 current_module_id. local_id ,
103124 )
104125 }
@@ -115,35 +136,37 @@ pub fn method_call_is_visible(
115136 let modifiers = interner. function_modifiers ( & func_id) ;
116137 match modifiers. visibility {
117138 ItemVisibility :: Public => true ,
118- ItemVisibility :: PublicCrate => {
119- if object_type. is_primitive ( ) {
120- current_module. krate . is_stdlib ( )
121- } else {
122- interner. function_module ( func_id) . krate == current_module. krate
139+ ItemVisibility :: PublicCrate | ItemVisibility :: Private => {
140+ let func_meta = interner. function_meta ( & func_id) ;
141+ if let Some ( struct_id) = func_meta. struct_id {
142+ return struct_member_is_visible (
143+ struct_id,
144+ modifiers. visibility ,
145+ current_module,
146+ def_maps,
147+ ) ;
123148 }
124- }
125- ItemVisibility :: Private => {
149+
150+ if let Some ( trait_id) = func_meta. trait_id {
151+ return trait_member_is_visible (
152+ trait_id,
153+ modifiers. visibility ,
154+ current_module,
155+ def_maps,
156+ ) ;
157+ }
158+
126159 if object_type. is_primitive ( ) {
127160 let func_module = interner. function_module ( func_id) ;
128- item_in_module_is_visible (
161+ return item_in_module_is_visible (
129162 def_maps,
130163 current_module,
131164 func_module,
132165 modifiers. visibility ,
133- )
134- } else {
135- let func_meta = interner. function_meta ( & func_id) ;
136- if let Some ( struct_id) = func_meta. struct_id {
137- struct_member_is_visible (
138- struct_id,
139- modifiers. visibility ,
140- current_module,
141- def_maps,
142- )
143- } else {
144- true
145- }
166+ ) ;
146167 }
168+
169+ true
147170 }
148171 }
149172}
0 commit comments