@@ -11,7 +11,7 @@ use crate::{
1111 nameres:: DefMap ,
1212 path:: { ModPath , PathKind } ,
1313 visibility:: Visibility ,
14- ModuleDefId , ModuleId ,
14+ CrateRootModuleId , ModuleDefId , ModuleId ,
1515} ;
1616
1717/// Find a path that can be used to refer to a certain item. This can depend on
@@ -81,7 +81,7 @@ fn find_path_inner(
8181 }
8282
8383 let def_map = from. def_map ( db) ;
84- let crate_root = def_map. crate_root ( ) . into ( ) ;
84+ let crate_root = def_map. crate_root ( ) ;
8585 // - if the item is a module, jump straight to module search
8686 if let ItemInNs :: Types ( ModuleDefId :: ModuleId ( module_id) ) = item {
8787 let mut visited_modules = FxHashSet :: default ( ) ;
@@ -149,7 +149,7 @@ fn find_path_for_module(
149149 db : & dyn DefDatabase ,
150150 def_map : & DefMap ,
151151 visited_modules : & mut FxHashSet < ModuleId > ,
152- crate_root : ModuleId ,
152+ crate_root : CrateRootModuleId ,
153153 from : ModuleId ,
154154 module_id : ModuleId ,
155155 max_len : usize ,
@@ -183,7 +183,7 @@ fn find_path_for_module(
183183
184184 // - if the item is the crate root of a dependency crate, return the name from the extern prelude
185185 let root_def_map = crate_root. def_map ( db) ;
186- for ( name, def_id) in root_def_map. extern_prelude ( ) {
186+ for ( name, ( def_id, _extern_crate ) ) in root_def_map. extern_prelude ( ) {
187187 if module_id == def_id {
188188 let name = scope_name. unwrap_or_else ( || name. clone ( ) ) ;
189189
@@ -192,7 +192,7 @@ fn find_path_for_module(
192192 def_map[ local_id]
193193 . scope
194194 . type_ ( & name)
195- . filter ( |& ( id, _) | id != ModuleDefId :: ModuleId ( def_id) )
195+ . filter ( |& ( id, _) | id != ModuleDefId :: ModuleId ( def_id. into ( ) ) )
196196 } )
197197 . is_some ( ) ;
198198 let kind = if name_already_occupied_in_type_ns {
@@ -224,6 +224,7 @@ fn find_path_for_module(
224224 )
225225}
226226
227+ // FIXME: Do we still need this now that we record import origins, and hence aliases?
227228fn find_in_scope (
228229 db : & dyn DefDatabase ,
229230 def_map : & DefMap ,
@@ -244,7 +245,7 @@ fn find_in_prelude(
244245 item : ItemInNs ,
245246 from : ModuleId ,
246247) -> Option < ModPath > {
247- let prelude_module = root_def_map. prelude ( ) ?;
248+ let ( prelude_module, _ ) = root_def_map. prelude ( ) ?;
248249 // Preludes in block DefMaps are ignored, only the crate DefMap is searched
249250 let prelude_def_map = prelude_module. def_map ( db) ;
250251 let prelude_scope = & prelude_def_map[ prelude_module. local_id ] . scope ;
@@ -293,7 +294,7 @@ fn calculate_best_path(
293294 db : & dyn DefDatabase ,
294295 def_map : & DefMap ,
295296 visited_modules : & mut FxHashSet < ModuleId > ,
296- crate_root : ModuleId ,
297+ crate_root : CrateRootModuleId ,
297298 max_len : usize ,
298299 item : ItemInNs ,
299300 from : ModuleId ,
@@ -346,6 +347,11 @@ fn calculate_best_path(
346347 let extern_paths = crate_graph[ from. krate ] . dependencies . iter ( ) . filter_map ( |dep| {
347348 let import_map = db. import_map ( dep. crate_id ) ;
348349 import_map. import_info_for ( item) . and_then ( |info| {
350+ if info. is_doc_hidden {
351+ // the item or import is `#[doc(hidden)]`, so skip it as it is in an external crate
352+ return None ;
353+ }
354+
349355 // Determine best path for containing module and append last segment from `info`.
350356 // FIXME: we should guide this to look up the path locally, or from the same crate again?
351357 let mut path = find_path_for_module (
@@ -1293,4 +1299,65 @@ pub mod prelude {
12931299 "None" ,
12941300 ) ;
12951301 }
1302+
1303+ #[ test]
1304+ fn different_crate_renamed_through_dep ( ) {
1305+ check_found_path (
1306+ r#"
1307+ //- /main.rs crate:main deps:intermediate
1308+ $0
1309+ //- /intermediate.rs crate:intermediate deps:std
1310+ pub extern crate std as std_renamed;
1311+ //- /std.rs crate:std
1312+ pub struct S;
1313+ "# ,
1314+ "intermediate::std_renamed::S" ,
1315+ "intermediate::std_renamed::S" ,
1316+ "intermediate::std_renamed::S" ,
1317+ "intermediate::std_renamed::S" ,
1318+ ) ;
1319+ }
1320+
1321+ #[ test]
1322+ fn different_crate_doc_hidden ( ) {
1323+ check_found_path (
1324+ r#"
1325+ //- /main.rs crate:main deps:intermediate
1326+ $0
1327+ //- /intermediate.rs crate:intermediate deps:std
1328+ #[doc(hidden)]
1329+ pub extern crate std;
1330+ pub extern crate std as longer;
1331+ //- /std.rs crate:std
1332+ pub struct S;
1333+ "# ,
1334+ "intermediate::longer::S" ,
1335+ "intermediate::longer::S" ,
1336+ "intermediate::longer::S" ,
1337+ "intermediate::longer::S" ,
1338+ ) ;
1339+ }
1340+
1341+ #[ test]
1342+ fn respect_doc_hidden ( ) {
1343+ check_found_path (
1344+ r#"
1345+ //- /main.rs crate:main deps:std,lazy_static
1346+ $0
1347+ //- /lazy_static.rs crate:lazy_static deps:core
1348+ #[doc(hidden)]
1349+ pub use core::ops::Deref as __Deref;
1350+ //- /std.rs crate:std deps:core
1351+ pub use core::ops;
1352+ //- /core.rs crate:core
1353+ pub mod ops {
1354+ pub trait Deref {}
1355+ }
1356+ "# ,
1357+ "std::ops::Deref" ,
1358+ "std::ops::Deref" ,
1359+ "std::ops::Deref" ,
1360+ "std::ops::Deref" ,
1361+ ) ;
1362+ }
12961363}
0 commit comments