Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: remove Clean trait impls for more items #99783

Merged
merged 4 commits into from
Jul 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 61 additions & 58 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,12 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for ty::Predicate<'tcx> {
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<WherePredicate> {
let bound_predicate = self.kind();
match bound_predicate.skip_binder() {
ty::PredicateKind::Trait(pred) => bound_predicate.rebind(pred).clean(cx),
ty::PredicateKind::RegionOutlives(pred) => pred.clean(cx),
ty::PredicateKind::TypeOutlives(pred) => pred.clean(cx),
ty::PredicateKind::Projection(pred) => Some(pred.clean(cx)),
ty::PredicateKind::Trait(pred) => {
clean_poly_trait_predicate(bound_predicate.rebind(pred), cx)
}
ty::PredicateKind::RegionOutlives(pred) => clean_region_outlives_predicate(pred, cx),
ty::PredicateKind::TypeOutlives(pred) => clean_type_outlives_predicate(pred, cx),
ty::PredicateKind::Projection(pred) => Some(clean_projection_predicate(pred, cx)),
ty::PredicateKind::ConstEvaluatable(..) => None,
ty::PredicateKind::WellFormed(..) => None,

Expand All @@ -344,57 +346,56 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for ty::Predicate<'tcx> {
}
}

impl<'tcx> Clean<'tcx, Option<WherePredicate>> for ty::PolyTraitPredicate<'tcx> {
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<WherePredicate> {
// `T: ~const Destruct` is hidden because `T: Destruct` is a no-op.
if self.skip_binder().constness == ty::BoundConstness::ConstIfConst
&& Some(self.skip_binder().def_id()) == cx.tcx.lang_items().destruct_trait()
{
return None;
}

let poly_trait_ref = self.map_bound(|pred| pred.trait_ref);
Some(WherePredicate::BoundPredicate {
ty: clean_middle_ty(poly_trait_ref.skip_binder().self_ty(), cx, None),
bounds: vec![poly_trait_ref.clean(cx)],
bound_params: Vec::new(),
})
fn clean_poly_trait_predicate<'tcx>(
pred: ty::PolyTraitPredicate<'tcx>,
cx: &mut DocContext<'tcx>,
) -> Option<WherePredicate> {
// `T: ~const Destruct` is hidden because `T: Destruct` is a no-op.
if pred.skip_binder().constness == ty::BoundConstness::ConstIfConst
&& Some(pred.skip_binder().def_id()) == cx.tcx.lang_items().destruct_trait()
{
return None;
}
}

impl<'tcx> Clean<'tcx, Option<WherePredicate>>
for ty::OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>
{
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<WherePredicate> {
let ty::OutlivesPredicate(a, b) = self;
let poly_trait_ref = pred.map_bound(|pred| pred.trait_ref);
Some(WherePredicate::BoundPredicate {
ty: clean_middle_ty(poly_trait_ref.skip_binder().self_ty(), cx, None),
bounds: vec![poly_trait_ref.clean(cx)],
bound_params: Vec::new(),
})
}

if a.is_empty() && b.is_empty() {
return None;
}
fn clean_region_outlives_predicate<'tcx>(
pred: ty::OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>,
cx: &mut DocContext<'tcx>,
) -> Option<WherePredicate> {
let ty::OutlivesPredicate(a, b) = pred;

Some(WherePredicate::RegionPredicate {
lifetime: a.clean(cx).expect("failed to clean lifetime"),
bounds: vec![GenericBound::Outlives(b.clean(cx).expect("failed to clean bounds"))],
})
if a.is_empty() && b.is_empty() {
return None;
}
}

impl<'tcx> Clean<'tcx, Option<WherePredicate>>
for ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>
{
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<WherePredicate> {
let ty::OutlivesPredicate(ty, lt) = self;
Some(WherePredicate::RegionPredicate {
lifetime: a.clean(cx).expect("failed to clean lifetime"),
bounds: vec![GenericBound::Outlives(b.clean(cx).expect("failed to clean bounds"))],
})
}

if lt.is_empty() {
return None;
}
fn clean_type_outlives_predicate<'tcx>(
pred: ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>,
cx: &mut DocContext<'tcx>,
) -> Option<WherePredicate> {
let ty::OutlivesPredicate(ty, lt) = pred;

Some(WherePredicate::BoundPredicate {
ty: clean_middle_ty(*ty, cx, None),
bounds: vec![GenericBound::Outlives(lt.clean(cx).expect("failed to clean lifetimes"))],
bound_params: Vec::new(),
})
if lt.is_empty() {
return None;
}

Some(WherePredicate::BoundPredicate {
ty: clean_middle_ty(ty, cx, None),
bounds: vec![GenericBound::Outlives(lt.clean(cx).expect("failed to clean lifetimes"))],
bound_params: Vec::new(),
})
}

impl<'tcx> Clean<'tcx, Term> for ty::Term<'tcx> {
Expand All @@ -418,10 +419,14 @@ impl<'tcx> Clean<'tcx, Term> for hir::Term<'tcx> {
}
}

impl<'tcx> Clean<'tcx, WherePredicate> for ty::ProjectionPredicate<'tcx> {
fn clean(&self, cx: &mut DocContext<'tcx>) -> WherePredicate {
let ty::ProjectionPredicate { projection_ty, term } = self;
WherePredicate::EqPredicate { lhs: projection_ty.clean(cx), rhs: term.clean(cx) }
fn clean_projection_predicate<'tcx>(
pred: ty::ProjectionPredicate<'tcx>,
cx: &mut DocContext<'tcx>,
) -> WherePredicate {
let ty::ProjectionPredicate { projection_ty, term } = pred;
WherePredicate::EqPredicate {
lhs: clean_projection(projection_ty, cx, None),
rhs: term.clean(cx),
}
}

Expand All @@ -447,12 +452,6 @@ fn clean_projection<'tcx>(
}
}

impl<'tcx> Clean<'tcx, Type> for ty::ProjectionTy<'tcx> {
fn clean(&self, cx: &mut DocContext<'tcx>) -> Type {
clean_projection(*self, cx, None)
}
}

fn compute_should_show_cast(self_def_id: Option<DefId>, trait_: &Path, self_type: &Type) -> bool {
!trait_.segments.is_empty()
&& self_def_id
Expand Down Expand Up @@ -734,8 +733,12 @@ fn clean_ty_generics<'tcx>(
.filter(|b| !b.is_sized_bound(cx)),
);

let proj = projection
.map(|p| (p.skip_binder().projection_ty.clean(cx), p.skip_binder().term));
let proj = projection.map(|p| {
(
clean_projection(p.skip_binder().projection_ty, cx, None),
p.skip_binder().term,
)
});
if let Some(((_, trait_did, name), rhs)) = proj
.as_ref()
.and_then(|(lhs, rhs): &(Type, _)| Some((lhs.projection()?, rhs)))
Expand Down