Skip to content

Commit f19d40a

Browse files
committed
Rename some methods.
Most of the methods returning `impl Display` have `print` in their name. This commit renames a few that didn't follow that convention.
1 parent b8ce853 commit f19d40a

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed

src/librustdoc/html/format.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -705,13 +705,13 @@ fn resolved_path(
705705
f,
706706
"{path}::{anchor}",
707707
path = join_with_double_colon(&fqp[..fqp.len() - 1]),
708-
anchor = anchor(did, *fqp.last().unwrap(), cx)
708+
anchor = print_anchor(did, *fqp.last().unwrap(), cx)
709709
)
710710
} else {
711711
write!(f, "{}", last.name)
712712
}
713713
} else {
714-
write!(f, "{}", anchor(did, last.name, cx))
714+
write!(f, "{}", print_anchor(did, last.name, cx))
715715
}
716716
});
717717
write!(w, "{path}{args}", args = last.args.print(cx))?;
@@ -797,7 +797,7 @@ fn primitive_link_fragment(
797797
Ok(())
798798
}
799799

800-
fn tybounds(
800+
fn print_tybounds(
801801
bounds: &[clean::PolyTrait],
802802
lt: &Option<clean::Lifetime>,
803803
cx: &Context<'_>,
@@ -829,7 +829,7 @@ fn print_higher_ranked_params_with_space(
829829
})
830830
}
831831

