Skip to content

Commit

Permalink
Remove unnecessary is_trait argument
Browse files Browse the repository at this point in the history
It was only used for sugaring `Fn` trait bounds, and rustdoc already
checks that the `did` is for a `Fn` (or `FnMut`, `FnOnce`) lang item,
so it's not necessary to also check that the `did` belongs to a trait.
  • Loading branch information
camelid committed Sep 11, 2021
1 parent 5321b35 commit 913764d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
11 changes: 5 additions & 6 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -164,8 +164,7 @@ 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, true, true, bounds.to_vec(), trait_ref.substs);
let path = external_path(cx, trait_ref.def_id, true, bounds.to_vec(), trait_ref.substs);

debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);

Expand Down Expand Up @@ -1442,12 +1441,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, false, false, vec![], substs);
let path = external_path(cx, did, 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, false, false, vec![], InternalSubsts::empty());
let path = external_path(cx, did, false, vec![], InternalSubsts::empty());
ResolvedPath { path, did, is_generic: false }
}
ty::Dynamic(ref obj, ref reg) => {
Expand All @@ -1471,7 +1470,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {

for did in dids {
let empty = cx.tcx.intern_substs(&[]);
let path = external_path(cx, did, true, false, vec![], empty);
let path = external_path(cx, did, false, vec![], empty);
inline::record_extern_fqn(cx, did, ItemType::Trait);
let bound = PolyTrait {
trait_: ResolvedPath { path, did, is_generic: false },
Expand All @@ -1488,7 +1487,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
});
}

let path = external_path(cx, did, true, false, bindings, substs);
let path = external_path(cx, did, false, bindings, substs);
bounds.insert(
0,
PolyTrait {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/types.rs
Expand Up @@ -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, true, false, vec![], empty);
let path = external_path(cx, did, false, vec![], empty);
inline::record_extern_fqn(cx, did, ItemType::Trait);
GenericBound::TraitBound(
PolyTrait {
Expand Down
8 changes: 2 additions & 6 deletions src/librustdoc/clean/utils.rs
Expand Up @@ -94,7 +94,6 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
fn external_generic_args(
cx: &mut DocContext<'_>,
did: DefId,
is_trait: bool,
has_self: bool,
bindings: Vec<TypeBinding>,
substs: SubstsRef<'_>,
Expand Down Expand Up @@ -122,7 +121,7 @@ fn external_generic_args(
})
.collect();

if is_trait && cx.tcx.fn_trait_kind_from_lang_item(did).is_some() {
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(),
Expand All @@ -140,12 +139,9 @@ fn external_generic_args(
}
}

/// `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,
is_trait: bool,
has_self: bool,
bindings: Vec<TypeBinding>,
substs: SubstsRef<'_>,
Expand All @@ -157,7 +153,7 @@ pub(super) fn external_path(
res: Res::Def(def_kind, did),
segments: vec![PathSegment {
name,
args: external_generic_args(cx, did, is_trait, has_self, bindings, substs),
args: external_generic_args(cx, did, has_self, bindings, substs),
}],
}
}
Expand Down

0 comments on commit 913764d

Please sign in to comment.