1
Fork 0

Fix redundant arguments in external_path()

If the path is for a trait, it is always true that `trait_did ==
Some(did)`, so instead, `external_path()` now takes an `is_trait`
boolean.
This commit is contained in:
Noah Lev 2021-09-11 15:43:44 -07:00
parent c2207f5a48
commit 5321b35a5a
3 changed files with 27 additions and 34 deletions

View file

@ -93,7 +93,8 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
fn external_generic_args(
cx: &mut DocContext<'_>,
trait_did: Option<DefId>,
did: DefId,
is_trait: bool,
has_self: bool,
bindings: Vec<TypeBinding>,
substs: SubstsRef<'_>,
@ -121,32 +122,30 @@ fn external_generic_args(
})
.collect();
match trait_did {
// Attempt to sugar an external path like Fn<(A, B,), C> to Fn(A, B) -> C
Some(did) if cx.tcx.fn_trait_kind_from_lang_item(did).is_some() => {
assert!(ty_kind.is_some());
let inputs = match ty_kind {
Some(ty::Tuple(ref tys)) => tys.iter().map(|t| t.expect_ty().clean(cx)).collect(),
_ => return GenericArgs::AngleBracketed { args, bindings },
};
let output = None;
// FIXME(#20299) return type comes from a projection now
// match types[1].kind {
// ty::Tuple(ref v) if v.is_empty() => None, // -> ()
// _ => Some(types[1].clean(cx))
// };
GenericArgs::Parenthesized { inputs, output }
}
_ => GenericArgs::AngleBracketed { args, bindings },
if is_trait && cx.tcx.fn_trait_kind_from_lang_item(did).is_some() {
assert!(ty_kind.is_some());
let inputs = match ty_kind {
Some(ty::Tuple(ref tys)) => tys.iter().map(|t| t.expect_ty().clean(cx)).collect(),
_ => return GenericArgs::AngleBracketed { args, bindings },
};
let output = None;
// FIXME(#20299) return type comes from a projection now
// match types[1].kind {
// ty::Tuple(ref v) if v.is_empty() => None, // -> ()
// _ => Some(types[1].clean(cx))
// };
GenericArgs::Parenthesized { inputs, output }
} else {
GenericArgs::AngleBracketed { args, bindings }
}
}
/// trait_did should be set to a trait's DefId if called on a TraitRef, in order to sugar
/// `is_trait` should be set to `true` if called on a `TraitRef`, in order to sugar
/// from `Fn<(A, B,), C>` to `Fn(A, B) -> C`
pub(super) fn external_path(
cx: &mut DocContext<'_>,
did: DefId,
trait_did: Option<DefId>,
is_trait: bool,
has_self: bool,
bindings: Vec<TypeBinding>,
substs: SubstsRef<'_>,
@ -158,7 +157,7 @@ pub(super) fn external_path(
res: Res::Def(def_kind, did),
segments: vec![PathSegment {
name,
args: external_generic_args(cx, trait_did, has_self, bindings, substs),
args: external_generic_args(cx, did, is_trait, has_self, bindings, substs),
}],
}
}