@@ -17,7 +17,7 @@ use rustc_session::utils::NativeLibKind;
17
17
use rustc_session:: { Session , StableCrateId } ;
18
18
use rustc_span:: hygiene:: { ExpnHash , ExpnId } ;
19
19
use rustc_span:: source_map:: { Span , Spanned } ;
20
- use rustc_span:: symbol:: Symbol ;
20
+ use rustc_span:: symbol:: { kw , Symbol } ;
21
21
22
22
use rustc_data_structures:: sync:: Lrc ;
23
23
use smallvec:: SmallVec ;
@@ -295,6 +295,10 @@ pub fn provide(providers: &mut Providers) {
295
295
use std:: collections:: vec_deque:: VecDeque ;
296
296
297
297
let mut visible_parent_map: DefIdMap < DefId > = Default :: default ( ) ;
298
+ // This is a secondary visible_parent_map, storing the DefId of parents that re-export
299
+ // the child as `_`. Since we prefer parents that don't do this, merge this map at the
300
+ // end, only if we're missing any keys from the former.
301
+ let mut fallback_map: DefIdMap < DefId > = Default :: default ( ) ;
298
302
299
303
// Issue 46112: We want the map to prefer the shortest
300
304
// paths when reporting the path to an item. Therefore we
@@ -317,12 +321,17 @@ pub fn provide(providers: &mut Providers) {
317
321
bfs_queue. push_back ( DefId { krate : cnum, index : CRATE_DEF_INDEX } ) ;
318
322
}
319
323
320
- let mut add_child = |bfs_queue : & mut VecDeque < _ > , child : & Export , parent : DefId | {
321
- if !child . vis . is_public ( ) {
324
+ let mut add_child = |bfs_queue : & mut VecDeque < _ > , export : & Export , parent : DefId | {
325
+ if !export . vis . is_public ( ) {
322
326
return ;
323
327
}
324
328
325
- if let Some ( child) = child. res . opt_def_id ( ) {
329
+ if let Some ( child) = export. res . opt_def_id ( ) {
330
+ if export. ident . name == kw:: Underscore {
331
+ fallback_map. insert ( child, parent) ;
332
+ return ;
333
+ }
334
+
326
335
match visible_parent_map. entry ( child) {
327
336
Entry :: Occupied ( mut entry) => {
328
337
// If `child` is defined in crate `cnum`, ensure
@@ -345,6 +354,12 @@ pub fn provide(providers: &mut Providers) {
345
354
}
346
355
}
347
356
357
+ // Fill in any missing entries with the (less preferable) path ending in `::_`.
358
+ // We still use this path in a diagnostic that suggests importing `::*`.
359
+ for ( child, parent) in fallback_map {
360
+ visible_parent_map. entry ( child) . or_insert ( parent) ;
361
+ }
362
+
348
363
visible_parent_map
349
364
} ,
350
365
0 commit comments