@@ -515,21 +515,55 @@ impl Clean<Vec<TyParamBound>> for ty::ExistentialBounds {
515
515
}
516
516
}
517
517
518
- fn external_path ( cx : & DocContext , name : & str , substs : & subst:: Substs ) -> Path {
518
+ fn external_path_params ( cx : & DocContext , trait_did : Option < ast:: DefId > ,
519
+ substs : & subst:: Substs ) -> PathParameters {
520
+ use rustc:: middle:: ty:: sty;
519
521
let lifetimes = substs. regions ( ) . get_slice ( subst:: TypeSpace )
520
522
. iter ( )
521
523
. filter_map ( |v| v. clean ( cx) )
522
524
. collect ( ) ;
523
525
let types = substs. types . get_slice ( subst:: TypeSpace ) . to_vec ( ) ;
524
- let types = types. clean ( cx) ;
526
+
527
+ match ( trait_did, cx. tcx_opt ( ) ) {
528
+ // Attempt to sugar an external path like Fn<(A, B,), C> to Fn(A, B) -> C
529
+ ( Some ( did) , Some ( ref tcx) ) if tcx. lang_items . fn_trait_kind ( did) . is_some ( ) => {
530
+ assert_eq ! ( types. len( ) , 2 ) ;
531
+ let inputs = match types[ 0 ] . sty {
532
+ sty:: ty_tup( ref tys) => tys. iter ( ) . map ( |t| t. clean ( cx) ) . collect ( ) ,
533
+ _ => {
534
+ return PathParameters :: AngleBracketed {
535
+ lifetimes : lifetimes,
536
+ types : types. clean ( cx)
537
+ }
538
+ }
539
+ } ;
540
+ let output = match types[ 1 ] . sty {
541
+ sty:: ty_tup( ref v) if v. is_empty ( ) => None , // -> ()
542
+ _ => Some ( types[ 1 ] . clean ( cx) )
543
+ } ;
544
+ PathParameters :: Parenthesized {
545
+ inputs : inputs,
546
+ output : output
547
+ }
548
+ } ,
549
+ ( _, _) => {
550
+ PathParameters :: AngleBracketed {
551
+ lifetimes : lifetimes,
552
+ types : types. clean ( cx) ,
553
+ }
554
+ }
555
+ }
556
+ }
557
+
558
+ // trait_did should be set to a trait's DefId if called on a TraitRef, in order to sugar
559
+ // from Fn<(A, B,), C> to Fn(A, B) -> C
560
+ fn external_path ( cx : & DocContext , name : & str , trait_did : Option < ast:: DefId > ,
561
+ substs : & subst:: Substs ) -> Path {
525
562
Path {
526
563
global : false ,
527
564
segments : vec ! [ PathSegment {
528
565
name: name. to_string( ) ,
529
- params: PathParameters :: AngleBracketed {
530
- lifetimes: lifetimes,
531
- types: types,
532
- }
566
+ params: external_path_params( cx, trait_did, substs)
533
567
} ] ,
534
568
}
535
569
}
@@ -544,16 +578,16 @@ impl Clean<TyParamBound> for ty::BuiltinBound {
544
578
let ( did, path) = match * self {
545
579
ty:: BoundSend =>
546
580
( tcx. lang_items . send_trait ( ) . unwrap ( ) ,
547
- external_path ( cx, "Send" , & empty) ) ,
581
+ external_path ( cx, "Send" , None , & empty) ) ,
548
582
ty:: BoundSized =>
549
583
( tcx. lang_items . sized_trait ( ) . unwrap ( ) ,
550
- external_path ( cx, "Sized" , & empty) ) ,
584
+ external_path ( cx, "Sized" , None , & empty) ) ,
551
585
ty:: BoundCopy =>
552
586
( tcx. lang_items . copy_trait ( ) . unwrap ( ) ,
553
- external_path ( cx, "Copy" , & empty) ) ,
587
+ external_path ( cx, "Copy" , None , & empty) ) ,
554
588
ty:: BoundSync =>
555
589
( tcx. lang_items . sync_trait ( ) . unwrap ( ) ,
556
- external_path ( cx, "Sync" , & empty) ) ,
590
+ external_path ( cx, "Sync" , None , & empty) ) ,
557
591
} ;
558
592
let fqn = csearch:: get_item_path ( tcx, did) ;
559
593
let fqn = fqn. into_iter ( ) . map ( |i| i. to_string ( ) ) . collect ( ) ;
@@ -586,7 +620,7 @@ impl<'tcx> Clean<TyParamBound> for ty::TraitRef<'tcx> {
586
620
let fqn = fqn. into_iter ( ) . map ( |i| i. to_string ( ) )
587
621
. collect :: < Vec < String > > ( ) ;
588
622
let path = external_path ( cx, fqn. last ( ) . unwrap ( ) . as_slice ( ) ,
589
- & self . substs ) ;
623
+ Some ( self . def_id ) , & self . substs ) ;
590
624
cx. external_paths . borrow_mut ( ) . as_mut ( ) . unwrap ( ) . insert ( self . def_id ,
591
625
( fqn, TypeTrait ) ) ;
592
626
@@ -1437,7 +1471,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
1437
1471
_ => TypeEnum ,
1438
1472
} ;
1439
1473
let path = external_path ( cx, fqn. last ( ) . unwrap ( ) . to_string ( ) . as_slice ( ) ,
1440
- substs) ;
1474
+ None , substs) ;
1441
1475
cx. external_paths . borrow_mut ( ) . as_mut ( ) . unwrap ( ) . insert ( did, ( fqn, kind) ) ;
1442
1476
ResolvedPath {
1443
1477
path : path,
0 commit comments