Skip to content

Commit a72e96c

Browse files
remove Clean trait implementation for ty::Region
1 parent e141246 commit a72e96c

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

src/librustdoc/clean/mod.rs

+30-29
Original file line numberDiff line numberDiff line change
@@ -242,30 +242,28 @@ pub(crate) fn clean_middle_const<'tcx>(
242242
}
243243
}
244244

245-
impl<'tcx> Clean<'tcx, Option<Lifetime>> for ty::Region<'tcx> {
246-
fn clean(&self, _cx: &mut DocContext<'_>) -> Option<Lifetime> {
247-
match **self {
248-
ty::ReStatic => Some(Lifetime::statik()),
249-
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrNamed(_, name), .. }) => {
250-
if name != kw::UnderscoreLifetime { Some(Lifetime(name)) } else { None }
251-
}
252-
ty::ReEarlyBound(ref data) => {
253-
if data.name != kw::UnderscoreLifetime {
254-
Some(Lifetime(data.name))
255-
} else {
256-
None
257-
}
258-
}
259-
ty::ReLateBound(..)
260-
| ty::ReFree(..)
261-
| ty::ReVar(..)
262-
| ty::RePlaceholder(..)
263-
| ty::ReEmpty(_)
264-
| ty::ReErased => {
265-
debug!("cannot clean region {:?}", self);
245+
pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Lifetime> {
246+
match *region {
247+
ty::ReStatic => Some(Lifetime::statik()),
248+
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrNamed(_, name), .. }) => {
249+
if name != kw::UnderscoreLifetime { Some(Lifetime(name)) } else { None }
250+
}
251+
ty::ReEarlyBound(ref data) => {
252+
if data.name != kw::UnderscoreLifetime {
253+
Some(Lifetime(data.name))
254+
} else {
266255
None
267256
}
268257
}
258+
ty::ReLateBound(..)
259+
| ty::ReFree(..)
260+
| ty::ReVar(..)
261+
| ty::RePlaceholder(..)
262+
| ty::ReEmpty(_)
263+
| ty::ReErased => {
264+
debug!("cannot clean region {:?}", region);
265+
None
266+
}
269267
}
270268
}
271269

@@ -316,7 +314,7 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for ty::Predicate<'tcx> {
316314
ty::PredicateKind::Trait(pred) => {
317315
clean_poly_trait_predicate(bound_predicate.rebind(pred), cx)
318316
}
319-
ty::PredicateKind::RegionOutlives(pred) => clean_region_outlives_predicate(pred, cx),
317+
ty::PredicateKind::RegionOutlives(pred) => clean_region_outlives_predicate(pred),
320318
ty::PredicateKind::TypeOutlives(pred) => clean_type_outlives_predicate(pred, cx),
321319
ty::PredicateKind::Projection(pred) => Some(clean_projection_predicate(pred, cx)),
322320
ty::PredicateKind::ConstEvaluatable(..) => None,
@@ -353,7 +351,6 @@ fn clean_poly_trait_predicate<'tcx>(
353351

354352
fn clean_region_outlives_predicate<'tcx>(
355353
pred: ty::OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>,
356-
cx: &mut DocContext<'tcx>,
357354
) -> Option<WherePredicate> {
358355
let ty::OutlivesPredicate(a, b) = pred;
359356

@@ -362,8 +359,10 @@ fn clean_region_outlives_predicate<'tcx>(
362359
}
363360

364361
Some(WherePredicate::RegionPredicate {
365-
lifetime: a.clean(cx).expect("failed to clean lifetime"),
366-
bounds: vec![GenericBound::Outlives(b.clean(cx).expect("failed to clean bounds"))],
362+
lifetime: clean_middle_region(a).expect("failed to clean lifetime"),
363+
bounds: vec![GenericBound::Outlives(
364+
clean_middle_region(b).expect("failed to clean bounds"),
365+
)],
367366
})
368367
}
369368

@@ -379,7 +378,9 @@ fn clean_type_outlives_predicate<'tcx>(
379378

380379
Some(WherePredicate::BoundPredicate {
381380
ty: clean_middle_ty(ty, cx, None),
382-
bounds: vec![GenericBound::Outlives(lt.clean(cx).expect("failed to clean lifetimes"))],
381+
bounds: vec![GenericBound::Outlives(
382+
clean_middle_region(lt).expect("failed to clean lifetimes"),
383+
)],
383384
bound_params: Vec::new(),
384385
})
385386
}
@@ -1592,7 +1593,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
15921593
}
15931594
ty::RawPtr(mt) => RawPointer(mt.mutbl, Box::new(clean_middle_ty(mt.ty, cx, None))),
15941595
ty::Ref(r, ty, mutbl) => BorrowedRef {
1595-
lifetime: r.clean(cx),
1596+
lifetime: clean_middle_region(r),
15961597
mutability: mutbl,
15971598
type_: Box::new(clean_middle_ty(ty, cx, None)),
15981599
},
@@ -1639,7 +1640,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
16391640

16401641
inline::record_extern_fqn(cx, did, ItemType::Trait);
16411642

1642-
let lifetime = reg.clean(cx);
1643+
let lifetime = clean_middle_region(*reg);
16431644
let mut bounds = vec![];
16441645

16451646
for did in dids {
@@ -1705,7 +1706,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
17051706
let trait_ref = match bound_predicate.skip_binder() {
17061707
ty::PredicateKind::Trait(tr) => bound_predicate.rebind(tr.trait_ref),
17071708
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => {
1708-
if let Some(r) = reg.clean(cx) {
1709+
if let Some(r) = clean_middle_region(reg) {
17091710
regions.push(GenericBound::Outlives(r));
17101711
}
17111712
return None;

src/librustdoc/clean/utils.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::clean::auto_trait::AutoTraitFinder;
22
use crate::clean::blanket_impl::BlanketImplFinder;
33
use crate::clean::render_macro_matchers::render_macro_matcher;
44
use crate::clean::{
5-
clean_middle_const, clean_middle_ty, inline, Clean, Crate, ExternalCrate, Generic, GenericArg,
6-
GenericArgs, ImportSource, Item, ItemKind, Lifetime, Path, PathSegment, Primitive,
7-
PrimitiveType, Type, TypeBinding, Visibility,
5+
clean_middle_const, clean_middle_region, clean_middle_ty, inline, Clean, Crate, ExternalCrate,
6+
Generic, GenericArg, GenericArgs, ImportSource, Item, ItemKind, Lifetime, Path, PathSegment,
7+
Primitive, PrimitiveType, Type, TypeBinding, Visibility,
88
};
99
use crate::core::DocContext;
1010
use crate::formats::item_type::ItemType;
@@ -86,7 +86,7 @@ pub(crate) fn substs_to_args<'tcx>(
8686
Vec::with_capacity(substs.len().saturating_sub(if skip_first { 1 } else { 0 }));
8787
ret_val.extend(substs.iter().filter_map(|kind| match kind.unpack() {
8888
GenericArgKind::Lifetime(lt) => {
89-
Some(GenericArg::Lifetime(lt.clean(cx).unwrap_or(Lifetime::elided())))
89+
Some(GenericArg::Lifetime(clean_middle_region(lt).unwrap_or(Lifetime::elided())))
9090
}
9191
GenericArgKind::Type(_) if skip_first => {
9292
skip_first = false;

0 commit comments

Comments
 (0)