@@ -162,11 +162,28 @@ fn find_refs_in_mod(
162
162
module : Module ,
163
163
visible_from : Option < Module > ,
164
164
) -> Option < Refs > {
165
+ if let Some ( from) = visible_from {
166
+ if !is_mod_visible_from ( ctx, module, from) {
167
+ return None ;
168
+ }
169
+ }
170
+
165
171
let module_scope = module. scope ( ctx. db ( ) , visible_from) ;
166
172
let refs = module_scope. into_iter ( ) . filter_map ( |( n, d) | Ref :: from_scope_def ( n, d) ) . collect ( ) ;
167
173
Some ( Refs ( refs) )
168
174
}
169
175
176
+ fn is_mod_visible_from ( ctx : & AssistContext , module : Module , from : Module ) -> bool {
177
+ match module. parent ( ctx. db ( ) ) {
178
+ Some ( parent) => {
179
+ parent. visibility_of ( ctx. db ( ) , & ModuleDef :: Module ( module) ) . map_or ( true , |vis| {
180
+ vis. is_visible_from ( ctx. db ( ) , from. into ( ) ) && is_mod_visible_from ( ctx, parent, from)
181
+ } )
182
+ }
183
+ None => true ,
184
+ }
185
+ }
186
+
170
187
// looks for name refs in parent use block's siblings
171
188
//
172
189
// mod bar {
@@ -815,6 +832,41 @@ fn main() {
815
832
) ;
816
833
}
817
834
835
+ #[ test]
836
+ fn expanding_is_not_applicable_if_target_module_is_not_accessible_from_current_scope ( ) {
837
+ check_assist_not_applicable (
838
+ expand_glob_import,
839
+ r"
840
+ mod foo {
841
+ mod bar {
842
+ pub struct Bar;
843
+ }
844
+ }
845
+
846
+ use foo::bar::*<|>;
847
+
848
+ fn baz(bar: Bar) {}
849
+ " ,
850
+ ) ;
851
+
852
+ check_assist_not_applicable (
853
+ expand_glob_import,
854
+ r"
855
+ mod foo {
856
+ mod bar {
857
+ pub mod baz {
858
+ pub struct Baz;
859
+ }
860
+ }
861
+ }
862
+
863
+ use foo::bar::baz::*<|>;
864
+
865
+ fn qux(baz: Baz) {}
866
+ " ,
867
+ ) ;
868
+ }
869
+
818
870
#[ test]
819
871
fn expanding_is_not_applicable_if_cursor_is_not_in_star_token ( ) {
820
872
check_assist_not_applicable (
0 commit comments