@@ -469,7 +469,8 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
469
469
/// Used when rendering a `ResolvedPath` structure. This invokes the `path`
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
- print_all : bool , use_absolute : bool , is_not_debug : bool ) -> fmt:: Result {
472
+ print_all : bool , use_absolute : bool , is_not_debug : bool ,
473
+ need_paren : bool ) -> fmt:: Result {
473
474
let empty = clean:: PathSegment {
474
475
name : String :: new ( ) ,
475
476
params : clean:: PathParameters :: Parenthesized {
@@ -534,7 +535,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
534
535
} else {
535
536
format ! ( "{}" , HRef :: new( did, & last. name) )
536
537
} ;
537
- write ! ( w, "{}{}" , path, last. params) ?;
538
+ write ! ( w, "{}{}{}" , if need_paren { "(" } else { "" } , path, last. params) ?;
538
539
} else {
539
540
let path = if use_absolute {
540
541
match href ( did) {
@@ -547,7 +548,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
547
548
} else {
548
549
format ! ( "{:?}" , HRef :: new( did, & last. name) )
549
550
} ;
550
- write ! ( w, "{}{}" , path, last. params) ?;
551
+ write ! ( w, "{}{}{}" , if need_paren { "(" } else { "" } , path, last. params) ?;
551
552
}
552
553
}
553
554
Ok ( ( ) )
@@ -599,13 +600,17 @@ fn primitive_link(f: &mut fmt::Formatter,
599
600
600
601
/// Helper to render type parameters
601
602
fn tybounds ( w : & mut fmt:: Formatter ,
602
- typarams : & Option < Vec < clean:: TyParamBound > > ) -> fmt:: Result {
603
+ typarams : & Option < Vec < clean:: TyParamBound > > ,
604
+ need_paren : bool ) -> fmt:: Result {
603
605
match * typarams {
604
606
Some ( ref params) => {
605
607
for param in params {
606
608
write ! ( w, " + " ) ?;
607
609
fmt:: Display :: fmt ( param, w) ?;
608
610
}
611
+ if need_paren {
612
+ write ! ( w, ")" ) ?;
613
+ }
609
614
Ok ( ( ) )
610
615
}
611
616
None => Ok ( ( ) )
@@ -639,15 +644,19 @@ impl<'a> fmt::Debug for HRef<'a> {
639
644
}
640
645
641
646
fn fmt_type ( t : & clean:: Type , f : & mut fmt:: Formatter , use_absolute : bool ,
642
- is_not_debug : bool ) -> fmt:: Result {
647
+ is_not_debug : bool , is_ref : bool ) -> fmt:: Result {
643
648
match * t {
644
649
clean:: Generic ( ref name) => {
645
650
f. write_str ( name)
646
651
}
647
652
clean:: ResolvedPath { did, ref typarams, ref path, is_generic } => {
648
653
// Paths like T::Output and Self::Output should be rendered with all segments
649
- resolved_path ( f, did, path, is_generic, use_absolute, is_not_debug) ?;
650
- tybounds ( f, typarams)
654
+ let need_paren = match * typarams {
655
+ Some ( ref v) => !v. is_empty ( ) ,
656
+ _ => false ,
657
+ } && is_ref;
658
+ resolved_path ( f, did, path, is_generic, use_absolute, is_not_debug, need_paren) ?;
659
+ tybounds ( f, typarams, need_paren)
651
660
}
652
661
clean:: Infer => write ! ( f, "_" ) ,
653
662
clean:: Primitive ( prim) if is_not_debug => primitive_link ( f, prim, prim. as_str ( ) ) ,
@@ -788,14 +797,14 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
788
797
_ => {
789
798
if f. alternate ( ) {
790
799
write ! ( f, "&{}{}" , lt, m) ?;
791
- fmt_type ( & ty, f, use_absolute, is_not_debug)
800
+ fmt_type ( & ty, f, use_absolute, is_not_debug, true )
792
801
} else {
793
802
if is_not_debug {
794
803
write ! ( f, "&{}{}" , lt, m) ?;
795
804
} else {
796
805
write ! ( f, "&{}{}" , lt, m) ?;
797
806
}
798
- fmt_type ( & ty, f, use_absolute, is_not_debug)
807
+ fmt_type ( & ty, f, use_absolute, is_not_debug, true )
799
808
}
800
809
}
801
810
}
@@ -865,7 +874,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
865
874
// look at).
866
875
box clean:: ResolvedPath { did, ref typarams, .. } => {
867
876
let path = clean:: Path :: singleton ( name. clone ( ) ) ;
868
- resolved_path ( f, did, & path, true , use_absolute, is_not_debug) ?;
877
+ resolved_path ( f, did, & path, true , use_absolute, is_not_debug, false ) ?;
869
878
870
879
// FIXME: `typarams` are not rendered, and this seems bad?
871
880
drop ( typarams) ;
@@ -884,13 +893,13 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
884
893
885
894
impl fmt:: Display for clean:: Type {
886
895
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
887
- fmt_type ( self , f, false , true )
896
+ fmt_type ( self , f, false , true , false )
888
897
}
889
898
}
890
899
891
900
impl fmt:: Debug for clean:: Type {
892
901
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
893
- fmt_type ( self , f, false , false )
902
+ fmt_type ( self , f, false , false , false )
894
903
}
895
904
}
896
905
@@ -924,7 +933,7 @@ fn fmt_impl(i: &clean::Impl,
924
933
write ! ( f, " for " ) ?;
925
934
}
926
935
927
- fmt_type ( & i. for_ , f, use_absolute, true ) ?;
936
+ fmt_type ( & i. for_ , f, use_absolute, true , false ) ?;
928
937
929
938
fmt:: Display :: fmt ( & WhereClause { gens : & i. generics , indent : 0 , end_newline : true } , f) ?;
930
939
Ok ( ( ) )
@@ -1130,7 +1139,7 @@ impl fmt::Display for clean::Import {
1130
1139
impl fmt:: Display for clean:: ImportSource {
1131
1140
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1132
1141
match self . did {
1133
- Some ( did) => resolved_path ( f, did, & self . path , true , false , true ) ,
1142
+ Some ( did) => resolved_path ( f, did, & self . path , true , false , true , false ) ,
1134
1143
_ => {
1135
1144
for ( i, seg) in self . path . segments . iter ( ) . enumerate ( ) {
1136
1145
if i > 0 {
0 commit comments