@@ -891,13 +891,20 @@ fn clean_fn_decl_with_args(
891891
892892fn clean_fn_decl_from_did_and_sig (
893893 cx : & mut DocContext < ' _ > ,
894- did : DefId ,
894+ did : Option < DefId > ,
895895 sig : ty:: PolyFnSig < ' _ > ,
896896) -> FnDecl {
897- let mut names = if did. is_local ( ) { & [ ] } else { cx. tcx . fn_arg_names ( did) } . iter ( ) ;
897+ let mut names = did. map_or ( & [ ] as & [ _ ] , |did| cx. tcx . fn_arg_names ( did) ) . iter ( ) ;
898+
899+ // We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
900+ // but shouldn't change any code meaning.
901+ let output = match sig. skip_binder ( ) . output ( ) . clean ( cx) {
902+ Type :: Tuple ( inner) if inner. len ( ) == 0 => DefaultReturn ,
903+ ty => Return ( ty) ,
904+ } ;
898905
899906 FnDecl {
900- output : Return ( sig . skip_binder ( ) . output ( ) . clean ( cx ) ) ,
907+ output,
901908 c_variadic : sig. skip_binder ( ) . c_variadic ,
902909 inputs : Arguments {
903910 values : sig
@@ -1031,20 +1038,18 @@ impl Clean<Item> for hir::ImplItem<'_> {
10311038 }
10321039 } ;
10331040
1034- let what_rustc_thinks =
1041+ let mut what_rustc_thinks =
10351042 Item :: from_def_id_and_parts ( local_did, Some ( self . ident . name ) , inner, cx) ;
1036- let parent_item = cx. tcx . hir ( ) . expect_item ( cx. tcx . hir ( ) . get_parent_item ( self . hir_id ( ) ) ) ;
1037- if let hir:: ItemKind :: Impl ( impl_) = & parent_item. kind {
1038- if impl_. of_trait . is_some ( ) {
1039- // Trait impl items always inherit the impl's visibility --
1040- // we don't want to show `pub`.
1041- Item { visibility : Inherited , ..what_rustc_thinks }
1042- } else {
1043- what_rustc_thinks
1044- }
1045- } else {
1046- panic ! ( "found impl item with non-impl parent {:?}" , parent_item) ;
1043+
1044+ let impl_ref = cx. tcx . parent ( local_did) . and_then ( |did| cx. tcx . impl_trait_ref ( did) ) ;
1045+
1046+ // Trait impl items always inherit the impl's visibility --
1047+ // we don't want to show `pub`.
1048+ if impl_ref. is_some ( ) {
1049+ what_rustc_thinks. visibility = Inherited ;
10471050 }
1051+
1052+ what_rustc_thinks
10481053 } )
10491054 }
10501055}
@@ -1069,7 +1074,7 @@ impl Clean<Item> for ty::AssocItem {
10691074 tcx. explicit_predicates_of ( self . def_id ) ,
10701075 ) ;
10711076 let sig = tcx. fn_sig ( self . def_id ) ;
1072- let mut decl = clean_fn_decl_from_did_and_sig ( cx, self . def_id , sig) ;
1077+ let mut decl = clean_fn_decl_from_did_and_sig ( cx, Some ( self . def_id ) , sig) ;
10731078
10741079 if self . fn_has_self_parameter {
10751080 let self_ty = match self . container {
@@ -1199,7 +1204,18 @@ impl Clean<Item> for ty::AssocItem {
11991204 }
12001205 } ;
12011206
1202- Item :: from_def_id_and_parts ( self . def_id , Some ( self . name ) , kind, cx)
1207+ let mut what_rustc_thinks =
1208+ Item :: from_def_id_and_parts ( self . def_id , Some ( self . name ) , kind, cx) ;
1209+
1210+ let impl_ref = tcx. parent ( self . def_id ) . and_then ( |did| tcx. impl_trait_ref ( did) ) ;
1211+
1212+ // Trait impl items always inherit the impl's visibility --
1213+ // we don't want to show `pub`.
1214+ if impl_ref. is_some ( ) {
1215+ what_rustc_thinks. visibility = Visibility :: Inherited ;
1216+ }
1217+
1218+ what_rustc_thinks
12031219 }
12041220}
12051221
@@ -1478,8 +1494,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
14781494 ty:: FnDef ( ..) | ty:: FnPtr ( _) => {
14791495 let ty = cx. tcx . lift ( * self ) . expect ( "FnPtr lift failed" ) ;
14801496 let sig = ty. fn_sig ( cx. tcx ) ;
1481- let def_id = DefId :: local ( CRATE_DEF_INDEX ) ;
1482- let decl = clean_fn_decl_from_did_and_sig ( cx, def_id, sig) ;
1497+ let decl = clean_fn_decl_from_did_and_sig ( cx, None , sig) ;
14831498 BareFunction ( box BareFunctionDecl {
14841499 unsafety : sig. unsafety ( ) ,
14851500 generic_params : Vec :: new ( ) ,
0 commit comments