summaryrefslogtreecommitdiff
path: root/src/librustdoc/html/render/print_item.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustdoc/html/render/print_item.rs')
-rw-r--r--src/librustdoc/html/render/print_item.rs31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index d120e7f36eb..38276e4d20c 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -436,16 +436,9 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
}
clean::ImportItem(ref import) => {
- let stab_tags = if let Some(import_def_id) = import.source.did {
- // Just need an item with the correct def_id and attrs
- let import_item =
- clean::Item { item_id: import_def_id.into(), ..(*myitem).clone() };
-
- let stab_tags = Some(extra_info_tags(&import_item, item, tcx).to_string());
- stab_tags
- } else {
- None
- };
+ let stab_tags = import.source.did.map_or_else(String::new, |import_def_id| {
+ extra_info_tags(tcx, myitem, item, Some(import_def_id)).to_string()
+ });
w.write_str(ITEM_TABLE_ROW_OPEN);
let id = match import.kind {
@@ -454,7 +447,6 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
}
clean::ImportKind::Glob => String::new(),
};
- let stab_tags = stab_tags.unwrap_or_default();
let (stab_tags_before, stab_tags_after) = if stab_tags.is_empty() {
("", "")
} else {
@@ -521,7 +513,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
{docs_before}{docs}{docs_after}",
name = EscapeBodyTextWithWbr(myitem.name.unwrap().as_str()),
visibility_and_hidden = visibility_and_hidden,
- stab_tags = extra_info_tags(myitem, item, tcx),
+ stab_tags = extra_info_tags(tcx, myitem, item, None),
class = myitem.type_(),
unsafety_flag = unsafety_flag,
href = item_path(myitem.type_(), myitem.name.unwrap().as_str()),
@@ -544,9 +536,10 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
/// Render the stability, deprecation and portability tags that are displayed in the item's summary
/// at the module level.
fn extra_info_tags<'a, 'tcx: 'a>(
+ tcx: TyCtxt<'tcx>,
item: &'a clean::Item,
parent: &'a clean::Item,
- tcx: TyCtxt<'tcx>,
+ import_def_id: Option<DefId>,
) -> impl fmt::Display + 'a + Captures<'tcx> {
display_fn(move |f| {
fn tag_html<'a>(
@@ -564,18 +557,18 @@ fn extra_info_tags<'a, 'tcx: 'a>(
}
// The trailing space after each tag is to space it properly against the rest of the docs.
- if let Some(depr) = &item.deprecation(tcx) {
+ let deprecation = import_def_id
+ .map_or_else(|| item.deprecation(tcx), |import_did| tcx.lookup_deprecation(import_did));
+ if let Some(depr) = deprecation {
let message = if depr.is_in_effect() { "Deprecated" } else { "Deprecation planned" };
write!(f, "{}", tag_html("deprecated", "", message))?;
}
// The "rustc_private" crates are permanently unstable so it makes no sense
// to render "unstable" everywhere.
- if item
- .stability(tcx)
- .as_ref()
- .is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private)
- {
+ let stability = import_def_id
+ .map_or_else(|| item.stability(tcx), |import_did| tcx.lookup_stability(import_did));
+ if stability.is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private) {
write!(f, "{}", tag_html("unstable", "", "Experimental"))?;
}