832-
pub(crate) fn anchor(did: DefId, text: Symbol, cx: &Context<'_>) -> impl Display {
832+
pub(crate) fn print_anchor(did: DefId, text: Symbol, cx: &Context<'_>) -> impl Display {
833833
fmt::from_fn(move |f| {
834834
let parts = href(did, cx);
835835
if let Ok((url, short_ty, fqp)) = parts {
@@ -863,7 +863,7 @@ fn fmt_type(
863863
}
864864
clean::DynTrait(bounds, lt) => {
865865
f.write_str("dyn ")?;
866-
tybounds(bounds, lt, cx).fmt(f)
866+
print_tybounds(bounds, lt, cx).fmt(f)
867867
}
868868
clean::Infer => write!(f, "_"),
869869
clean::Primitive(clean::PrimitiveType::Never) => {
@@ -1128,7 +1128,7 @@ impl clean::Impl {
11281128
self.print_type(inner_type, f, use_absolute, cx)?;
11291129
write!(f, ">")?;
11301130
} else {
1131-
write!(f, "{}&lt;", anchor(ty.def_id(), last, cx))?;
1131+
write!(f, "{}&lt;", print_anchor(ty.def_id(), last, cx))?;
11321132
self.print_type(inner_type, f, use_absolute, cx)?;
11331133
write!(f, "&gt;")?;
11341134
}
@@ -1203,7 +1203,7 @@ impl clean::Impl {
12031203
&& self.kind.is_fake_variadic()
12041204
{
12051205
let ty = generics[0];
1206-
let wrapper = anchor(path.def_id(), path.last(), cx);
1206+
let wrapper = print_anchor(path.def_id(), path.last(), cx);
12071207
if f.alternate() {
12081208
write!(f, "{wrapper:#}&lt;")?;
12091209
} else {
@@ -1416,7 +1416,7 @@ pub(crate) fn visibility_print_with_space(item: &clean::Item, cx: &Context<'_>)
14161416
debug!("path={path:?}");
14171417
// modified from `resolved_path()` to work with `DefPathData`
14181418
let last_name = path.data.last().unwrap().data.get_opt_name().unwrap();
1419-
let anchor = anchor(vis_did, last_name, cx);
1419+
let anchor = print_anchor(vis_did, last_name, cx);
14201420

14211421
let mut s = "pub(in ".to_owned();
14221422
for seg in &path.data[..path.data.len() - 1] {

src/librustdoc/html/render/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_span::edition::Edition;
1414
use rustc_span::{FileName, Symbol, sym};
1515
use tracing::info;
1616

17-
use super::print_item::{full_path, item_path, print_item};
17+
use super::print_item::{full_path, print_item, print_item_path};
1818
use super::sidebar::{ModuleLike, Sidebar, print_sidebar, sidebar_module_like};
1919
use super::{AllTypes, LinkFromSrc, StylePath, collect_spans_and_sources, scrape_examples_help};
2020
use crate::clean::types::ExternalLocation;
@@ -266,7 +266,7 @@ impl<'tcx> Context<'tcx> {
266266
for name in &names[..names.len() - 1] {
267267
write!(f, "{name}/")?;
268268
}
269-
write!(f, "{}", item_path(ty, names.last().unwrap().as_str()))
269+
write!(f, "{}", print_item_path(ty, names.last().unwrap().as_str()))
270270
});
271271
match self.shared.redirections {
272272
Some(ref redirections) => {
@@ -278,7 +278,7 @@ impl<'tcx> Context<'tcx> {
278278
let _ = write!(
279279
current_path,
280280
"{}",
281-
item_path(ty, names.last().unwrap().as_str())
281+
print_item_path(ty, names.last().unwrap().as_str())
282282
);
283283
redirections.borrow_mut().insert(current_path, path.to_string());
284284
}
@@ -847,7 +847,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
847847
if !buf.is_empty() {
848848
let name = item.name.as_ref().unwrap();
849849
let item_type = item.type_();
850-
let file_name = item_path(item_type, name.as_str()).to_string();
850+
let file_name = print_item_path(item_type, name.as_str()).to_string();
851851
self.shared.ensure_dir(&self.dst)?;
852852
let joint_dst = self.dst.join(&file_name);
853853
self.shared.fs.write(joint_dst, buf)?;

src/librustdoc/html/render/print_item.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,15 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
413413

414414
match myitem.kind {
415415
clean::ExternCrateItem { ref src } => {
416-
use crate::html::format::anchor;
416+
use crate::html::format::print_anchor;
417417

418418
match *src {
419419
Some(src) => {
420420
write!(
421421
w,
422422
"<dt><code>{}extern crate {} as {};",
423423
visibility_print_with_space(myitem, cx),
424-
anchor(myitem.item_id.expect_def_id(), src, cx),
424+
print_anchor(myitem.item_id.expect_def_id(), src, cx),
425425
EscapeBodyTextWithWbr(myitem.name.unwrap().as_str())
426426
)?;
427427
}
@@ -430,7 +430,11 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
430430
w,
431431
"<dt><code>{}extern crate {};",
432432
visibility_print_with_space(myitem, cx),
433-
anchor(myitem.item_id.expect_def_id(), myitem.name.unwrap(), cx)
433+
print_anchor(
434+
myitem.item_id.expect_def_id(),
435+
myitem.name.unwrap(),
436+
cx
437+
)
434438
)?;
435439
}
436440
}
@@ -439,7 +443,7 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
439443

440444
clean::ImportItem(ref import) => {
441445
let stab_tags = import.source.did.map_or_else(String::new, |import_def_id| {
442-
extra_info_tags(tcx, myitem, item, Some(import_def_id)).to_string()
446+
print_extra_info_tags(tcx, myitem, item, Some(import_def_id)).to_string()
443447
});
444448

445449
let id = match import.kind {
@@ -497,19 +501,22 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
497501
write!(
498502
w,
499503
"<dt>\
500-
<a class=\"{class}\" href=\"{href}\" title=\"{title}\">{name}</a>\
504+
<a class=\"{class}\" href=\"{href}\" title=\"{title1} {title2}\">\
505+
{name}\
506+
</a>\
501507
{visibility_and_hidden}\
502508
{unsafety_flag}\
503509
{stab_tags}\
504510
</dt>\
505511
{docs_before}{docs}{docs_after}",
506512
name = EscapeBodyTextWithWbr(myitem.name.unwrap().as_str()),
507513
visibility_and_hidden = visibility_and_hidden,
508-
stab_tags = extra_info_tags(tcx, myitem, item, None),
514+
stab_tags = print_extra_info_tags(tcx, myitem, item, None),
509515
class = myitem.type_(),
510516
unsafety_flag = unsafety_flag,
511-
href = item_path(myitem.type_(), myitem.name.unwrap().as_str()),
512-
title = format_args!("{} {}", myitem.type_(), full_path(cx, myitem)),
517+
href = print_item_path(myitem.type_(), myitem.name.unwrap().as_str()),
518+
title1 = myitem.type_(),
519+
title2 = full_path(cx, myitem),
513520
)?;
514521
}
515522
}
@@ -524,7 +531,7 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
524531

525532
/// Render the stability, deprecation and portability tags that are displayed in the item's summary
526533
/// at the module level.
527-
fn extra_info_tags(
534+
fn print_extra_info_tags(
528535
tcx: TyCtxt<'_>,
529536
item: &clean::Item,
530537
parent: &clean::Item,
@@ -639,7 +646,7 @@ fn item_function(cx: &Context<'_>, it: &clean::Item, f: &clean::Function) -> imp
639646
fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt::Display {
640647
fmt::from_fn(|w| {
641648
let tcx = cx.tcx();
642-
let bounds = bounds(&t.bounds, false, cx);
649+
let bounds = print_bounds(&t.bounds, false, cx);
643650
let required_types =
644651
t.items.iter().filter(|m| m.is_required_associated_type()).collect::<Vec<_>>();
645652
let provided_types = t.items.iter().filter(|m| m.is_associated_type()).collect::<Vec<_>>();
@@ -1236,7 +1243,7 @@ fn item_trait_alias(
12361243
attrs = render_attributes_in_pre(it, "", cx),
12371244
name = it.name.unwrap(),
12381245
generics = t.generics.print(cx),
1239-
bounds = bounds(&t.bounds, true, cx),
1246+
bounds = print_bounds(&t.bounds, true, cx),
12401247
where_clause =
12411248
print_where_clause(&t.generics, cx, 0, Ending::NoNewline).maybe_display(),
12421249
)
@@ -2185,14 +2192,18 @@ pub(super) fn full_path(cx: &Context<'_>, item: &clean::Item) -> String {
21852192
s
21862193
}
21872194

2188-
pub(super) fn item_path(ty: ItemType, name: &str) -> impl Display {
2195+
pub(super) fn print_item_path(ty: ItemType, name: &str) -> impl Display {
21892196
fmt::from_fn(move |f| match ty {
21902197
ItemType::Module => write!(f, "{}index.html", ensure_trailing_slash(name)),
21912198
_ => write!(f, "{ty}.{name}.html"),
21922199
})
21932200
}
21942201

2195-
fn bounds(bounds: &[clean::GenericBound], trait_alias: bool, cx: &Context<'_>) -> impl Display {
2202+
fn print_bounds(
2203+
bounds: &[clean::GenericBound],
2204+
trait_alias: bool,
2205+
cx: &Context<'_>,
2206+
) -> impl Display {
21962207
(!bounds.is_empty())
21972208
.then_some(fmt::from_fn(move |f| {
21982209
let has_lots_of_bounds = bounds.len() > 2;

0 commit comments

Comments
 (0)