Skip to content

Commit 65cc68b

Browse files
authored
Rollup merge of rust-lang#100212 - GuillaumeGomez:rm-clean-impls, r=Dylan-DPC
Remove more Clean trait implementations Follow-up of rust-lang#99638. r? `@notriddle`
2 parents a1829bb + a238d12 commit 65cc68b

File tree

2 files changed

+64
-58
lines changed

2 files changed

+64
-58
lines changed

src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ where
474474
let mut ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)> = Default::default();
475475

476476
for p in clean_where_predicates {
477-
let (orig_p, p) = (p, p.clean(self.cx));
477+
let (orig_p, p) = (p, clean_predicate(p, self.cx));
478478
if p.is_none() {
479479
continue;
480480
}

src/librustdoc/clean/mod.rs

+63-57
Original file line numberDiff line numberDiff line change
@@ -259,66 +259,68 @@ pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Life
259259
}
260260
}
261261

262-
impl<'tcx> Clean<'tcx, Option<WherePredicate>> for hir::WherePredicate<'tcx> {
263-
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<WherePredicate> {
264-
if !self.in_where_clause() {
265-
return None;
266-
}
267-
Some(match *self {
268-
hir::WherePredicate::BoundPredicate(ref wbp) => {
269-
let bound_params = wbp
270-
.bound_generic_params
271-
.iter()
272-
.map(|param| {
273-
// Higher-ranked params must be lifetimes.
274-
// Higher-ranked lifetimes can't have bounds.
275-
assert_matches!(
276-
param,
277-
hir::GenericParam { kind: hir::GenericParamKind::Lifetime { .. }, .. }
278-
);
279-
Lifetime(param.name.ident().name)
280-
})
281-
.collect();
282-
WherePredicate::BoundPredicate {
283-
ty: clean_ty(wbp.bounded_ty, cx),
284-
bounds: wbp.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
285-
bound_params,
286-
}
262+
fn clean_where_predicate<'tcx>(
263+
predicate: &hir::WherePredicate<'tcx>,
264+
cx: &mut DocContext<'tcx>,
265+
) -> Option<WherePredicate> {
266+
if !predicate.in_where_clause() {
267+
return None;
268+
}
269+
Some(match *predicate {
270+
hir::WherePredicate::BoundPredicate(ref wbp) => {
271+
let bound_params = wbp
272+
.bound_generic_params
273+
.iter()
274+
.map(|param| {
275+
// Higher-ranked params must be lifetimes.
276+
// Higher-ranked lifetimes can't have bounds.
277+
assert_matches!(
278+
param,
279+
hir::GenericParam { kind: hir::GenericParamKind::Lifetime { .. }, .. }
280+
);
281+
Lifetime(param.name.ident().name)
282+
})
283+
.collect();
284+
WherePredicate::BoundPredicate {
285+
ty: clean_ty(wbp.bounded_ty, cx),
286+
bounds: wbp.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
287+
bound_params,
287288
}
289+
}
288290

289-
hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate {
290-
lifetime: clean_lifetime(wrp.lifetime, cx),
291-
bounds: wrp.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
292-
},
291+
hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate {
292+
lifetime: clean_lifetime(wrp.lifetime, cx),
293+
bounds: wrp.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
294+
},
293295

294-
hir::WherePredicate::EqPredicate(ref wrp) => WherePredicate::EqPredicate {
295-
lhs: clean_ty(wrp.lhs_ty, cx),
296-
rhs: clean_ty(wrp.rhs_ty, cx).into(),
297-
},
298-
})
299-
}
296+
hir::WherePredicate::EqPredicate(ref wrp) => WherePredicate::EqPredicate {
297+
lhs: clean_ty(wrp.lhs_ty, cx),
298+
rhs: clean_ty(wrp.rhs_ty, cx).into(),
299+
},
300+
})
300301
}
301302

