@@ -11,7 +11,7 @@ use crate::{
11
11
nameres:: DefMap ,
12
12
path:: { ModPath , PathKind } ,
13
13
visibility:: Visibility ,
14
- ModuleDefId , ModuleId ,
14
+ CrateRootModuleId , ModuleDefId , ModuleId ,
15
15
} ;
16
16
17
17
/// 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(
81
81
}
82
82
83
83
let def_map = from. def_map ( db) ;
84
- let crate_root = def_map. crate_root ( ) . into ( ) ;
84
+ let crate_root = def_map. crate_root ( ) ;
85
85
// - if the item is a module, jump straight to module search
86
86
if let ItemInNs :: Types ( ModuleDefId :: ModuleId ( module_id) ) = item {
87
87
let mut visited_modules = FxHashSet :: default ( ) ;
@@ -149,7 +149,7 @@ fn find_path_for_module(
149
149
db : & dyn DefDatabase ,
150
150
def_map : & DefMap ,
151
151
visited_modules : & mut FxHashSet < ModuleId > ,
152
- crate_root : ModuleId ,
152
+ crate_root : CrateRootModuleId ,
153
153
from : ModuleId ,
154
154
module_id : ModuleId ,
155
155
max_len : usize ,
@@ -183,7 +183,7 @@ fn find_path_for_module(
183
183
184
184
// - if the item is the crate root of a dependency crate, return the name from the extern prelude
185
185
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 ( ) {
187
187
if module_id == def_id {
188
188
let name = scope_name. unwrap_or_else ( || name. clone ( ) ) ;
189
189
@@ -192,7 +192,7 @@ fn find_path_for_module(
192
192
def_map[ local_id]
193
193
. scope
194
194
. type_ ( & name)
195
- . filter ( |& ( id, _) | id != ModuleDefId :: ModuleId ( def_id) )
195
+ . filter ( |& ( id, _) | id != ModuleDefId :: ModuleId ( def_id. into ( ) ) )
196
196
} )
197
197
. is_some ( ) ;
198
198
let kind = if name_already_occupied_in_type_ns {
@@ -224,6 +224,7 @@ fn find_path_for_module(
224
224
)
225
225
}
226
226
227
+ // FIXME: Do we still need this now that we record import origins, and hence aliases?
227
228
fn find_in_scope (
228
229
db : & dyn DefDatabase ,
229
230
def_map : & DefMap ,
@@ -244,7 +245,7 @@ fn find_in_prelude(
244
245
item : ItemInNs ,
245
246
from : ModuleId ,
246
247
) -> Option < ModPath > {
247
- let prelude_module = root_def_map. prelude ( ) ?;
248
+ let ( prelude_module, _ ) = root_def_map. prelude ( ) ?;
248
249
// Preludes in block DefMaps are ignored, only the crate DefMap is searched
249
250
let prelude_def_map = prelude_module. def_map ( db) ;
250
251
let prelude_scope = & prelude_def_map[ prelude_module. local_id ] . scope ;
@@ -293,7 +294,7 @@ fn calculate_best_path(
293
294
db : & dyn DefDatabase ,
294
295
def_map : & DefMap ,
295
296
visited_modules : & mut FxHashSet < ModuleId > ,
296
- crate_root : ModuleId ,
297
+ crate_root : CrateRootModuleId ,
297
298
max_len : usize ,
298
299
item : ItemInNs ,
299
300
from : ModuleId ,
@@ -346,6 +347,11 @@ fn calculate_best_path(
346
347
let extern_paths = crate_graph[ from. krate ] . dependencies . iter ( ) . filter_map ( |dep| {
347
348
let import_map = db. import_map ( dep. crate_id ) ;
348
349
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
+
349
355
// Determine best path for containing module and append last segment from `info`.
350
356
// FIXME: we should guide this to look up the path locally, or from the same crate again?
351
357
let mut path = find_path_for_module (
@@ -1293,4 +1299,65 @@ pub mod prelude {
1293
1299
"None" ,
1294
1300
) ;
1295
1301
}
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
+ }
1296
1363
}
0 commit comments