@@ -119,8 +119,7 @@ fn find_path_inner(
119119
120120 // - if the item is the crate root, return `crate`
121121 let root = def_map. crate_root ( db) ;
122- if item == ItemInNs :: Types ( ModuleDefId :: ModuleId ( root) ) && def_map. block_id ( ) . is_none ( ) {
123- // FIXME: the `block_id()` check should be unnecessary, but affects the result
122+ if item == ItemInNs :: Types ( ModuleDefId :: ModuleId ( root) ) {
124123 return Some ( ModPath :: from_segments ( PathKind :: Crate , Vec :: new ( ) ) ) ;
125124 }
126125
@@ -131,7 +130,7 @@ fn find_path_inner(
131130 }
132131
133132 // - if the item is the crate root of a dependency crate, return the name from the extern prelude
134- for ( name, def_id) in def_map. extern_prelude ( ) {
133+ for ( name, def_id) in root . def_map ( db ) . extern_prelude ( ) {
135134 if item == ItemInNs :: Types ( * def_id) {
136135 let name = scope_name. unwrap_or_else ( || name. clone ( ) ) ;
137136 return Some ( ModPath :: from_segments ( PathKind :: Plain , vec ! [ name] ) ) ;
@@ -298,6 +297,7 @@ fn find_local_import_locations(
298297 let data = & def_map[ from. local_id ] ;
299298 let mut worklist =
300299 data. children . values ( ) . map ( |child| def_map. module_id ( * child) ) . collect :: < Vec < _ > > ( ) ;
300+ // FIXME: do we need to traverse out of block expressions here?
301301 for ancestor in iter:: successors ( from. containing_module ( db) , |m| m. containing_module ( db) ) {
302302 worklist. push ( ancestor) ;
303303 }
@@ -947,10 +947,11 @@ fn main() {
947947 $0
948948}
949949 "# ,
950+ // FIXME: these could use fewer/better prefixes
950951 "module::CompleteMe" ,
951- "module::CompleteMe" ,
952952 "crate::module::CompleteMe" ,
953- "self::module::CompleteMe" ,
953+ "crate::module::CompleteMe" ,
954+ "crate::module::CompleteMe" ,
954955 )
955956 }
956957
@@ -977,6 +978,28 @@ mod bar {
977978 )
978979 }
979980
981+ #[ test]
982+ fn from_inside_module_with_inner_items ( ) {
983+ check_found_path (
984+ r#"
985+ mod baz {
986+ pub struct Foo {}
987+ }
988+
989+ mod bar {
990+ fn bar() {
991+ fn inner() {}
992+ $0
993+ }
994+ }
995+ "# ,
996+ "crate::baz::Foo" ,
997+ "crate::baz::Foo" ,
998+ "crate::baz::Foo" ,
999+ "crate::baz::Foo" ,
1000+ )
1001+ }
1002+
9801003 #[ test]
9811004 fn recursive_pub_mod_reexport ( ) {
9821005 cov_mark:: check!( recursive_imports) ;
@@ -1004,4 +1027,34 @@ pub mod name {
10041027 "self::name::AsName" ,
10051028 ) ;
10061029 }
1030+
1031+ #[ test]
1032+ fn extern_crate ( ) {
1033+ check_found_path (
1034+ r#"
1035+ //- /main.rs crate:main deps:dep
1036+ $0
1037+ //- /dep.rs crate:dep
1038+ "# ,
1039+ "dep" ,
1040+ "dep" ,
1041+ "dep" ,
1042+ "dep" ,
1043+ ) ;
1044+
1045+ check_found_path (
1046+ r#"
1047+ //- /main.rs crate:main deps:dep
1048+ fn f() {
1049+ fn inner() {}
1050+ $0
1051+ }
1052+ //- /dep.rs crate:dep
1053+ "# ,
1054+ "dep" ,
1055+ "dep" ,
1056+ "dep" ,
1057+ "dep" ,
1058+ ) ;
1059+ }
10071060}
0 commit comments