302-
impl<'tcx> Clean<'tcx, Option<WherePredicate>> for ty::Predicate<'tcx> {
303-
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<WherePredicate> {
304-
let bound_predicate = self.kind();
305-
match bound_predicate.skip_binder() {
306-
ty::PredicateKind::Trait(pred) => {
307-
clean_poly_trait_predicate(bound_predicate.rebind(pred), cx)
308-
}
309-
ty::PredicateKind::RegionOutlives(pred) => clean_region_outlives_predicate(pred),
310-
ty::PredicateKind::TypeOutlives(pred) => clean_type_outlives_predicate(pred, cx),
311-
ty::PredicateKind::Projection(pred) => Some(clean_projection_predicate(pred, cx)),
312-
ty::PredicateKind::ConstEvaluatable(..) => None,
313-
ty::PredicateKind::WellFormed(..) => None,
314-
315-
ty::PredicateKind::Subtype(..)
316-
| ty::PredicateKind::Coerce(..)
317-
| ty::PredicateKind::ObjectSafe(..)
318-
| ty::PredicateKind::ClosureKind(..)
319-
| ty::PredicateKind::ConstEquate(..)
320-
| ty::PredicateKind::TypeWellFormedFromEnv(..) => panic!("not user writable"),
303+
pub(crate) fn clean_predicate<'tcx>(
304+
predicate: ty::Predicate<'tcx>,
305+
cx: &mut DocContext<'tcx>,
306+
) -> Option<WherePredicate> {
307+
let bound_predicate = predicate.kind();
308+
match bound_predicate.skip_binder() {
309+
ty::PredicateKind::Trait(pred) => {
310+
clean_poly_trait_predicate(bound_predicate.rebind(pred), cx)
321311
}
312+
ty::PredicateKind::RegionOutlives(pred) => clean_region_outlives_predicate(pred),
313+
ty::PredicateKind::TypeOutlives(pred) => clean_type_outlives_predicate(pred, cx),
314+
ty::PredicateKind::Projection(pred) => Some(clean_projection_predicate(pred, cx)),
315+
ty::PredicateKind::ConstEvaluatable(..) => None,
316+
ty::PredicateKind::WellFormed(..) => None,
317+
318+
ty::PredicateKind::Subtype(..)
319+
| ty::PredicateKind::Coerce(..)
320+
| ty::PredicateKind::ObjectSafe(..)
321+
| ty::PredicateKind::ClosureKind(..)
322+
| ty::PredicateKind::ConstEquate(..)
323+
| ty::PredicateKind::TypeWellFormedFromEnv(..) => panic!("not user writable"),
322324
}
323325
}
324326

@@ -594,7 +596,11 @@ impl<'tcx> Clean<'tcx, Generics> for hir::Generics<'tcx> {
594596

595597
let mut generics = Generics {
596598
params,
597-
where_predicates: self.predicates.iter().filter_map(|x| x.clean(cx)).collect(),
599+
where_predicates: self
600+
.predicates
601+
.iter()
602+
.filter_map(|x| clean_where_predicate(x, cx))
603+
.collect(),
598604
};
599605

600606
// Some duplicates are generated for ?Sized bounds between type params and where
@@ -695,7 +701,7 @@ fn clean_ty_generics<'tcx>(
695701

696702
if let Some(param_idx) = param_idx {
697703
if let Some(b) = impl_trait.get_mut(&param_idx.into()) {
698-
let p: WherePredicate = p.clean(cx)?;
704+
let p: WherePredicate = clean_predicate(*p, cx)?;
699705

700706
b.extend(
701707
p.get_bounds()
@@ -752,7 +758,7 @@ fn clean_ty_generics<'tcx>(
752758
// Now that `cx.impl_trait_bounds` is populated, we can process
753759
// remaining predicates which could contain `impl Trait`.
754760
let mut where_predicates =
755-
where_predicates.into_iter().flat_map(|p| p.clean(cx)).collect::<Vec<_>>();
761+
where_predicates.into_iter().flat_map(|p| clean_predicate(*p, cx)).collect::<Vec<_>>();
756762

757763
// Type parameters have a Sized bound by default unless removed with
758764
// ?Sized. Scan through the predicates and mark any type parameter with

0 commit comments

Comments
 (0)