@@ -319,6 +319,9 @@ pub trait PrettyPrinter<'tcx>:
319
319
///
320
320
/// `callers` is a chain of visible_parent's leading to `def_id`,
321
321
/// to support cycle detection during recursion.
322
+ ///
323
+ /// This method returns false if we can't print the visible path, so
324
+ /// `print_def_path` can fall back on the item's real definition path.
322
325
fn try_print_visible_def_path_recur (
323
326
mut self ,
324
327
def_id : DefId ,
@@ -405,19 +408,7 @@ pub trait PrettyPrinter<'tcx>:
405
408
Some ( parent) => parent,
406
409
None => return Ok ( ( self , false ) ) ,
407
410
} ;
408
- if callers. contains ( & visible_parent) {
409
- return Ok ( ( self , false ) ) ;
410
- }
411
- callers. push ( visible_parent) ;
412
- // HACK(eddyb) this bypasses `path_append`'s prefix printing to avoid
413
- // knowing ahead of time whether the entire path will succeed or not.
414
- // To support printers that do not implement `PrettyPrinter`, a `Vec` or
415
- // linked list on the stack would need to be built, before any printing.
416
- match self . try_print_visible_def_path_recur ( visible_parent, callers) ? {
417
- ( cx, false ) => return Ok ( ( cx, false ) ) ,
418
- ( cx, true ) => self = cx,
419
- }
420
- callers. pop ( ) ;
411
+
421
412
let actual_parent = self . tcx ( ) . parent ( def_id) ;
422
413
debug ! (
423
414
"try_print_visible_def_path: visible_parent={:?} actual_parent={:?}" ,
@@ -463,14 +454,21 @@ pub trait PrettyPrinter<'tcx>:
463
454
// `visible_parent_map`), looking for the specific child we currently have and then
464
455
// have access to the re-exported name.
465
456
DefPathData :: TypeNs ( ref mut name) if Some ( visible_parent) != actual_parent => {
457
+ // Item might be re-exported several times, but filter for the one
458
+ // that's public and whose identifier isn't `_`.
466
459
let reexport = self
467
460
. tcx ( )
468
461
. item_children ( visible_parent)
469
462
. iter ( )
470
- . find ( |child| child. res . opt_def_id ( ) == Some ( def_id) )
463
+ . filter ( |child| child. res . opt_def_id ( ) == Some ( def_id) )
464
+ . find ( |child| child. vis . is_public ( ) && child. ident . name != kw:: Underscore )
471
465
. map ( |child| child. ident . name ) ;
472
- if let Some ( reexport) = reexport {
473
- * name = reexport;
466
+
467
+ if let Some ( new_name) = reexport {
468
+ * name = new_name;
469
+ } else {
470
+ // There is no name that is public and isn't `_`, so bail.
471
+ return Ok ( ( self , false ) ) ;
474
472
}
475
473
}
476
474
// Re-exported `extern crate` (#43189).
@@ -481,6 +479,20 @@ pub trait PrettyPrinter<'tcx>:
481
479
}
482
480
debug ! ( "try_print_visible_def_path: data={:?}" , data) ;
483
481
482
+ if callers. contains ( & visible_parent) {
483
+ return Ok ( ( self , false ) ) ;
484
+ }
485
+ callers. push ( visible_parent) ;
486
+ // HACK(eddyb) this bypasses `path_append`'s prefix printing to avoid
487
+ // knowing ahead of time whether the entire path will succeed or not.
488
+ // To support printers that do not implement `PrettyPrinter`, a `Vec` or
489
+ // linked list on the stack would need to be built, before any printing.
490
+ match self . try_print_visible_def_path_recur ( visible_parent, callers) ? {
491
+ ( cx, false ) => return Ok ( ( cx, false ) ) ,
492
+ ( cx, true ) => self = cx,
493
+ }
494
+ callers. pop ( ) ;
495
+
484
496
Ok ( ( self . path_append ( Ok , & DisambiguatedDefPathData { data, disambiguator : 0 } ) ?, true ) )
485
497
}
486
498
0 commit comments