Skip to content

Commit

Permalink
rustdoc: stylistic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Jul 26, 2023
1 parent c3c5a5c commit f68f37d
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,10 @@ fn clean_ty_generics<'tcx>(
let where_predicates = preds
.predicates
.iter()
.flat_map(|(p, _)| {
.flat_map(|(pred, _)| {
let mut projection = None;
let param_idx = (|| {
let bound_p = p.kind();
let bound_p = pred.kind();
match bound_p.skip_binder() {
ty::ClauseKind::Trait(pred) => {
if let ty::Param(param) = pred.self_ty().kind() {
Expand All @@ -826,33 +826,27 @@ fn clean_ty_generics<'tcx>(
})();

if let Some(param_idx) = param_idx
&& let Some(b) = impl_trait.get_mut(&param_idx.into())
&& let Some(bounds) = impl_trait.get_mut(&param_idx.into())
{
let p: WherePredicate = clean_predicate(*p, cx)?;
let pred = clean_predicate(*pred, cx)?;

b.extend(
p.get_bounds()
bounds.extend(
pred.get_bounds()
.into_iter()
.flatten()
.cloned()
.filter(|b| !b.is_sized_bound(cx)),
);

let proj = projection.map(|p| {
(
clean_projection(p.map_bound(|p| p.projection_ty), cx, None),
p.map_bound(|p| p.term),
)
});
if let Some(((_, trait_did, name), rhs)) = proj
.as_ref()
.and_then(|(lhs, rhs): &(Type, _)| Some((lhs.projection()?, rhs)))
if let Some(proj) = projection
&& let lhs = clean_projection(proj.map_bound(|p| p.projection_ty), cx, None)
&& let Some((_, trait_did, name)) = lhs.projection()
{
impl_trait_proj.entry(param_idx).or_default().push((
trait_did,
name,
*rhs,
p.get_bound_params()
proj.map_bound(|p| p.term),
pred.get_bound_params()
.into_iter()
.flatten()
.cloned()
Expand All @@ -863,7 +857,7 @@ fn clean_ty_generics<'tcx>(
return None;
}

Some(p)
Some(pred)
})
.collect::<Vec<_>>();

Expand Down Expand Up @@ -891,7 +885,7 @@ fn clean_ty_generics<'tcx>(
// implicit `Sized` bound unless removed with `?Sized`.
// However, in the list of where-predicates below, `Sized` appears like a
// normal bound: It's either present (the type is sized) or
// absent (the type is unsized) but never *maybe* (i.e. `?Sized`).
// absent (the type might be unsized) but never *maybe* (i.e. `?Sized`).
//
// This is unsuitable for rendering.
// Thus, as a first step remove all `Sized` bounds that should be implicit.
Expand All @@ -902,8 +896,8 @@ fn clean_ty_generics<'tcx>(
let mut sized_params = FxHashSet::default();
where_predicates.retain(|pred| {
if let WherePredicate::BoundPredicate { ty: Generic(g), bounds, .. } = pred
&& *g != kw::SelfUpper
&& bounds.iter().any(|b| b.is_sized_bound(cx))
&& *g != kw::SelfUpper
&& bounds.iter().any(|b| b.is_sized_bound(cx))
{
sized_params.insert(*g);
false
Expand Down

0 comments on commit f68f37d

Please sign in to comment.