Skip to content

Commit f141a52

Browse files
committed
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.
1 parent 8d39ec1 commit f141a52

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,13 @@ pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
207207
span_bug!(cx.tcx.def_span(trait_ref.def_id()), "`TraitRef` had unexpected kind {kind:?}");
208208
}
209209
inline::record_extern_fqn(cx, trait_ref.def_id(), kind);
210-
let path =
211-
external_path(cx, trait_ref.def_id(), true, bindings, trait_ref.map_bound(|tr| tr.args));
210+
let path = clean_middle_path(
211+
cx,
212+
trait_ref.def_id(),
213+
true,
214+
bindings,
215+
trait_ref.map_bound(|tr| tr.args),
216+
);
212217

213218
debug!(?trait_ref);
214219

@@ -467,7 +472,7 @@ fn projection_to_path_segment<'tcx>(
467472
PathSegment {
468473
name: item.name,
469474
args: GenericArgs::AngleBracketed {
470-
args: ty_args_to_args(
475+
args: clean_middle_generic_args(
471476
cx,
472477
ty.map_bound(|ty| &ty.args[generics.parent_count..]),
473478
false,
@@ -2096,12 +2101,12 @@ pub(crate) fn clean_middle_ty<'tcx>(
20962101
AdtKind::Enum => ItemType::Enum,
20972102
};
20982103
inline::record_extern_fqn(cx, did, kind);
2099-
let path = external_path(cx, did, false, ThinVec::new(), bound_ty.rebind(args));
2104+
let path = clean_middle_path(cx, did, false, ThinVec::new(), bound_ty.rebind(args));
21002105
Type::Path { path }
21012106
}
21022107
ty::Foreign(did) => {
21032108
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
2104-
let path = external_path(
2109+
let path = clean_middle_path(
21052110
cx,
21062111
did,
21072112
false,
@@ -2132,7 +2137,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
21322137
let mut bounds = dids
21332138
.map(|did| {
21342139
let empty = ty::Binder::dummy(ty::GenericArgs::empty());
2135-
let path = external_path(cx, did, false, ThinVec::new(), empty);
2140+
let path = clean_middle_path(cx, did, false, ThinVec::new(), empty);
21362141
inline::record_extern_fqn(cx, did, ItemType::Trait);
21372142
PolyTrait { trait_: path, generic_params: Vec::new() }
21382143
})
@@ -2171,7 +2176,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
21712176
.collect();
21722177
let late_bound_regions = late_bound_regions.into_iter().collect();
21732178

2174-
let path = external_path(cx, did, false, bindings, args);
2179+
let path = clean_middle_path(cx, did, false, bindings, args);
21752180
bounds.insert(0, PolyTrait { trait_: path, generic_params: late_bound_regions });
21762181

21772182
DynTrait(bounds, lifetime)
@@ -2193,7 +2198,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
21932198
assoc: PathSegment {
21942199
name: cx.tcx.associated_item(def_id).name,
21952200
args: GenericArgs::AngleBracketed {
2196-
args: ty_args_to_args(
2201+
args: clean_middle_generic_args(
21972202
cx,
21982203
alias_ty.map_bound(|ty| ty.args.as_slice()),
21992204
true,
@@ -2213,7 +2218,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
22132218
if cx.tcx.features().lazy_type_alias {
22142219
// Weak type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
22152220
// we need to use `type_of`.
2216-
let path = external_path(
2221+
let path = clean_middle_path(
22172222
cx,
22182223
data.def_id,
22192224
false,
@@ -2243,7 +2248,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
22432248
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
22442249
// If it's already in the same alias, don't get an infinite loop.
22452250
if cx.current_type_aliases.contains_key(&def_id) {
2246-
let path = external_path(cx, def_id, false, ThinVec::new(), bound_ty.rebind(args));
2251+
let path =
2252+
clean_middle_path(cx, def_id, false, ThinVec::new(), bound_ty.rebind(args));
22472253
Type::Path { path }
22482254
} else {
22492255
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;

src/librustdoc/clean/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_target::abi::VariantIdx;
3636
use rustc_target::spec::abi::Abi;
3737

3838
use crate::clean::cfg::Cfg;
39-
use crate::clean::external_path;
39+
use crate::clean::clean_middle_path;
4040
use crate::clean::inline::{self, print_inlined_const};
4141
use crate::clean::utils::{is_literal_expr, print_evaluated_const};
4242
use crate::core::DocContext;
@@ -1258,7 +1258,7 @@ impl GenericBound {
12581258
fn sized_with(cx: &mut DocContext<'_>, modifier: hir::TraitBoundModifier) -> GenericBound {
12591259
let did = cx.tcx.require_lang_item(LangItem::Sized, None);
12601260
let empty = ty::Binder::dummy(ty::GenericArgs::empty());
1261-
let path = external_path(cx, did, false, ThinVec::new(), empty);
1261+
let path = clean_middle_path(cx, did, false, ThinVec::new(), empty);
12621262
inline::record_extern_fqn(cx, did, ItemType::Trait);
12631263
GenericBound::TraitBound(PolyTrait { trait_: path, generic_params: Vec::new() }, modifier)
12641264
}

src/librustdoc/clean/utils.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate {
7575
Crate { module, external_traits: cx.external_traits.clone() }
7676
}
7777

78-
pub(crate) fn ty_args_to_args<'tcx>(
78+
pub(crate) fn clean_middle_generic_args<'tcx>(
7979
cx: &mut DocContext<'tcx>,
80-
ty_args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
80+
args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
8181
has_self: bool,
8282
owner: DefId,
8383
) -> Vec<GenericArg> {
84-
if ty_args.skip_binder().is_empty() {
84+
if args.skip_binder().is_empty() {
8585
// Fast path which avoids executing the query `generics_of`.
8686
return Vec::new();
8787
}
@@ -90,9 +90,9 @@ pub(crate) fn ty_args_to_args<'tcx>(
9090
let mut elision_has_failed_once_before = false;
9191

9292
let offset = if has_self { 1 } else { 0 };
93-
let mut args = Vec::with_capacity(ty_args.skip_binder().len().saturating_sub(offset));
93+
let mut clean_args = Vec::with_capacity(args.skip_binder().len().saturating_sub(offset));
9494

95-
let ty_arg_to_arg = |(index, arg): (usize, &ty::GenericArg<'tcx>)| match arg.unpack() {
95+
let clean_arg = |(index, arg): (usize, &ty::GenericArg<'tcx>)| match arg.unpack() {
9696
GenericArgKind::Lifetime(lt) => {
9797
Some(GenericArg::Lifetime(clean_middle_region(lt).unwrap_or(Lifetime::elided())))
9898
}
@@ -101,26 +101,20 @@ pub(crate) fn ty_args_to_args<'tcx>(
101101
if !elision_has_failed_once_before
102102
&& let Some(default) = params[index].default_value(cx.tcx)
103103
{
104-
let default =
105-
ty_args.map_bound(|args| default.instantiate(cx.tcx, args).expect_ty());
104+
let default = args.map_bound(|args| default.instantiate(cx.tcx, args).expect_ty());
106105

107-
if can_elide_generic_arg(ty_args.rebind(ty), default) {
106+
if can_elide_generic_arg(args.rebind(ty), default) {
108107
return None;
109108
}
110109

111110
elision_has_failed_once_before = true;
112111
}
113112

114113
Some(GenericArg::Type(clean_middle_ty(
115-
ty_args.rebind(ty),
114+
args.rebind(ty),
116115
cx,
117116
None,
118-
Some(crate::clean::ContainerTy::Regular {
119-
ty: owner,
120-
args: ty_args,
121-
has_self,
122-
arg: index,
123-
}),
117+
Some(crate::clean::ContainerTy::Regular { ty: owner, args, has_self, arg: index }),
124118
)))
125119
}
126120
GenericArgKind::Const(ct) => {
@@ -133,22 +127,22 @@ pub(crate) fn ty_args_to_args<'tcx>(
133127
&& let Some(default) = params[index].default_value(cx.tcx)
134128
{
135129
let default =
136-
ty_args.map_bound(|args| default.instantiate(cx.tcx, args).expect_const());
130+
args.map_bound(|args| default.instantiate(cx.tcx, args).expect_const());
137131

138-
if can_elide_generic_arg(ty_args.rebind(ct), default) {
132+
if can_elide_generic_arg(args.rebind(ct), default) {
139133
return None;
140134
}
141135

142136
elision_has_failed_once_before = true;
143137
}
144138

145-
Some(GenericArg::Const(Box::new(clean_middle_const(ty_args.rebind(ct), cx))))
139+
Some(GenericArg::Const(Box::new(clean_middle_const(args.rebind(ct), cx))))
146140
}
147141
};
148142

149-
args.extend(ty_args.skip_binder().iter().enumerate().rev().filter_map(ty_arg_to_arg));
150-
args.reverse();
151-
args
143+
clean_args.extend(args.skip_binder().iter().enumerate().rev().filter_map(clean_arg));
144+
clean_args.reverse();
145+
clean_args
152146
}
153147

154148
/// Check if the generic argument `actual` coincides with the `default` and can therefore be elided.
@@ -192,14 +186,14 @@ where
192186
actual.skip_binder() == default.skip_binder()
193187
}
194188

195-
fn external_generic_args<'tcx>(
189+
fn clean_middle_generic_args_with_bindings<'tcx>(
196190
cx: &mut DocContext<'tcx>,
197191
did: DefId,
198192
has_self: bool,
199193
bindings: ThinVec<TypeBinding>,
200194
ty_args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
201195
) -> GenericArgs {
202-
let args = ty_args_to_args(cx, ty_args.map_bound(|args| &args[..]), has_self, did);
196+
let args = clean_middle_generic_args(cx, ty_args.map_bound(|args| &args[..]), has_self, did);
203197

204198
if cx.tcx.fn_trait_kind_from_def_id(did).is_some() {
205199
let ty = ty_args
@@ -225,7 +219,7 @@ fn external_generic_args<'tcx>(
225219
}
226220
}
227221

228-
pub(super) fn external_path<'tcx>(
222+
pub(super) fn clean_middle_path<'tcx>(
229223
cx: &mut DocContext<'tcx>,
230224
did: DefId,
231225
has_self: bool,
@@ -238,7 +232,7 @@ pub(super) fn external_path<'tcx>(
238232
res: Res::Def(def_kind, did),
239233
segments: thin_vec![PathSegment {
240234
name,
241-
args: external_generic_args(cx, did, has_self, bindings, args),
235+
args: clean_middle_generic_args_with_bindings(cx, did, has_self, bindings, args),
242236
}],
243237
}
244238
}

0 commit comments

Comments
 (0)