@@ -470,10 +470,22 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
470
470
/// rendering function with the necessary arguments for linking to a local path.
471
471
fn resolved_path ( w : & mut fmt:: Formatter , did : DefId , path : & clean:: Path ,
472
472
print_all : bool , use_absolute : bool , is_not_debug : bool ) -> fmt:: Result {
473
- let last = path. segments . last ( ) . unwrap ( ) ;
474
- let rel_root = match & * path. segments [ 0 ] . name {
475
- "self" => Some ( "./" . to_string ( ) ) ,
476
- _ => None ,
473
+ let empty = clean:: PathSegment {
474
+ name : String :: new ( ) ,
475
+ params : clean:: PathParameters :: Parenthesized {
476
+ inputs : Vec :: new ( ) ,
477
+ output : None ,
478
+ }
479
+ } ;
480
+ let last = path. segments . last ( )
481
+ . unwrap_or ( & empty) ;
482
+ let rel_root = if path. segments . is_empty ( ) {
483
+ None
484
+ } else {
485
+ match & * path. segments [ 0 ] . name {
486
+ "self" => Some ( "./" . to_string ( ) ) ,
487
+ _ => None ,
488
+ }
477
489
} ;
478
490
479
491
if print_all {
@@ -487,10 +499,9 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
487
499
root. push_str ( & seg. name ) ;
488
500
root. push_str ( "/" ) ;
489
501
if is_not_debug {
490
- write ! ( w, "<a class=\" mod\"
491
- href=\" {}index.html\" >{}</a>::" ,
492
- root,
493
- seg. name) ?;
502
+ write ! ( w, "<a class=\" mod\" href=\" {}index.html\" >{}</a>::" ,
503
+ root,
504
+ seg. name) ?;
494
505
} else {
495
506
write ! ( w, "{}::" , seg. name) ?;
496
507
}
@@ -516,7 +527,8 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
516
527
match href ( did) {
517
528
Some ( ( _, _, fqp) ) => format ! ( "{}::{}" ,
518
529
fqp[ ..fqp. len( ) -1 ] . join( "::" ) ,
519
- HRef :: new( did, fqp. last( ) . unwrap( ) ) ) ,
530
+ HRef :: new( did, fqp. last( )
531
+ . unwrap_or( & String :: new( ) ) ) ) ,
520
532
None => format ! ( "{}" , HRef :: new( did, & last. name) ) ,
521
533
}
522
534
} else {
@@ -528,7 +540,8 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
528
540
match href ( did) {
529
541
Some ( ( _, _, fqp) ) => format ! ( "{:?}::{:?}" ,
530
542
fqp[ ..fqp. len( ) -1 ] . join( "::" ) ,
531
- HRef :: new( did, fqp. last( ) . unwrap( ) ) ) ,
543
+ HRef :: new( did, fqp. last( )
544
+ . unwrap_or( & String :: new( ) ) ) ) ,
532
545
None => format ! ( "{:?}" , HRef :: new( did, & last. name) ) ,
533
546
}
534
547
} else {
@@ -801,45 +814,65 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
801
814
}
802
815
Ok ( ( ) )
803
816
}
804
- // It's pretty unsightly to look at `<A as B>::C` in output, and
805
- // we've got hyperlinking on our side, so try to avoid longer
806
- // notation as much as possible by making `C` a hyperlink to trait
807
- // `B` to disambiguate.
808
- //
809
- // FIXME: this is still a lossy conversion and there should probably
810
- // be a better way of representing this in general? Most of
811
- // the ugliness comes from inlining across crates where
812
- // everything comes in as a fully resolved QPath (hard to
813
- // look at).
814
- clean:: QPath {
815
- ref name,
816
- ref self_type,
817
- trait_ : box clean:: ResolvedPath { did, ref typarams, .. } ,
818
- } => {
819
- if f. alternate ( ) {
820
- write ! ( f, "{:#}::" , self_type) ?;
821
- } else {
822
- write ! ( f, "{}::" , self_type) ?;
823
- }
824
- let path = clean:: Path :: singleton ( name. clone ( ) ) ;
825
- resolved_path ( f, did, & path, true , use_absolute, is_not_debug) ?;
826
-
827
- // FIXME: `typarams` are not rendered, and this seems bad?
828
- drop ( typarams) ;
829
- Ok ( ( ) )
830
- }
831
817
clean:: QPath { ref name, ref self_type, ref trait_ } => {
818
+ let should_show_cast = match * trait_ {
819
+ box clean:: ResolvedPath { .. } => {
820
+ let path = clean:: Path :: singleton ( name. clone ( ) ) ;
821
+ !path. segments . is_empty ( ) && & format ! ( "{:#}" , trait_) != "()" &&
822
+ & format ! ( "{:#}" , self_type) != "Self"
823
+ }
824
+ _ => true ,
825
+ } ;
832
826
if f. alternate ( ) {
833
827
if is_not_debug {
834
- write ! ( f, "<{:#} as {:#}>::{}" , self_type, trait_, name)
828
+ if should_show_cast {
829
+ write ! ( f, "<{:#} as {:#}>::" , self_type, trait_) ?
830
+ } else {
831
+ write ! ( f, "{:#}::" , self_type) ?
832
+ }
835
833
} else {
836
- write ! ( f, "<{:#?} as {:#?}>::{}" , self_type, trait_, name)
834
+ if should_show_cast {
835
+ write ! ( f, "<{:#?} as {:#?}>::" , self_type, trait_) ?
836
+ } else {
837
+ write ! ( f, "{:#?}::" , self_type) ?
838
+ }
837
839
}
838
840
} else {
839
841
if is_not_debug {
840
- write ! ( f, "<{} as {}>::{}" , self_type, trait_, name)
842
+ if should_show_cast {
843
+ write ! ( f, "<{} as {}>::" , self_type, trait_) ?
844
+ } else {
845
+ write ! ( f, "{}::" , self_type) ?
846
+ }
841
847
} else {
842
- write ! ( f, "<{:?} as {:?}>::{}" , self_type, trait_, name)
848
+ if should_show_cast {
849
+ write ! ( f, "<{:?} as {:?}>::" , self_type, trait_) ?
850
+ } else {
851
+ write ! ( f, "{:?}::" , self_type) ?
852
+ }
853
+ }
854
+ } ;
855
+ match * trait_ {
856
+ // It's pretty unsightly to look at `<A as B>::C` in output, and
857
+ // we've got hyperlinking on our side, so try to avoid longer
858
+ // notation as much as possible by making `C` a hyperlink to trait
859
+ // `B` to disambiguate.
860
+ //
861
+ // FIXME: this is still a lossy conversion and there should probably
862
+ // be a better way of representing this in general? Most of
863
+ // the ugliness comes from inlining across crates where
864
+ // everything comes in as a fully resolved QPath (hard to
865
+ // look at).
866
+ box clean:: ResolvedPath { did, ref typarams, .. } => {
867
+ let path = clean:: Path :: singleton ( name. clone ( ) ) ;
868
+ resolved_path ( f, did, & path, true , use_absolute, is_not_debug) ?;
869
+
870
+ // FIXME: `typarams` are not rendered, and this seems bad?
871
+ drop ( typarams) ;
872
+ Ok ( ( ) )
873
+ }
874
+ _ => {
875
+ write ! ( f, "{}" , name)
843
876
}
844
877
}
845
878
}
0 commit comments