{
let mut extra_info = vec![];
if let Some(depr @ Deprecation { note, since, is_since_rustc_version: _, suggestion: _ }) =
@@ -603,15 +620,10 @@ fn short_item_info(
if let Some(note) = note {
let note = note.as_str();
let html = MarkdownItemInfo(note, &mut cx.id_map);
- message.push_str(&format!(": {}", html.into_string()));
+ message.push_str(": ");
+ message.push_str(&html.into_string());
}
- extra_info.push(format!(
- "\
- 👎\
- {}\
-
",
- message,
- ));
+ extra_info.push(ShortItemInfo::Deprecation { message });
}
// Render unstable items. But don't render "rustc_private" crates (internal compiler crates).
@@ -622,26 +634,17 @@ fn short_item_info(
.filter(|stab| stab.feature != sym::rustc_private)
.map(|stab| (stab.level, stab.feature))
{
- let mut message = "🔬\
- This is a nightly-only experimental API."
- .to_owned();
-
- let mut feature = format!("{}
", Escape(feature.as_str()));
- if let (Some(url), Some(issue)) = (&cx.shared.issue_tracker_base_url, issue) {
- feature.push_str(&format!(
- " #{issue}",
- url = url,
- issue = issue
- ));
- }
-
- message.push_str(&format!(" ({})", feature));
-
- extra_info.push(format!("{}
", message));
+ let tracking = if let (Some(url), Some(issue)) = (&cx.shared.issue_tracker_base_url, issue)
+ {
+ Some((url.clone(), issue.get()))
+ } else {
+ None
+ };
+ extra_info.push(ShortItemInfo::Unstable { feature: feature.to_string(), tracking });
}
- if let Some(portability) = portability(item, parent) {
- extra_info.push(portability);
+ if let Some(message) = portability(item, parent) {
+ extra_info.push(ShortItemInfo::Portability { message });
}
extra_info
@@ -1473,7 +1476,9 @@ fn render_impl(
// We need the stability of the item from the trait
// because impls can't have a stability.
if item.doc_value().is_some() {
- document_item_info(&mut info_buffer, cx, it, Some(parent));
+ document_item_info(cx, it, Some(parent))
+ .render_into(&mut info_buffer)
+ .unwrap();
document_full(&mut doc_buffer, item, cx, HeadingOffset::H5);
short_documented = false;
} else {
@@ -1490,7 +1495,9 @@ fn render_impl(
}
}
} else {
- document_item_info(&mut info_buffer, cx, item, Some(parent));
+ document_item_info(cx, item, Some(parent))
+ .render_into(&mut info_buffer)
+ .unwrap();
if rendering_params.show_def_docs {
document_full(&mut doc_buffer, item, cx, HeadingOffset::H5);
short_documented = false;
@@ -1863,7 +1870,11 @@ pub(crate) fn render_impl_summary(
let is_trait = inner_impl.trait_.is_some();
if is_trait {
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
- write!(w, "{}", portability);
+ write!(
+ w,
+ "{}
",
+ portability
+ );
}
}
diff --git a/src/librustdoc/html/templates/item_info.html b/src/librustdoc/html/templates/item_info.html
new file mode 100644
index 0000000000000..d2ea9bdae9c65
--- /dev/null
+++ b/src/librustdoc/html/templates/item_info.html
@@ -0,0 +1,7 @@
+{% if !items.is_empty() %}
+ {# #}
+ {% for item in items %}
+ {{item|safe}} {# #}
+ {% endfor %}
+
+{% endif %}
diff --git a/src/librustdoc/html/templates/short_item_info.html b/src/librustdoc/html/templates/short_item_info.html
new file mode 100644
index 0000000000000..e3125af0e47ea
--- /dev/null
+++ b/src/librustdoc/html/templates/short_item_info.html
@@ -0,0 +1,23 @@
+{% match self %}
+ {% when Self::Deprecation with { message } %}
+ {# #}
+ 👎 {# #}
+ {{message}} {# #}
+
{# #}
+ {% when Self::Unstable with { feature, tracking } %}
+ {# #}
+
🔬 {# #}
+
{# #}
+ This is a nightly-only experimental API. ({# #}
+ {{feature}}
{# #}
+ {% match tracking %}
+ {% when Some with ((url, num)) %}
+ #{{num}} {# #}
+ {% when None %}
+ {% endmatch %}
+ ) {# #}
+ {# #}
+
{# #}
+ {% when Self::Portability with { message } %}
+ {{message|safe}}
{# #}
+{% endmatch %}