summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/html/highlight.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustdoc/html/highlight.rs')
-rw-r--r--src/librustdoc/html/highlight.rs38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs
index c94968b48..039e8cdb9 100644
--- a/src/librustdoc/html/highlight.rs
+++ b/src/librustdoc/html/highlight.rs
@@ -928,18 +928,16 @@ fn string_without_closing_tag<T: Display>(
href_context: &Option<HrefContext<'_, '_>>,
open_tag: bool,
) -> Option<&'static str> {
- let Some(klass) = klass
- else {
- write!(out, "{}", text).unwrap();
+ let Some(klass) = klass else {
+ write!(out, "{text}").unwrap();
return None;
};
- let Some(def_span) = klass.get_span()
- else {
+ let Some(def_span) = klass.get_span() else {
if !open_tag {
- write!(out, "{}", text).unwrap();
+ write!(out, "{text}").unwrap();
return None;
}
- write!(out, "<span class=\"{}\">{}", klass.as_html(), text).unwrap();
+ write!(out, "<span class=\"{klass}\">{text}", klass = klass.as_html()).unwrap();
return Some("</span>");
};
@@ -949,14 +947,17 @@ fn string_without_closing_tag<T: Display>(
match t {
"self" | "Self" => write!(
&mut path,
- "<span class=\"{}\">{}</span>",
- Class::Self_(DUMMY_SP).as_html(),
- t
+ "<span class=\"{klass}\">{t}</span>",
+ klass = Class::Self_(DUMMY_SP).as_html(),
),
"crate" | "super" => {
- write!(&mut path, "<span class=\"{}\">{}</span>", Class::KeyWord.as_html(), t)
+ write!(
+ &mut path,
+ "<span class=\"{klass}\">{t}</span>",
+ klass = Class::KeyWord.as_html(),
+ )
}
- t => write!(&mut path, "{}", t),
+ t => write!(&mut path, "{t}"),
}
.expect("Failed to build source HTML path");
path
@@ -988,19 +989,24 @@ fn string_without_closing_tag<T: Display>(
)
.ok()
.map(|(url, _, _)| url),
+ LinkFromSrc::Doc(def_id) => {
+ format::href_with_root_path(*def_id, context, Some(&href_context.root_path))
+ .ok()
+ .map(|(doc_link, _, _)| doc_link)
+ }
}
})
{
if !open_tag {
// We're already inside an element which has the same klass, no need to give it
// again.
- write!(out, "<a href=\"{}\">{}", href, text_s).unwrap();
+ write!(out, "<a href=\"{href}\">{text_s}").unwrap();
} else {
let klass_s = klass.as_html();
if klass_s.is_empty() {
- write!(out, "<a href=\"{}\">{}", href, text_s).unwrap();
+ write!(out, "<a href=\"{href}\">{text_s}").unwrap();
} else {
- write!(out, "<a class=\"{}\" href=\"{}\">{}", klass_s, href, text_s).unwrap();
+ write!(out, "<a class=\"{klass_s}\" href=\"{href}\">{text_s}").unwrap();
}
}
return Some("</a>");
@@ -1015,7 +1021,7 @@ fn string_without_closing_tag<T: Display>(
out.write_str(&text_s).unwrap();
Some("")
} else {
- write!(out, "<span class=\"{}\">{}", klass_s, text_s).unwrap();
+ write!(out, "<span class=\"{klass_s}\">{text_s}").unwrap();
Some("</span>")
}
}