Skip to content

Commit f9cfc72

Browse files
committed
nits: librustdoc::clean
- librustdoc::clean::clean_lifetime doesn't need a mut doc context - librustdoc::clean::normalize doesn't need a mut doc context - move Some() wrapping up into `clean_predicate()` - simplify nested if in librustdoc::clean::record_extern_fqn()
1 parent 4ed8cf4 commit f9cfc72

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/librustdoc/clean/inline.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,8 @@ pub(crate) fn item_relative_path(tcx: TyCtxt<'_>, def_id: DefId) -> Vec<Symbol>
229229
/// These names are used later on by HTML rendering to generate things like
230230
/// source links back to the original item.
231231
pub(crate) fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType) {
232-
if did.is_local() {
233-
if cx.cache.exact_paths.contains_key(&did) {
234-
return;
235-
}
232+
if did.is_local() && cx.cache.exact_paths.contains_key(&did) {
233+
return;
236234
} else if cx.cache.external_paths.contains_key(&did) {
237235
return;
238236
}

src/librustdoc/clean/mod.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fn clean_poly_trait_ref_with_constraints<'tcx>(
268268
)
269269
}
270270

271-
fn clean_lifetime(lifetime: &hir::Lifetime, cx: &mut DocContext<'_>) -> Lifetime {
271+
fn clean_lifetime(lifetime: &hir::Lifetime, cx: &DocContext<'_>) -> Lifetime {
272272
if let Some(
273273
rbv::ResolvedArg::EarlyBound(did)
274274
| rbv::ResolvedArg::LateBound(_, _, did)
@@ -362,9 +362,9 @@ pub(crate) fn clean_predicate<'tcx>(
362362
let bound_predicate = predicate.kind();
363363
match bound_predicate.skip_binder() {
364364
ty::ClauseKind::Trait(pred) => clean_poly_trait_predicate(bound_predicate.rebind(pred), cx),
365-
ty::ClauseKind::RegionOutlives(pred) => clean_region_outlives_predicate(pred),
365+
ty::ClauseKind::RegionOutlives(pred) => Some(clean_region_outlives_predicate(pred)),
366366
ty::ClauseKind::TypeOutlives(pred) => {
367-
clean_type_outlives_predicate(bound_predicate.rebind(pred), cx)
367+
Some(clean_type_outlives_predicate(bound_predicate.rebind(pred), cx))
368368
}
369369
ty::ClauseKind::Projection(pred) => {
370370
Some(clean_projection_predicate(bound_predicate.rebind(pred), cx))
@@ -396,32 +396,30 @@ fn clean_poly_trait_predicate<'tcx>(
396396
})
397397
}
398398

399-
fn clean_region_outlives_predicate(
400-
pred: ty::RegionOutlivesPredicate<'_>,
401-
) -> Option<WherePredicate> {
399+
fn clean_region_outlives_predicate(pred: ty::RegionOutlivesPredicate<'_>) -> WherePredicate {
402400
let ty::OutlivesPredicate(a, b) = pred;
403401

404-
Some(WherePredicate::RegionPredicate {
402+
WherePredicate::RegionPredicate {
405403
lifetime: clean_middle_region(a).expect("failed to clean lifetime"),
406404
bounds: vec![GenericBound::Outlives(
407405
clean_middle_region(b).expect("failed to clean bounds"),
408406
)],
409-
})
407+
}
410408
}
411409

412410
fn clean_type_outlives_predicate<'tcx>(
413411
pred: ty::Binder<'tcx, ty::TypeOutlivesPredicate<'tcx>>,
414412
cx: &mut DocContext<'tcx>,
415-
) -> Option<WherePredicate> {
413+
) -> WherePredicate {
416414
let ty::OutlivesPredicate(ty, lt) = pred.skip_binder();
417415

418-
Some(WherePredicate::BoundPredicate {
416+
WherePredicate::BoundPredicate {
419417
ty: clean_middle_ty(pred.rebind(ty), cx, None, None),
420418
bounds: vec![GenericBound::Outlives(
421419
clean_middle_region(lt).expect("failed to clean lifetimes"),
422420
)],
423421
bound_params: Vec::new(),
424-
})
422+
}
425423
}
426424

427425
fn clean_middle_term<'tcx>(
@@ -1860,7 +1858,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18601858

18611859
/// Returns `None` if the type could not be normalized
18621860
fn normalize<'tcx>(
1863-
cx: &mut DocContext<'tcx>,
1861+
cx: &DocContext<'tcx>,
18641862
ty: ty::Binder<'tcx, Ty<'tcx>>,
18651863
) -> Option<ty::Binder<'tcx, Ty<'tcx>>> {
18661864
// HACK: low-churn fix for #79459 while we wait for a trait normalization fix

0 commit comments

Comments
 (0)