about summary refs log tree commit diff
path: root/src/librustdoc/html/render
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-04-20 06:03:15 +0000
committerbors <bors@rust-lang.org>2021-04-20 06:03:15 +0000
commita70fbf6620ddaacc2ef805fa8c4ac2dc9bf02f3c (patch)
tree60bb10feeedfd7c83f078324c7548d697a601219 /src/librustdoc/html/render
parentb2c20b51ed838368d3f2bdccb63f401bcddb7e1c (diff)
parent64a68ae69adf508c73e642ff8739d3e547878467 (diff)
downloadrust-a70fbf6620ddaacc2ef805fa8c4ac2dc9bf02f3c.tar.gz
rust-a70fbf6620ddaacc2ef805fa8c4ac2dc9bf02f3c.zip
Auto merge of #83900 - torhovland:issue-83832, r=jyn514
Add stability tags to ImportItem.

Fixes #83832.
Diffstat (limited to 'src/librustdoc/html/render')
-rw-r--r--src/librustdoc/html/render/print_item.rs38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index 42b79503017..a303ca956d8 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -4,6 +4,7 @@ use rustc_data_structures::fx::FxHashMap;
 use rustc_hir as hir;
 use rustc_hir::def::CtorKind;
 use rustc_hir::def_id::DefId;
+use rustc_middle::dep_graph::DepContext;
 use rustc_middle::middle::stability;
 use rustc_middle::ty::TyCtxt;
 use rustc_span::hygiene::MacroKind;
@@ -282,11 +283,40 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
             }
 
             clean::ImportItem(ref import) => {
+                let (stab, stab_tags) = if let Some(import_def_id) = import.source.did {
+                    let import_attrs = Box::new(clean::Attributes::from_ast(
+                        cx.tcx().sess().diagnostic(),
+                        cx.tcx().get_attrs(import_def_id),
+                        None,
+                    ));
+
+                    // Just need an item with the correct def_id and attrs
+                    let import_item = clean::Item {
+                        def_id: import_def_id,
+                        attrs: import_attrs,
+                        ..myitem.clone()
+                    };
+
+                    let stab = import_item.stability_class(cx.tcx());
+                    let stab_tags = Some(extra_info_tags(&import_item, item, cx.tcx()));
+                    (stab, stab_tags)
+                } else {
+                    (None, None)
+                };
+
+                let add = if stab.is_some() { " " } else { "" };
+
                 write!(
                     w,
-                    "<tr><td><code>{}{}</code></td></tr>",
-                    myitem.visibility.print_with_space(myitem.def_id, cx),
-                    import.print(cx),
+                    "<tr class=\"{stab}{add}import-item\">\
+                         <td><code>{vis}{imp}</code></td>\
+                         <td class=\"docblock-short\">{stab_tags}</td>\
+                     </tr>",
+                    stab = stab.unwrap_or_default(),
+                    add = add,
+                    vis = myitem.visibility.print_with_space(myitem.def_id, cx),
+                    imp = import.print(cx),
+                    stab_tags = stab_tags.unwrap_or_default(),
                 );
             }
 
@@ -320,7 +350,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
                     docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(),
                     class = myitem.type_(),
                     add = add,
-                    stab = stab.unwrap_or_else(String::new),
+                    stab = stab.unwrap_or_default(),
                     unsafety_flag = unsafety_flag,
                     href = item_path(myitem.type_(), &myitem.name.unwrap().as_str()),
                     title = [full_path(cx, myitem), myitem.type_().to_string()]