mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
[perf] rustdoc: Perform less work when cleaning parenthesized generic args
This commit is contained in:
parent
143ce0920a
commit
46603166d7
@ -2119,7 +2119,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let bindings = obj
|
let constraints = obj
|
||||||
.projection_bounds()
|
.projection_bounds()
|
||||||
.map(|pb| AssocItemConstraint {
|
.map(|pb| AssocItemConstraint {
|
||||||
assoc: projection_to_path_segment(
|
assoc: projection_to_path_segment(
|
||||||
@ -2155,7 +2155,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
|
|||||||
.collect();
|
.collect();
|
||||||
let late_bound_regions = late_bound_regions.into_iter().collect();
|
let late_bound_regions = late_bound_regions.into_iter().collect();
|
||||||
|
|
||||||
let path = clean_middle_path(cx, did, false, bindings, args);
|
let path = clean_middle_path(cx, did, false, constraints, args);
|
||||||
bounds.insert(0, PolyTrait { trait_: path, generic_params: late_bound_regions });
|
bounds.insert(0, PolyTrait { trait_: path, generic_params: late_bound_regions });
|
||||||
|
|
||||||
DynTrait(bounds, lifetime)
|
DynTrait(bounds, lifetime)
|
||||||
|
@ -112,7 +112,6 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Elide internal host effect args.
|
|
||||||
let param = generics.param_at(index, cx.tcx);
|
let param = generics.param_at(index, cx.tcx);
|
||||||
let arg = ty::Binder::bind_with_vars(arg, bound_vars);
|
let arg = ty::Binder::bind_with_vars(arg, bound_vars);
|
||||||
|
|
||||||
@ -201,35 +200,30 @@ fn clean_middle_generic_args_with_constraints<'tcx>(
|
|||||||
cx: &mut DocContext<'tcx>,
|
cx: &mut DocContext<'tcx>,
|
||||||
did: DefId,
|
did: DefId,
|
||||||
has_self: bool,
|
has_self: bool,
|
||||||
constraints: ThinVec<AssocItemConstraint>,
|
mut constraints: ThinVec<AssocItemConstraint>,
|
||||||
ty_args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
|
args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
|
||||||
) -> GenericArgs {
|
) -> GenericArgs {
|
||||||
let args = clean_middle_generic_args(cx, ty_args.map_bound(|args| &args[..]), has_self, did);
|
if cx.tcx.is_trait(did)
|
||||||
|
&& cx.tcx.trait_def(did).paren_sugar
|
||||||
if cx.tcx.is_trait(did) && cx.tcx.trait_def(did).paren_sugar {
|
&& let ty::Tuple(tys) = args.skip_binder().type_at(has_self as usize).kind()
|
||||||
let ty = ty_args
|
|
||||||
.iter()
|
|
||||||
.nth(if has_self { 1 } else { 0 })
|
|
||||||
.unwrap()
|
|
||||||
.map_bound(|arg| arg.expect_ty());
|
|
||||||
let inputs =
|
|
||||||
// The trait's first substitution is the one after self, if there is one.
|
|
||||||
match ty.skip_binder().kind() {
|
|
||||||
ty::Tuple(tys) => tys.iter().map(|t| clean_middle_ty(ty.rebind(t), cx, None, None)).collect::<Vec<_>>().into(),
|
|
||||||
_ => return GenericArgs::AngleBracketed { args: args.into(), constraints },
|
|
||||||
};
|
|
||||||
let output = constraints.into_iter().next().and_then(|binding| match binding.kind {
|
|
||||||
AssocItemConstraintKind::Equality { term: Term::Type(ty) }
|
|
||||||
if ty != Type::Tuple(Vec::new()) =>
|
|
||||||
{
|
{
|
||||||
|
let inputs = tys
|
||||||
|
.iter()
|
||||||
|
.map(|ty| clean_middle_ty(args.rebind(ty), cx, None, None))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.into();
|
||||||
|
let output = constraints.pop().and_then(|constraint| match constraint.kind {
|
||||||
|
AssocItemConstraintKind::Equality { term: Term::Type(ty) } if !ty.is_unit() => {
|
||||||
Some(Box::new(ty))
|
Some(Box::new(ty))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
GenericArgs::Parenthesized { inputs, output }
|
return GenericArgs::Parenthesized { inputs, output };
|
||||||
} else {
|
|
||||||
GenericArgs::AngleBracketed { args: args.into(), constraints }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let args = clean_middle_generic_args(cx, args.map_bound(|args| &args[..]), has_self, did);
|
||||||
|
|
||||||
|
GenericArgs::AngleBracketed { args: args.into(), constraints }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn clean_middle_path<'tcx>(
|
pub(super) fn clean_middle_path<'tcx>(
|
||||||
|
Loading…
Reference in New Issue
Block a user