summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/html/render/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustdoc/html/render/mod.rs')
-rw-r--r--src/librustdoc/html/render/mod.rs266
1 files changed, 141 insertions, 125 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index f923f9054..ac9c180a6 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -85,7 +85,7 @@ use crate::DOC_RUST_LANG_ORG_CHANNEL;
pub(crate) fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
crate::html::format::display_fn(move |f| {
- if !v.ends_with('/') && !v.is_empty() { write!(f, "{}/", v) } else { f.write_str(v) }
+ if !v.ends_with('/') && !v.is_empty() { write!(f, "{v}/") } else { f.write_str(v) }
})
}
@@ -268,7 +268,7 @@ impl AllTypes {
fn append(&mut self, item_name: String, item_type: &ItemType) {
let mut url: Vec<_> = item_name.split("::").skip(1).collect();
if let Some(name) = url.pop() {
- let new_url = format!("{}/{}.{}.html", url.join("/"), item_type, name);
+ let new_url = format!("{}/{item_type}.{name}.html", url.join("/"));
url.push(name);
let name = url.join("::");
match *item_type {
@@ -385,16 +385,17 @@ impl AllTypes {
fn scrape_examples_help(shared: &SharedContext<'_>) -> String {
let mut content = SCRAPE_EXAMPLES_HELP_MD.to_owned();
content.push_str(&format!(
- "## More information\n\n\
- If you want more information about this feature, please read the [corresponding chapter in the Rustdoc book]({}/rustdoc/scraped-examples.html).",
- DOC_RUST_LANG_ORG_CHANNEL));
+ "## More information\n\n\
+ If you want more information about this feature, please read the [corresponding chapter in \
+ the Rustdoc book]({DOC_RUST_LANG_ORG_CHANNEL}/rustdoc/scraped-examples.html)."
+ ));
let mut ids = IdMap::default();
format!(
"<div class=\"main-heading\">\
- <h1>About scraped examples</h1>\
- </div>\
- <div>{}</div>",
+ <h1>About scraped examples</h1>\
+ </div>\
+ <div>{}</div>",
Markdown {
content: &content,
links: &[],
@@ -415,7 +416,7 @@ fn document<'a, 'cx: 'a>(
heading_offset: HeadingOffset,
) -> impl fmt::Display + 'a + Captures<'cx> {
if let Some(ref name) = item.name {
- info!("Documenting {}", name);
+ info!("Documenting {name}");
}
display_fn(move |f| {
@@ -473,7 +474,7 @@ fn document_short<'a, 'cx: 'a>(
MarkdownSummaryLine(&s, &item.links(cx)).into_string_with_has_more_content();
if has_more_content {
- let link = format!(r#" <a{}>Read more</a>"#, assoc_href_attr(item, link, cx));
+ let link = format!(" <a{}>Read more</a>", assoc_href_attr(item, link, cx));
if let Some(idx) = summary_html.rfind("</p>") {
summary_html.insert_str(idx, &link);
@@ -482,7 +483,7 @@ fn document_short<'a, 'cx: 'a>(
}
}
- write!(f, "<div class='docblock'>{}</div>", summary_html)?;
+ write!(f, "<div class='docblock'>{summary_html}</div>")?;
}
Ok(())
})
@@ -512,14 +513,14 @@ fn document_full_inner<'a, 'cx: 'a>(
) -> impl fmt::Display + 'a + Captures<'cx> {
display_fn(move |f| {
if let Some(s) = item.opt_doc_value() {
- debug!("Doc block: =====\n{}\n=====", s);
+ debug!("Doc block: =====\n{s}\n=====");
if is_collapsible {
write!(
f,
"<details class=\"toggle top-doc\" open>\
- <summary class=\"hideme\">\
+ <summary class=\"hideme\">\
<span>Expand description</span>\
- </summary>{}</details>",
+ </summary>{}</details>",
render_markdown(cx, &s, item.links(cx), heading_offset)
)?;
} else {
@@ -564,12 +565,10 @@ fn portability(item: &clean::Item, parent: Option<&clean::Item>) -> Option<Strin
};
debug!(
- "Portability {:?} {:?} (parent: {:?}) - {:?} = {:?}",
- item.name,
- item.cfg,
- parent,
- parent.and_then(|p| p.cfg.as_ref()),
- cfg
+ "Portability {name:?} {item_cfg:?} (parent: {parent:?}) - {parent_cfg:?} = {cfg:?}",
+ name = item.name,
+ item_cfg = item.cfg,
+ parent_cfg = parent.and_then(|p| p.cfg.as_ref()),
);
Some(cfg?.render_long_html())
@@ -701,8 +700,8 @@ fn assoc_href_attr(it: &clean::Item, link: AssocItemLink<'_>, cx: &Context<'_>)
let item_type = it.type_();
let href = match link {
- AssocItemLink::Anchor(Some(ref id)) => Some(format!("#{}", id)),
- AssocItemLink::Anchor(None) => Some(format!("#{}.{}", item_type, name)),
+ AssocItemLink::Anchor(Some(ref id)) => Some(format!("#{id}")),
+ AssocItemLink::Anchor(None) => Some(format!("#{item_type}.{name}")),
AssocItemLink::GotoSource(did, provided_methods) => {
// We're creating a link from the implementation of an associated item to its
// declaration in the trait declaration.
@@ -722,7 +721,7 @@ fn assoc_href_attr(it: &clean::Item, link: AssocItemLink<'_>, cx: &Context<'_>)
};
match href(did.expect_def_id(), cx) {
- Ok((url, ..)) => Some(format!("{}#{}.{}", url, item_type, name)),
+ Ok((url, ..)) => Some(format!("{url}#{item_type}.{name}")),
// The link is broken since it points to an external crate that wasn't documented.
// Do not create any link in such case. This is better than falling back to a
// dummy anchor like `#{item_type}.{name}` representing the `id` of *this* impl item
@@ -735,37 +734,39 @@ fn assoc_href_attr(it: &clean::Item, link: AssocItemLink<'_>, cx: &Context<'_>)
// In this scenario, the actual `id` of this impl item would be
// `#{item_type}.{name}-{n}` for some number `n` (a disambiguator).
Err(HrefError::DocumentationNotBuilt) => None,
- Err(_) => Some(format!("#{}.{}", item_type, name)),
+ Err(_) => Some(format!("#{item_type}.{name}")),
}
}
};
// If there is no `href` for the reason explained above, simply do not render it which is valid:
// https://html.spec.whatwg.org/multipage/links.html#links-created-by-a-and-area-elements
- href.map(|href| format!(" href=\"{}\"", href)).unwrap_or_default()
+ href.map(|href| format!(" href=\"{href}\"")).unwrap_or_default()
}
fn assoc_const(
w: &mut Buffer,
it: &clean::Item,
+ generics: &clean::Generics,
ty: &clean::Type,
default: Option<&clean::ConstantKind>,
link: AssocItemLink<'_>,
- extra: &str,
+ indent: usize,
cx: &Context<'_>,
) {
let tcx = cx.tcx();
write!(
w,
- "{extra}{vis}const <a{href} class=\"constant\">{name}</a>: {ty}",
- extra = extra,
+ "{indent}{vis}const <a{href} class=\"constant\">{name}</a>{generics}: {ty}",
+ indent = " ".repeat(indent),
vis = visibility_print_with_space(it.visibility(tcx), it.item_id, cx),
href = assoc_href_attr(it, link, cx),
name = it.name.as_ref().unwrap(),
+ generics = generics.print(cx),
ty = ty.print(cx),
);
if let Some(default) = default {
- write!(w, " = ");
+ w.write_str(" = ");
// FIXME: `.value()` uses `clean::utils::format_integer_with_underscore_sep` under the
// hood which adds noisy underscores and a type suffix to number literals.
@@ -774,6 +775,7 @@ fn assoc_const(
// Find a way to print constants here without all that jazz.
write!(w, "{}", Escape(&default.value(tcx).unwrap_or_else(|| default.expr(tcx))));
}
+ write!(w, "{}", print_where_clause(generics, cx, indent, Ending::NoNewline));
}
fn assoc_type(
@@ -820,6 +822,7 @@ fn assoc_method(
let header = meth.fn_header(tcx).expect("Trying to get header from a non-function item");
let name = meth.name.as_ref().unwrap();
let vis = visibility_print_with_space(meth.visibility(tcx), meth.item_id, cx).to_string();
+ let defaultness = print_default_space(meth.is_default());
// FIXME: Once https://github.com/rust-lang/rust/issues/67792 is implemented, we can remove
// this condition.
let constness = match render_mode {
@@ -830,7 +833,6 @@ fn assoc_method(
};
let asyncness = header.asyncness.print_with_space();
let unsafety = header.unsafety.print_with_space();
- let defaultness = print_default_space(meth.is_default());
let abi = print_abi_with_space(header.abi).to_string();
let href = assoc_href_attr(meth, link, cx);
@@ -838,10 +840,10 @@ fn assoc_method(
let generics_len = format!("{:#}", g.print(cx)).len();
let mut header_len = "fn ".len()
+ vis.len()
+ + defaultness.len()
+ constness.len()
+ asyncness.len()
+ unsafety.len()
- + defaultness.len()
+ abi.len()
+ name.as_str().len()
+ generics_len;
@@ -860,14 +862,14 @@ fn assoc_method(
w.reserve(header_len + "<a href=\"\" class=\"fn\">{".len() + "</a>".len());
write!(
w,
- "{indent}{vis}{constness}{asyncness}{unsafety}{defaultness}{abi}fn \
+ "{indent}{vis}{defaultness}{constness}{asyncness}{unsafety}{abi}fn \
<a{href} class=\"fn\">{name}</a>{generics}{decl}{notable_traits}{where_clause}",
indent = indent_str,
vis = vis,
+ defaultness = defaultness,
constness = constness,
asyncness = asyncness,
unsafety = unsafety,
- defaultness = defaultness,
abi = abi,
href = href,
name = name,
@@ -907,39 +909,41 @@ fn render_stability_since_raw_with_extra(
if let Some(ver) = stable_version {
stability.push_str(ver.as_str());
- title.push_str(&format!("Stable since Rust version {}", ver));
+ title.push_str(&format!("Stable since Rust version {ver}"));
}
let const_title_and_stability = match const_stability {
Some(ConstStability { level: StabilityLevel::Stable { since, .. }, .. })
if Some(since) != containing_const_ver =>
{
- Some((format!("const since {}", since), format!("const: {}", since)))
+ Some((format!("const since {since}"), format!("const: {since}")))
}
Some(ConstStability { level: StabilityLevel::Unstable { issue, .. }, feature, .. }) => {
let unstable = if let Some(n) = issue {
format!(
- r#"<a href="https://github.com/rust-lang/rust/issues/{}" title="Tracking issue for {}">unstable</a>"#,
- n, feature
+ "<a \
+ href=\"https://github.com/rust-lang/rust/issues/{n}\" \
+ title=\"Tracking issue for {feature}\"\
+ >unstable</a>"
)
} else {
String::from("unstable")
};
- Some((String::from("const unstable"), format!("const: {}", unstable)))
+ Some((String::from("const unstable"), format!("const: {unstable}")))
}
_ => None,
};
if let Some((const_title, const_stability)) = const_title_and_stability {
if !title.is_empty() {
- title.push_str(&format!(", {}", const_title));
+ title.push_str(&format!(", {const_title}"));
} else {
title.push_str(&const_title);
}
if !stability.is_empty() {
- stability.push_str(&format!(" ({})", const_stability));
+ stability.push_str(&format!(" ({const_stability})"));
} else {
stability.push_str(&const_stability);
}
@@ -986,19 +990,22 @@ fn render_assoc_item(
clean::MethodItem(m, _) => {
assoc_method(w, item, &m.generics, &m.decl, link, parent, cx, render_mode)
}
- kind @ (clean::TyAssocConstItem(ty) | clean::AssocConstItem(ty, _)) => assoc_const(
- w,
- item,
- ty,
- match kind {
- clean::TyAssocConstItem(_) => None,
- clean::AssocConstItem(_, default) => Some(default),
- _ => unreachable!(),
- },
- link,
- if parent == ItemType::Trait { " " } else { "" },
- cx,
- ),
+ kind @ (clean::TyAssocConstItem(generics, ty) | clean::AssocConstItem(generics, ty, _)) => {
+ assoc_const(
+ w,
+ item,
+ generics,
+ ty,
+ match kind {
+ clean::TyAssocConstItem(..) => None,
+ clean::AssocConstItem(.., default) => Some(default),
+ _ => unreachable!(),
+ },
+ link,
+ if parent == ItemType::Trait { 4 } else { 0 },
+ cx,
+ )
+ }
clean::TyAssocTypeItem(ref generics, ref bounds) => assoc_type(
w,
item,
@@ -1032,7 +1039,7 @@ fn render_attributes_in_pre<'a, 'b: 'a>(
) -> impl fmt::Display + Captures<'a> + Captures<'b> {
crate::html::format::display_fn(move |f| {
for a in it.attributes(tcx, false) {
- writeln!(f, "{}{}", prefix, a)?;
+ writeln!(f, "{prefix}{a}")?;
}
Ok(())
})
@@ -1085,7 +1092,7 @@ pub(crate) fn render_all_impls(
let impls = impls.into_inner();
if !impls.is_empty() {
write_impl_section_heading(&mut w, "Trait Implementations", "trait-implementations");
- write!(w, "<div id=\"trait-implementations-list\">{}</div>", impls).unwrap();
+ write!(w, "<div id=\"trait-implementations-list\">{impls}</div>").unwrap();
}
if !synthetic.is_empty() {
@@ -1144,9 +1151,7 @@ fn render_assoc_items_inner(
AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => {
let id =
cx.derive_id(small_url_encode(format!("deref-methods-{:#}", type_.print(cx))));
- if let Some(def_id) = type_.def_id(cx.cache()) {
- cx.deref_id_map.insert(def_id, id.clone());
- }
+ let derived_id = cx.derive_id(&id);
write_impl_section_heading(
&mut tmp_buf,
&format!(
@@ -1156,11 +1161,10 @@ fn render_assoc_items_inner(
),
&id,
);
- (
- RenderMode::ForDeref { mut_: deref_mut_ },
- cx.derive_id(id),
- r#" class="impl-items""#,
- )
+ if let Some(def_id) = type_.def_id(cx.cache()) {
+ cx.deref_id_map.insert(def_id, id);
+ }
+ (RenderMode::ForDeref { mut_: deref_mut_ }, derived_id, r#" class="impl-items""#)
}
};
let mut impls_buf = Buffer::html();
@@ -1183,10 +1187,13 @@ fn render_assoc_items_inner(
);
}
if !impls_buf.is_empty() {
- write!(w, "{}", tmp_buf.into_inner()).unwrap();
- write!(w, "<div id=\"{id}\"{class_html}>").unwrap();
- write!(w, "{}", impls_buf.into_inner()).unwrap();
- w.write_str("</div>").unwrap();
+ write!(
+ w,
+ "{}<div id=\"{id}\"{class_html}>{}</div>",
+ tmp_buf.into_inner(),
+ impls_buf.into_inner()
+ )
+ .unwrap();
}
}
@@ -1236,7 +1243,10 @@ fn render_deref_methods(
_ => None,
})
.expect("Expected associated type binding");
- debug!("Render deref methods for {:#?}, target {:#?}", impl_.inner_impl().for_, target);
+ debug!(
+ "Render deref methods for {for_:#?}, target {target:#?}",
+ for_ = impl_.inner_impl().for_
+ );
let what =
AssocItemRender::DerefFor { trait_: deref_type, type_: real_target, deref_mut_: deref_mut };
if let Some(did) = target.def_id(cache) {
@@ -1386,7 +1396,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
}
}
if out.is_empty() {
- write!(&mut out, "</code></pre>",);
+ out.write_str("</code></pre>");
}
(format!("{:#}", ty.print(cx)), out.into_inner())
@@ -1532,25 +1542,25 @@ fn render_impl(
let toggled = !doc_buffer.is_empty();
if toggled {
let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" };
- write!(w, "<details class=\"toggle{}\" open><summary>", method_toggle_class);
+ write!(w, "<details class=\"toggle{method_toggle_class}\" open><summary>");
}
match &*item.kind {
clean::MethodItem(..) | clean::TyMethodItem(_) => {
// Only render when the method is not static or we allow static methods
if render_method_item {
- let id = cx.derive_id(format!("{}.{}", item_type, name));
+ let id = cx.derive_id(format!("{item_type}.{name}"));
let source_id = trait_
.and_then(|trait_| {
trait_.items.iter().find(|item| {
item.name.map(|n| n.as_str().eq(name.as_str())).unwrap_or(false)
})
})
- .map(|item| format!("{}.{}", item.type_(), name));
- write!(w, "<section id=\"{}\" class=\"{}{}\">", id, item_type, in_trait_class,);
+ .map(|item| format!("{}.{name}", item.type_()));
+ write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
render_rightside(w, cx, item, containing_item, render_mode);
if trait_.is_some() {
// Anchors are only used on trait impls.
- write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id);
+ write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>");
}
w.write_str("<h4 class=\"code-header\">");
render_assoc_item(
@@ -1561,43 +1571,43 @@ fn render_impl(
cx,
render_mode,
);
- w.write_str("</h4>");
- w.write_str("</section>");
+ w.write_str("</h4></section>");
}
}
- kind @ (clean::TyAssocConstItem(ty) | clean::AssocConstItem(ty, _)) => {
- let source_id = format!("{}.{}", item_type, name);
- let id = cx.derive_id(source_id.clone());
- write!(w, "<section id=\"{}\" class=\"{}{}\">", id, item_type, in_trait_class);
+ kind @ (clean::TyAssocConstItem(generics, ty)
+ | clean::AssocConstItem(generics, ty, _)) => {
+ let source_id = format!("{item_type}.{name}");
+ let id = cx.derive_id(&source_id);
+ write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
render_rightside(w, cx, item, containing_item, render_mode);
if trait_.is_some() {
// Anchors are only used on trait impls.
- write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id);
+ write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>");
}
w.write_str("<h4 class=\"code-header\">");
assoc_const(
w,
item,
+ generics,
ty,
match kind {
- clean::TyAssocConstItem(_) => None,
- clean::AssocConstItem(_, default) => Some(default),
+ clean::TyAssocConstItem(..) => None,
+ clean::AssocConstItem(.., default) => Some(default),
_ => unreachable!(),
},
link.anchor(if trait_.is_some() { &source_id } else { &id }),
- "",
+ 0,
cx,
);
- w.write_str("</h4>");
- w.write_str("</section>");
+ w.write_str("</h4></section>");
}
clean::TyAssocTypeItem(generics, bounds) => {
- let source_id = format!("{}.{}", item_type, name);
- let id = cx.derive_id(source_id.clone());
- write!(w, "<section id=\"{}\" class=\"{}{}\">", id, item_type, in_trait_class);
+ let source_id = format!("{item_type}.{name}");
+ let id = cx.derive_id(&source_id);
+ write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
if trait_.is_some() {
// Anchors are only used on trait impls.
- write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id);
+ write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>");
}
w.write_str("<h4 class=\"code-header\">");
assoc_type(
@@ -1610,16 +1620,15 @@ fn render_impl(
0,
cx,
);
- w.write_str("</h4>");
- w.write_str("</section>");
+ w.write_str("</h4></section>");
}
clean::AssocTypeItem(tydef, _bounds) => {
- let source_id = format!("{}.{}", item_type, name);
- let id = cx.derive_id(source_id.clone());
- write!(w, "<section id=\"{}\" class=\"{}{}\">", id, item_type, in_trait_class);
+ let source_id = format!("{item_type}.{name}");
+ let id = cx.derive_id(&source_id);
+ write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
if trait_.is_some() {
// Anchors are only used on trait impls.
- write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id);
+ write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>");
}
w.write_str("<h4 class=\"code-header\">");
assoc_type(
@@ -1632,8 +1641,7 @@ fn render_impl(
0,
cx,
);
- w.write_str("</h4>");
- w.write_str("</section>");
+ w.write_str("</h4></section>");
}
clean::StrippedItem(..) => return,
_ => panic!("can't make docs for trait item with name {:?}", item.name),
@@ -1678,11 +1686,11 @@ fn render_impl(
rendering_params: ImplRenderingParameters,
) {
for trait_item in &t.items {
- // Skip over any default trait items that are impossible to call
+ // Skip over any default trait items that are impossible to reference
// (e.g. if it has a `Self: Sized` bound on an unsized type).
if let Some(impl_def_id) = parent.item_id.as_def_id()
&& let Some(trait_item_def_id) = trait_item.item_id.as_def_id()
- && cx.tcx().is_impossible_method((impl_def_id, trait_item_def_id))
+ && cx.tcx().is_impossible_associated_item((impl_def_id, trait_item_def_id))
{
continue;
}
@@ -1736,10 +1744,10 @@ fn render_impl(
close_tags.insert_str(0, "</details>");
write!(
w,
- "<details class=\"toggle implementors-toggle\"{}>",
+ "<details class=\"toggle implementors-toggle\"{}>\
+ <summary>",
if rendering_params.toggle_open_by_default { " open" } else { "" }
);
- write!(w, "<summary>")
}
render_impl_summary(
w,
@@ -1752,15 +1760,15 @@ fn render_impl(
aliases,
);
if toggled {
- write!(w, "</summary>")
+ w.write_str("</summary>");
}
if let Some(ref dox) = i.impl_item.opt_doc_value() {
if trait_.is_none() && i.inner_impl().items.is_empty() {
w.write_str(
"<div class=\"item-info\">\
- <div class=\"stab empty-impl\">This impl block contains no items.</div>\
- </div>",
+ <div class=\"stab empty-impl\">This impl block contains no items.</div>\
+ </div>",
);
}
write!(
@@ -1819,11 +1827,11 @@ fn render_rightside(
const_stable_since,
if has_src_ref { "" } else { " rightside" },
);
- if let Some(l) = src_href {
+ if let Some(link) = src_href {
if has_stability {
- write!(rightside, " · <a class=\"srclink\" href=\"{}\">source</a>", l)
+ write!(rightside, " · <a class=\"src\" href=\"{link}\">source</a>")
} else {
- write!(rightside, "<a class=\"srclink rightside\" href=\"{}\">source</a>", l)
+ write!(rightside, "<a class=\"src rightside\" href=\"{link}\">source</a>")
}
}
if has_stability && has_src_ref {
@@ -1852,10 +1860,13 @@ pub(crate) fn render_impl_summary(
} else {
format!(" data-aliases=\"{}\"", aliases.join(","))
};
- write!(w, "<section id=\"{}\" class=\"impl\"{}>", id, aliases);
+ write!(w, "<section id=\"{id}\" class=\"impl\"{aliases}>");
render_rightside(w, cx, &i.impl_item, containing_item, RenderMode::Normal);
- write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id);
- write!(w, "<h3 class=\"code-header\">");
+ write!(
+ w,
+ "<a href=\"#{id}\" class=\"anchor\">§</a>\
+ <h3 class=\"code-header\">"
+ );
if let Some(use_absolute) = use_absolute {
write!(w, "{}", inner_impl.print(use_absolute, cx));
@@ -1880,15 +1891,16 @@ pub(crate) fn render_impl_summary(
} else {
write!(w, "{}", inner_impl.print(false, cx));
}
- write!(w, "</h3>");
+ w.write_str("</h3>");
let is_trait = inner_impl.trait_.is_some();
if is_trait {
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
write!(
w,
- "<span class=\"item-info\"><div class=\"stab portability\">{}</div></span>",
- portability
+ "<span class=\"item-info\">\
+ <div class=\"stab portability\">{portability}</div>\
+ </span>",
);
}
}
@@ -1941,7 +1953,7 @@ pub(crate) fn small_url_encode(s: String) -> String {
// consistent with itself when encoding them.
st += "+";
} else {
- write!(st, "%{:02X}", b).unwrap();
+ write!(st, "%{b:02X}").unwrap();
}
// Invariant: if the current byte is not at the start of a multi-byte character,
// we need to get down here so that when the next turn of the loop comes around,
@@ -1988,7 +2000,9 @@ pub(crate) fn get_filtered_impls_for_reference<'a>(
) -> (Vec<&'a Impl>, Vec<&'a Impl>, Vec<&'a Impl>) {
let def_id = it.item_id.expect_def_id();
// If the reference primitive is somehow not defined, exit early.
- let Some(v) = shared.cache.impls.get(&def_id) else { return (Vec::new(), Vec::new(), Vec::new()) };
+ let Some(v) = shared.cache.impls.get(&def_id) else {
+ return (Vec::new(), Vec::new(), Vec::new());
+ };
// Since there is no "direct implementation" on the reference primitive type, we filter out
// every implementation which isn't a trait implementation.
let traits = v.iter().filter(|i| i.inner_impl().trait_.is_some());
@@ -2254,7 +2268,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
format!("lines {}-{}", line_lo + 1, line_hi + 1),
)
};
- let url = format!("{}{}#{}", cx.root_path(), call_data.url, anchor);
+ let url = format!("{}{}#{anchor}", cx.root_path(), call_data.url);
(url, title)
};
@@ -2264,7 +2278,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
Ok(contents) => contents,
Err(err) => {
let span = item.span(tcx).map_or(rustc_span::DUMMY_SP, |span| span.inner());
- tcx.sess.span_err(span, format!("failed to read file {}: {}", path.display(), err));
+ tcx.sess.span_err(span, format!("failed to read file {}: {err}", path.display()));
return false;
}
};
@@ -2323,7 +2337,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
.unwrap();
if line_ranges.len() > 1 {
- write!(w, r#"<button class="prev">&pr;</button> <button class="next">&sc;</button>"#)
+ w.write_str(r#"<button class="prev">&pr;</button> <button class="next">&sc;</button>"#)
.unwrap();
}
@@ -2359,7 +2373,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
highlight::DecorationInfo(decoration_info),
sources::SourceContext::Embedded { offset: line_min, needs_expansion },
);
- write!(w, "</div></div>").unwrap();
+ w.write_str("</div></div>").unwrap();
true
};
@@ -2426,8 +2440,10 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
// For the remaining examples, generate a <ul> containing links to the source files.
if it.peek().is_some() {
- write!(w, r#"<div class="example-links">Additional examples can be found in:<br><ul>"#)
- .unwrap();
+ w.write_str(
+ r#"<div class="example-links">Additional examples can be found in:<br><ul>"#,
+ )
+ .unwrap();
it.for_each(|(_, call_data)| {
let (url, _) = link_to_loc(call_data, &call_data.locations[0]);
write!(
@@ -2438,11 +2454,11 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
)
.unwrap();
});
- write!(w, "</ul></div>").unwrap();
+ w.write_str("</ul></div>").unwrap();
}
- write!(w, "</div></details>").unwrap();
+ w.write_str("</div></details>").unwrap();
}
- write!(w, "</div>").unwrap();
+ w.write_str("</div>").unwrap();
}