@@ -891,13 +891,20 @@ fn clean_fn_decl_with_args(
891
891
892
892
fn clean_fn_decl_from_did_and_sig (
893
893
cx : & mut DocContext < ' _ > ,
894
- did : DefId ,
894
+ did : Option < DefId > ,
895
895
sig : ty:: PolyFnSig < ' _ > ,
896
896
) -> 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
+ } ;
898
905
899
906
FnDecl {
900
- output : Return ( sig . skip_binder ( ) . output ( ) . clean ( cx ) ) ,
907
+ output,
901
908
c_variadic : sig. skip_binder ( ) . c_variadic ,
902
909
inputs : Arguments {
903
910
values : sig
@@ -1031,20 +1038,18 @@ impl Clean<Item> for hir::ImplItem<'_> {
1031
1038
}
1032
1039
} ;
1033
1040
1034
- let what_rustc_thinks =
1041
+ let mut what_rustc_thinks =
1035
1042
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 ;
1047
1050
}
1051
+
1052
+ what_rustc_thinks
1048
1053
} )
1049
1054
}
1050
1055
}
@@ -1069,7 +1074,7 @@ impl Clean<Item> for ty::AssocItem {
1069
1074
tcx. explicit_predicates_of ( self . def_id ) ,
1070
1075
) ;
1071
1076
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) ;
1073
1078
1074
1079
if self . fn_has_self_parameter {
1075
1080
let self_ty = match self . container {
@@ -1199,7 +1204,18 @@ impl Clean<Item> for ty::AssocItem {
1199
1204
}
1200
1205
} ;
1201
1206
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
1203
1219
}
1204
1220
}
1205
1221
@@ -1478,8 +1494,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
1478
1494
ty:: FnDef ( ..) | ty:: FnPtr ( _) => {
1479
1495
let ty = cx. tcx . lift ( * self ) . expect ( "FnPtr lift failed" ) ;
1480
1496
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) ;
1483
1498
BareFunction ( box BareFunctionDecl {
1484
1499
unsafety : sig. unsafety ( ) ,
1485
1500
generic_params : Vec :: new ( ) ,
0 commit comments