@@ -440,28 +440,29 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
440
440
/// Used when rendering a `ResolvedPath` structure. This invokes the `path`
441
441
/// rendering function with the necessary arguments for linking to a local path.
442
442
fn resolved_path ( w : & mut fmt:: Formatter , did : DefId , path : & clean:: Path ,
443
- print_all : bool , use_absolute : bool ) -> fmt:: Result {
443
+ print_all : bool , use_absolute : bool , rename : Option < & str > ) -> fmt:: Result {
444
444
let last = path. segments . last ( ) . unwrap ( ) ;
445
+ let last_name = rename. unwrap_or ( & last. name ) ;
445
446
446
447
if print_all {
447
448
for seg in & path. segments [ ..path. segments . len ( ) - 1 ] {
448
449
write ! ( w, "{}::" , seg. name) ?;
449
450
}
450
451
}
451
452
if w. alternate ( ) {
452
- write ! ( w, "{:#}{:#}" , HRef :: new( did, & last . name ) , last. args) ?;
453
+ write ! ( w, "{:#}{:#}" , HRef :: new( did, last_name ) , last. args) ?;
453
454
} else {
454
455
let path = if use_absolute {
455
456
match href ( did) {
456
457
Some ( ( _, _, fqp) ) => {
457
458
format ! ( "{}::{}" ,
458
459
fqp[ ..fqp. len( ) - 1 ] . join( "::" ) ,
459
- HRef :: new( did, fqp. last( ) . unwrap( ) ) )
460
+ HRef :: new( did, rename . or ( fqp. last( ) . map ( |n| & * * n ) ) . unwrap( ) ) )
460
461
}
461
- None => HRef :: new ( did, & last . name ) . to_string ( ) ,
462
+ None => HRef :: new ( did, last_name ) . to_string ( ) ,
462
463
}
463
464
} else {
464
- HRef :: new ( did, & last . name ) . to_string ( )
465
+ HRef :: new ( did, last_name ) . to_string ( )
465
466
} ;
466
467
write ! ( w, "{}{}" , path, last. args) ?;
467
468
}
@@ -547,7 +548,14 @@ impl<'a> fmt::Display for HRef<'a> {
547
548
}
548
549
}
549
550
550
- fn fmt_type ( t : & clean:: Type , f : & mut fmt:: Formatter , use_absolute : bool ) -> fmt:: Result {
551
+ /// Writes the given type into the given formatter, optionally printing its full path or using the
552
+ /// given name instead.
553
+ fn fmt_type (
554
+ t : & clean:: Type ,
555
+ f : & mut fmt:: Formatter ,
556
+ use_absolute : bool ,
557
+ rename : Option < & str > ,
558
+ ) -> fmt:: Result {
551
559
match * t {
552
560
clean:: Generic ( ref name) => {
553
561
f. write_str ( name)
@@ -557,7 +565,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt:
557
565
f. write_str ( "dyn " ) ?;
558
566
}
559
567
// Paths like T::Output and Self::Output should be rendered with all segments
560
- resolved_path ( f, did, path, is_generic, use_absolute) ?;
568
+ resolved_path ( f, did, path, is_generic, use_absolute, rename ) ?;
561
569
tybounds ( f, typarams)
562
570
}
563
571
clean:: Infer => write ! ( f, "_" ) ,
@@ -657,17 +665,17 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt:
657
665
}
658
666
clean:: ResolvedPath { typarams : Some ( ref v) , .. } if !v. is_empty ( ) => {
659
667
write ! ( f, "{}{}{}(" , amp, lt, m) ?;
660
- fmt_type ( & ty, f, use_absolute) ?;
668
+ fmt_type ( & ty, f, use_absolute, rename ) ?;
661
669
write ! ( f, ")" )
662
670
}
663
671
clean:: Generic ( ..) => {
664
672
primitive_link ( f, PrimitiveType :: Reference ,
665
673
& format ! ( "{}{}{}" , amp, lt, m) ) ?;
666
- fmt_type ( & ty, f, use_absolute)
674
+ fmt_type ( & ty, f, use_absolute, rename )
667
675
}
668
676
_ => {
669
677
write ! ( f, "{}{}{}" , amp, lt, m) ?;
670
- fmt_type ( & ty, f, use_absolute)
678
+ fmt_type ( & ty, f, use_absolute, rename )
671
679
}
672
680
}
673
681
}
@@ -736,14 +744,15 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt:
736
744
737
745
impl fmt:: Display for clean:: Type {
738
746
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
739
- fmt_type ( self , f, false )
747
+ fmt_type ( self , f, false , None )
740
748
}
741
749
}
742
750
743
751
fn fmt_impl ( i : & clean:: Impl ,
744
752
f : & mut fmt:: Formatter ,
745
753
link_trait : bool ,
746
- use_absolute : bool ) -> fmt:: Result {
754
+ use_absolute : bool ,
755
+ rename : Option < & str > ) -> fmt:: Result {
747
756
if f. alternate ( ) {
748
757
write ! ( f, "impl{:#} " , i. generics) ?;
749
758
} else {
@@ -771,9 +780,9 @@ fn fmt_impl(i: &clean::Impl,
771
780
}
772
781
773
782
if let Some ( ref ty) = i. blanket_impl {
774
- fmt_type ( ty, f, use_absolute) ?;
783
+ fmt_type ( ty, f, use_absolute, rename ) ?;
775
784
} else {
776
- fmt_type ( & i. for_ , f, use_absolute) ?;
785
+ fmt_type ( & i. for_ , f, use_absolute, rename ) ?;
777
786
}
778
787
779
788
fmt:: Display :: fmt ( & WhereClause { gens : & i. generics , indent : 0 , end_newline : true } , f) ?;
@@ -782,15 +791,23 @@ fn fmt_impl(i: &clean::Impl,
782
791
783
792
impl fmt:: Display for clean:: Impl {
784
793
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
785
- fmt_impl ( self , f, true , false )
794
+ fmt_impl ( self , f, true , false , None )
786
795
}
787
796
}
788
797
789
798
// The difference from above is that trait is not hyperlinked.
790
799
pub fn fmt_impl_for_trait_page ( i : & clean:: Impl ,
791
800
f : & mut fmt:: Formatter ,
792
- use_absolute : bool ) -> fmt:: Result {
793
- fmt_impl ( i, f, false , use_absolute)
801
+ use_absolute : bool ,
802
+ rename : Option < & str > ) -> fmt:: Result {
803
+ fmt_impl ( i, f, false , use_absolute, rename)
804
+ }
805
+
806
+ /// Renders an `impl` block signature, but with the `for` type renamed to the given name.
807
+ pub fn fmt_impl_renamed ( i : & clean:: Impl ,
808
+ f : & mut fmt:: Formatter ,
809
+ rename : Option < & str > ) -> fmt:: Result {
810
+ fmt_impl ( i, f, true , false , rename)
794
811
}
795
812
796
813
impl fmt:: Display for clean:: Arguments {
@@ -946,7 +963,7 @@ impl<'a> fmt::Display for VisSpace<'a> {
946
963
{
947
964
f. write_str ( "in " ) ?;
948
965
}
949
- resolved_path ( f, did, path, true , false ) ?;
966
+ resolved_path ( f, did, path, true , false , None ) ?;
950
967
f. write_str ( ") " )
951
968
}
952
969
}
@@ -1004,7 +1021,7 @@ impl fmt::Display for clean::Import {
1004
1021
impl fmt:: Display for clean:: ImportSource {
1005
1022
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1006
1023
match self . did {
1007
- Some ( did) => resolved_path ( f, did, & self . path , true , false ) ,
1024
+ Some ( did) => resolved_path ( f, did, & self . path , true , false , None ) ,
1008
1025
_ => {
1009
1026
for ( i, seg) in self . path . segments . iter ( ) . enumerate ( ) {
1010
1027
if i > 0 {
0 commit comments