Rename rustc_middle path cleaning functions

The new names are consistent with the other rustc_middle cleaning functions.
Regarding the local variable `ty_args`, it's used throughout the function and
personally speaking its name isn't very legible, I trip up on it.
This commit is contained in:
León Orell Valerian Liehr 2024-01-08 22:37:42 +01:00
parent 8d39ec1825
commit f141a524e8
No known key found for this signature in database
GPG Key ID: D17A07215F68E713
3 changed files with 37 additions and 37 deletions

View File

@ -207,8 +207,13 @@ pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
span_bug!(cx.tcx.def_span(trait_ref.def_id()), "`TraitRef` had unexpected kind {kind:?}");
}
inline::record_extern_fqn(cx, trait_ref.def_id(), kind);
let path =
external_path(cx, trait_ref.def_id(), true, bindings, trait_ref.map_bound(|tr| tr.args));
let path = clean_middle_path(
cx,
trait_ref.def_id(),
true,
bindings,
trait_ref.map_bound(|tr| tr.args),
);
debug!(?trait_ref);
@ -467,7 +472,7 @@ fn projection_to_path_segment<'tcx>(
PathSegment {
name: item.name,
args: GenericArgs::AngleBracketed {
args: ty_args_to_args(
args: clean_middle_generic_args(
cx,
ty.map_bound(|ty| &ty.args[generics.parent_count..]),
false,
@ -2096,12 +2101,12 @@ pub(crate) fn clean_middle_ty<'tcx>(
AdtKind::Enum => ItemType::Enum,
};
inline::record_extern_fqn(cx, did, kind);
let path = external_path(cx, did, false, ThinVec::new(), bound_ty.rebind(args));
let path = clean_middle_path(cx, did, false, ThinVec::new(), bound_ty.rebind(args));
Type::Path { path }
}
ty::Foreign(did) => {
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
let path = external_path(
let path = clean_middle_path(
cx,
did,
false,
@ -2132,7 +2137,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
let mut bounds = dids
.map(|did| {
let empty = ty::Binder::dummy(ty::GenericArgs::empty());
let path = external_path(cx, did, false, ThinVec::new(), empty);
let path = clean_middle_path(cx, did, false, ThinVec::new(), empty);
inline::record_extern_fqn(cx, did, ItemType::Trait);
PolyTrait { trait_: path, generic_params: Vec::new() }
})
@ -2171,7 +2176,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
.collect();
let late_bound_regions = late_bound_regions.into_iter().collect();
let path = external_path(cx, did, false, bindings, args);
let path = clean_middle_path(cx, did, false, bindings, args);
bounds.insert(0, PolyTrait { trait_: path, generic_params: late_bound_regions });
DynTrait(bounds, lifetime)
@ -2193,7 +2198,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
assoc: PathSegment {
name: cx.tcx.associated_item(def_id).name,
args: GenericArgs::AngleBracketed {
args: ty_args_to_args(
args: clean_middle_generic_args(
cx,
alias_ty.map_bound(|ty| ty.args.as_slice()),
true,
@ -2213,7 +2218,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
if cx.tcx.features().lazy_type_alias {
// Weak type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
// we need to use `type_of`.
let path = external_path(
let path = clean_middle_path(
cx,
data.def_id,
false,
@ -2243,7 +2248,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
// If it's already in the same alias, don't get an infinite loop.
if cx.current_type_aliases.contains_key(&def_id) {
let path = external_path(cx, def_id, false, ThinVec::new(), bound_ty.rebind(args));
let path =
clean_middle_path(cx, def_id, false, ThinVec::new(), bound_ty.rebind(args));
Type::Path { path }
} else {
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;

View File

@ -36,7 +36,7 @@ use rustc_target::abi::VariantIdx;
use rustc_target::spec::abi::Abi;
use crate::clean::cfg::Cfg;
use crate::clean::external_path;
use crate::clean::clean_middle_path;
use crate::clean::inline::{self, print_inlined_const};
use crate::clean::utils::{is_literal_expr, print_evaluated_const};
use crate::core::DocContext;
@ -1258,7 +1258,7 @@ impl GenericBound {
fn sized_with(cx: &mut DocContext<'_>, modifier: hir::TraitBoundModifier) -> GenericBound {
let did = cx.tcx.require_lang_item(LangItem::Sized, None);
let empty = ty::Binder::dummy(ty::GenericArgs::empty());
let path = external_path(cx, did, false, ThinVec::new(), empty);
let path = clean_middle_path(cx, did, false, ThinVec::new(), empty);
inline::record_extern_fqn(cx, did, ItemType::Trait);
GenericBound::TraitBound(PolyTrait { trait_: path, generic_params: Vec::new() }, modifier)
}

View File

@ -75,13 +75,13 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate {
Crate { module, external_traits: cx.external_traits.clone() }
}
pub(crate) fn ty_args_to_args<'tcx>(
pub(crate) fn clean_middle_generic_args<'tcx>(
cx: &mut DocContext<'tcx>,
ty_args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
has_self: bool,
owner: DefId,
) -> Vec<GenericArg> {
if ty_args.skip_binder().is_empty() {
if args.skip_binder().is_empty() {
// Fast path which avoids executing the query `generics_of`.
return Vec::new();
}
@ -90,9 +90,9 @@ pub(crate) fn ty_args_to_args<'tcx>(
let mut elision_has_failed_once_before = false;
let offset = if has_self { 1 } else { 0 };
let mut args = Vec::with_capacity(ty_args.skip_binder().len().saturating_sub(offset));
let mut clean_args = Vec::with_capacity(args.skip_binder().len().saturating_sub(offset));
let ty_arg_to_arg = |(index, arg): (usize, &ty::GenericArg<'tcx>)| match arg.unpack() {
let clean_arg = |(index, arg): (usize, &ty::GenericArg<'tcx>)| match arg.unpack() {
GenericArgKind::Lifetime(lt) => {
Some(GenericArg::Lifetime(clean_middle_region(lt).unwrap_or(Lifetime::elided())))
}
@ -101,10 +101,9 @@ pub(crate) fn ty_args_to_args<'tcx>(
if !elision_has_failed_once_before
&& let Some(default) = params[index].default_value(cx.tcx)
{
let default =
ty_args.map_bound(|args| default.instantiate(cx.tcx, args).expect_ty());
let default = args.map_bound(|args| default.instantiate(cx.tcx, args).expect_ty());
if can_elide_generic_arg(ty_args.rebind(ty), default) {
if can_elide_generic_arg(args.rebind(ty), default) {
return None;
}
@ -112,15 +111,10 @@ pub(crate) fn ty_args_to_args<'tcx>(
}
Some(GenericArg::Type(clean_middle_ty(
ty_args.rebind(ty),
args.rebind(ty),
cx,
None,
Some(crate::clean::ContainerTy::Regular {
ty: owner,
args: ty_args,
has_self,
arg: index,
}),
Some(crate::clean::ContainerTy::Regular { ty: owner, args, has_self, arg: index }),
)))
}
GenericArgKind::Const(ct) => {
@ -133,22 +127,22 @@ pub(crate) fn ty_args_to_args<'tcx>(
&& let Some(default) = params[index].default_value(cx.tcx)
{
let default =
ty_args.map_bound(|args| default.instantiate(cx.tcx, args).expect_const());
args.map_bound(|args| default.instantiate(cx.tcx, args).expect_const());
if can_elide_generic_arg(ty_args.rebind(ct), default) {
if can_elide_generic_arg(args.rebind(ct), default) {
return None;
}
elision_has_failed_once_before = true;
}
Some(GenericArg::Const(Box::new(clean_middle_const(ty_args.rebind(ct), cx))))
Some(GenericArg::Const(Box::new(clean_middle_const(args.rebind(ct), cx))))
}
};
args.extend(ty_args.skip_binder().iter().enumerate().rev().filter_map(ty_arg_to_arg));
args.reverse();
args
clean_args.extend(args.skip_binder().iter().enumerate().rev().filter_map(clean_arg));
clean_args.reverse();
clean_args
}
/// Check if the generic argument `actual` coincides with the `default` and can therefore be elided.
@ -192,14 +186,14 @@ where
actual.skip_binder() == default.skip_binder()
}
fn external_generic_args<'tcx>(
fn clean_middle_generic_args_with_bindings<'tcx>(
cx: &mut DocContext<'tcx>,
did: DefId,
has_self: bool,
bindings: ThinVec<TypeBinding>,
ty_args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
) -> GenericArgs {
let args = ty_args_to_args(cx, ty_args.map_bound(|args| &args[..]), has_self, did);
let args = clean_middle_generic_args(cx, ty_args.map_bound(|args| &args[..]), has_self, did);
if cx.tcx.fn_trait_kind_from_def_id(did).is_some() {
let ty = ty_args
@ -225,7 +219,7 @@ fn external_generic_args<'tcx>(
}
}
pub(super) fn external_path<'tcx>(
pub(super) fn clean_middle_path<'tcx>(
cx: &mut DocContext<'tcx>,
did: DefId,
has_self: bool,
@ -238,7 +232,7 @@ pub(super) fn external_path<'tcx>(
res: Res::Def(def_kind, did),
segments: thin_vec![PathSegment {
name,
args: external_generic_args(cx, did, has_self, bindings, args),
args: clean_middle_generic_args_with_bindings(cx, did, has_self, bindings, args),
}],
}
}