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:
parent
c2207f5a48
commit
5321b35a5a
3 changed files with 27 additions and 34 deletions
|
@ -164,14 +164,8 @@ impl Clean<Type> for (ty::TraitRef<'_>, &[TypeBinding]) {
|
|||
);
|
||||
}
|
||||
inline::record_extern_fqn(cx, trait_ref.def_id, kind);
|
||||
let path = external_path(
|
||||
cx,
|
||||
trait_ref.def_id,
|
||||
Some(trait_ref.def_id),
|
||||
true,
|
||||
bounds.to_vec(),
|
||||
trait_ref.substs,
|
||||
);
|
||||
let path =
|
||||
external_path(cx, trait_ref.def_id, true, true, bounds.to_vec(), trait_ref.substs);
|
||||
|
||||
debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);
|
||||
|
||||
|
@ -1448,12 +1442,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
|||
AdtKind::Enum => ItemType::Enum,
|
||||
};
|
||||
inline::record_extern_fqn(cx, did, kind);
|
||||
let path = external_path(cx, did, None, false, vec![], substs);
|
||||
let path = external_path(cx, did, false, false, vec![], substs);
|
||||
ResolvedPath { path, did, is_generic: false }
|
||||
}
|
||||
ty::Foreign(did) => {
|
||||
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
|
||||
let path = external_path(cx, did, None, false, vec![], InternalSubsts::empty());
|
||||
let path = external_path(cx, did, false, false, vec![], InternalSubsts::empty());
|
||||
ResolvedPath { path, did, is_generic: false }
|
||||
}
|
||||
ty::Dynamic(ref obj, ref reg) => {
|
||||
|
@ -1477,7 +1471,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
|||
|
||||
for did in dids {
|
||||
let empty = cx.tcx.intern_substs(&[]);
|
||||
let path = external_path(cx, did, Some(did), false, vec![], empty);
|
||||
let path = external_path(cx, did, true, false, vec![], empty);
|
||||
inline::record_extern_fqn(cx, did, ItemType::Trait);
|
||||
let bound = PolyTrait {
|
||||
trait_: ResolvedPath { path, did, is_generic: false },
|
||||
|
@ -1494,7 +1488,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
|||
});
|
||||
}
|
||||
|
||||
let path = external_path(cx, did, Some(did), false, bindings, substs);
|
||||
let path = external_path(cx, did, true, false, bindings, substs);
|
||||
bounds.insert(
|
||||
0,
|
||||
PolyTrait {
|
||||
|
|
|
@ -1158,7 +1158,7 @@ impl GenericBound {
|
|||
crate fn maybe_sized(cx: &mut DocContext<'_>) -> GenericBound {
|
||||
let did = cx.tcx.require_lang_item(LangItem::Sized, None);
|
||||
let empty = cx.tcx.intern_substs(&[]);
|
||||
let path = external_path(cx, did, Some(did), false, vec![], empty);
|
||||
let path = external_path(cx, did, true, false, vec![], empty);
|
||||
inline::record_extern_fqn(cx, did, ItemType::Trait);
|
||||
GenericBound::TraitBound(
|
||||
PolyTrait {
|
||||
|
|
|
@ -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),
|
||||
}],
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue