1
Fork 0

remove Clean trait implementation for hir::GenericBound

This commit is contained in:
Guillaume Gomez 2022-08-06 11:52:27 +02:00
parent 46d17d6aaa
commit ca70ed8c81

View file

@ -126,40 +126,40 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
} }
} }
impl<'tcx> Clean<'tcx, Option<GenericBound>> for hir::GenericBound<'tcx> { fn clean_generic_bound<'tcx>(
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<GenericBound> { bound: &hir::GenericBound<'tcx>,
Some(match *self { cx: &mut DocContext<'tcx>,
hir::GenericBound::Outlives(lt) => GenericBound::Outlives(clean_lifetime(lt, cx)), ) -> Option<GenericBound> {
hir::GenericBound::LangItemTrait(lang_item, span, _, generic_args) => { Some(match *bound {
let def_id = cx.tcx.require_lang_item(lang_item, Some(span)); hir::GenericBound::Outlives(lt) => GenericBound::Outlives(clean_lifetime(lt, cx)),
hir::GenericBound::LangItemTrait(lang_item, span, _, generic_args) => {
let def_id = cx.tcx.require_lang_item(lang_item, Some(span));
let trait_ref = ty::TraitRef::identity(cx.tcx, def_id).skip_binder(); let trait_ref = ty::TraitRef::identity(cx.tcx, def_id).skip_binder();
let generic_args = generic_args.clean(cx); let generic_args = generic_args.clean(cx);
let GenericArgs::AngleBracketed { bindings, .. } = generic_args let GenericArgs::AngleBracketed { bindings, .. } = generic_args
else { else {
bug!("clean: parenthesized `GenericBound::LangItemTrait`"); bug!("clean: parenthesized `GenericBound::LangItemTrait`");
}; };
let trait_ = clean_trait_ref_with_bindings(cx, trait_ref, &bindings); let trait_ = clean_trait_ref_with_bindings(cx, trait_ref, &bindings);
GenericBound::TraitBound( GenericBound::TraitBound(
PolyTrait { trait_, generic_params: vec![] }, PolyTrait { trait_, generic_params: vec![] },
hir::TraitBoundModifier::None, hir::TraitBoundModifier::None,
) )
}
hir::GenericBound::Trait(ref t, modifier) => {
// `T: ~const Destruct` is hidden because `T: Destruct` is a no-op.
if modifier == hir::TraitBoundModifier::MaybeConst
&& cx.tcx.lang_items().destruct_trait() == Some(t.trait_ref.trait_def_id().unwrap())
{
return None;
} }
hir::GenericBound::Trait(ref t, modifier) => {
// `T: ~const Destruct` is hidden because `T: Destruct` is a no-op.
if modifier == hir::TraitBoundModifier::MaybeConst
&& cx.tcx.lang_items().destruct_trait()
== Some(t.trait_ref.trait_def_id().unwrap())
{
return None;
}
GenericBound::TraitBound(clean_poly_trait_ref(t, cx), modifier) GenericBound::TraitBound(clean_poly_trait_ref(t, cx), modifier)
} }
}) })
}
} }
pub(crate) fn clean_trait_ref_with_bindings<'tcx>( pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
@ -294,14 +294,14 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for hir::WherePredicate<'tcx> {
.collect(); .collect();
WherePredicate::BoundPredicate { WherePredicate::BoundPredicate {
ty: clean_ty(wbp.bounded_ty, cx), ty: clean_ty(wbp.bounded_ty, cx),
bounds: wbp.bounds.iter().filter_map(|x| x.clean(cx)).collect(), bounds: wbp.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
bound_params, bound_params,
} }
} }
hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate { hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate {
lifetime: clean_lifetime(wrp.lifetime, cx), lifetime: clean_lifetime(wrp.lifetime, cx),
bounds: wrp.bounds.iter().filter_map(|x| x.clean(cx)).collect(), bounds: wrp.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
}, },
hir::WherePredicate::EqPredicate(ref wrp) => WherePredicate::EqPredicate { hir::WherePredicate::EqPredicate(ref wrp) => WherePredicate::EqPredicate {
@ -531,7 +531,7 @@ fn clean_generic_param<'tcx>(
.bounds_for_param(did) .bounds_for_param(did)
.filter(|bp| bp.origin != PredicateOrigin::WhereClause) .filter(|bp| bp.origin != PredicateOrigin::WhereClause)
.flat_map(|bp| bp.bounds) .flat_map(|bp| bp.bounds)
.filter_map(|x| x.clean(cx)) .filter_map(|x| clean_generic_bound(x, cx))
.collect() .collect()
} else { } else {
Vec::new() Vec::new()
@ -1041,7 +1041,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
} }
hir::TraitItemKind::Type(bounds, Some(default)) => { hir::TraitItemKind::Type(bounds, Some(default)) => {
let generics = enter_impl_trait(cx, |cx| trait_item.generics.clean(cx)); let generics = enter_impl_trait(cx, |cx| trait_item.generics.clean(cx));
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect(); let bounds = bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect();
let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, default), cx, None); let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, default), cx, None);
AssocTypeItem( AssocTypeItem(
Box::new(Typedef { Box::new(Typedef {
@ -1054,7 +1054,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
} }
hir::TraitItemKind::Type(bounds, None) => { hir::TraitItemKind::Type(bounds, None) => {
let generics = enter_impl_trait(cx, |cx| trait_item.generics.clean(cx)); let generics = enter_impl_trait(cx, |cx| trait_item.generics.clean(cx));
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect(); let bounds = bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect();
TyAssocTypeItem(Box::new(generics), bounds) TyAssocTypeItem(Box::new(generics), bounds)
} }
}; };
@ -1507,7 +1507,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
TyKind::OpaqueDef(item_id, _) => { TyKind::OpaqueDef(item_id, _) => {
let item = cx.tcx.hir().item(item_id); let item = cx.tcx.hir().item(item_id);
if let hir::ItemKind::OpaqueTy(ref ty) = item.kind { if let hir::ItemKind::OpaqueTy(ref ty) = item.kind {
ImplTrait(ty.bounds.iter().filter_map(|x| x.clean(cx)).collect()) ImplTrait(ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect())
} else { } else {
unreachable!() unreachable!()
} }
@ -1911,7 +1911,7 @@ fn clean_maybe_renamed_item<'tcx>(
kind: ConstantKind::Local { body: body_id, def_id }, kind: ConstantKind::Local { body: body_id, def_id },
}), }),
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy { ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
bounds: ty.bounds.iter().filter_map(|x| x.clean(cx)).collect(), bounds: ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
generics: ty.generics.clean(cx), generics: ty.generics.clean(cx),
}), }),
ItemKind::TyAlias(hir_ty, generics) => { ItemKind::TyAlias(hir_ty, generics) => {
@ -1929,7 +1929,7 @@ fn clean_maybe_renamed_item<'tcx>(
}), }),
ItemKind::TraitAlias(generics, bounds) => TraitAliasItem(TraitAlias { ItemKind::TraitAlias(generics, bounds) => TraitAliasItem(TraitAlias {
generics: generics.clean(cx), generics: generics.clean(cx),
bounds: bounds.iter().filter_map(|x| x.clean(cx)).collect(), bounds: bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
}), }),
ItemKind::Union(ref variant_data, generics) => UnionItem(Union { ItemKind::Union(ref variant_data, generics) => UnionItem(Union {
generics: generics.clean(cx), generics: generics.clean(cx),
@ -1961,7 +1961,7 @@ fn clean_maybe_renamed_item<'tcx>(
def_id, def_id,
items, items,
generics: generics.clean(cx), generics: generics.clean(cx),
bounds: bounds.iter().filter_map(|x| x.clean(cx)).collect(), bounds: bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
}) })
} }
ItemKind::ExternCrate(orig_name) => { ItemKind::ExternCrate(orig_name) => {
@ -2241,7 +2241,7 @@ fn clean_type_binding<'tcx>(
TypeBindingKind::Equality { term: clean_hir_term(term, cx) } TypeBindingKind::Equality { term: clean_hir_term(term, cx) }
} }
hir::TypeBindingKind::Constraint { bounds } => TypeBindingKind::Constraint { hir::TypeBindingKind::Constraint { bounds } => TypeBindingKind::Constraint {
bounds: bounds.iter().filter_map(|b| b.clean(cx)).collect(), bounds: bounds.iter().filter_map(|b| clean_generic_bound(b, cx)).collect(),
}, },
}, },
} }