Skip to content

Commit a70fbf6

Browse files
committedApr 20, 2021
Auto merge of #83900 - torhovland:issue-83832, r=jyn514
Add stability tags to ImportItem. Fixes #83832.
2 parents b2c20b5 + 64a68ae commit a70fbf6

File tree

7 files changed

+153
-9
lines changed

7 files changed

+153
-9
lines changed
 

‎src/librustdoc/html/render/print_item.rs

+34-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_data_structures::fx::FxHashMap;
44
use rustc_hir as hir;
55
use rustc_hir::def::CtorKind;
66
use rustc_hir::def_id::DefId;
7+
use rustc_middle::dep_graph::DepContext;
78
use rustc_middle::middle::stability;
89
use rustc_middle::ty::TyCtxt;
910
use rustc_span::hygiene::MacroKind;
@@ -282,11 +283,40 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
282283
}
283284

284285
clean::ImportItem(ref import) => {
286+
let (stab, stab_tags) = if let Some(import_def_id) = import.source.did {
287+
let import_attrs = Box::new(clean::Attributes::from_ast(
288+
cx.tcx().sess().diagnostic(),
289+
cx.tcx().get_attrs(import_def_id),
290+
None,
291+
));
292+
293+
// Just need an item with the correct def_id and attrs
294+
let import_item = clean::Item {
295+
def_id: import_def_id,
296+
attrs: import_attrs,
297+
..myitem.clone()
298+
};
299+
300+
let stab = import_item.stability_class(cx.tcx());
301+
let stab_tags = Some(extra_info_tags(&import_item, item, cx.tcx()));
302+
(stab, stab_tags)
303+
} else {
304+
(None, None)
305+
};
306+
307+
let add = if stab.is_some() { " " } else { "" };
308+
285309
write!(
286310
w,
287-
"<tr><td><code>{}{}</code></td></tr>",
288-
myitem.visibility.print_with_space(myitem.def_id, cx),
289-
import.print(cx),
311+
"<tr class=\"{stab}{add}import-item\">\
312+
<td><code>{vis}{imp}</code></td>\
313+
<td class=\"docblock-short\">{stab_tags}</td>\
314+
</tr>",
315+
stab = stab.unwrap_or_default(),
316+
add = add,
317+
vis = myitem.visibility.print_with_space(myitem.def_id, cx),
318+
imp = import.print(cx),
319+
stab_tags = stab_tags.unwrap_or_default(),
290320
);
291321
}
292322

@@ -320,7 +350,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
320350
docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(),
321351
class = myitem.type_(),
322352
add = add,
323-
stab = stab.unwrap_or_else(String::new),
353+
stab = stab.unwrap_or_default(),
324354
unsafety_flag = unsafety_flag,
325355
href = item_path(myitem.type_(), &myitem.name.unwrap().as_str()),
326356
title = [full_path(cx, myitem), myitem.type_().to_string()]

‎src/librustdoc/html/static/rustdoc.css

+4-2
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,8 @@ body.blur > :not(#help) {
868868
0 -1px 0 black;
869869
}
870870

871-
.module-item .stab {
871+
.module-item .stab,
872+
.import-item .stab {
872873
border-radius: 3px;
873874
display: inline-block;
874875
font-size: 80%;
@@ -879,7 +880,8 @@ body.blur > :not(#help) {
879880
vertical-align: text-bottom;
880881
}
881882

882-
.module-item.unstable {
883+
.module-item.unstable,
884+
.import-item.unstable {
883885
opacity: 0.65;
884886
}
885887

‎src/librustdoc/html/static/themes/ayu.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ details.rustdoc-toggle > summary::before {
252252
color: #929292;
253253
}
254254

255-
.module-item .stab {
255+
.module-item .stab,
256+
.import-item .stab {
256257
color: #000;
257258
}
258259

‎src/librustdoc/html/static/themes/dark.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ details.rustdoc-toggle > summary::before {
217217
box-shadow: 0 0 8px 4px #078dd8;
218218
}
219219

220-
.module-item .stab {
220+
.module-item .stab,
221+
.import-item .stab {
221222
color: #ddd;
222223
}
223224

‎src/librustdoc/html/static/themes/light.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ details.rustdoc-toggle > summary::before {
215215
box-shadow: 0 0 8px #078dd8;
216216
}
217217

218-
.module-item .stab {
218+
.module-item .stab,
219+
.import-item .stab {
219220
color: #000;
220221
}
221222

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#![crate_name = "foo"]
2+
#![feature(doc_cfg)]
3+
4+
pub mod tag {
5+
#[deprecated(since = "0.1.8", note = "Use bar() instead")]
6+
pub trait Deprecated {}
7+
8+
#[doc(cfg(feature = "sync"))]
9+
pub trait Portability {}
10+
11+
#[deprecated(since = "0.1.8", note = "Use bar() instead")]
12+
#[doc(cfg(feature = "sync"))]
13+
pub trait Both {}
14+
15+
pub trait None {}
16+
}
17+
18+
// @has foo/mod1/index.html
19+
pub mod mod1 {
20+
// @has - '//code' 'pub use tag::Deprecated;'
21+
// @has - '//span' 'Deprecated'
22+
// @!has - '//span' 'sync'
23+
pub use tag::Deprecated;
24+
}
25+
26+
// @has foo/mod2/index.html
27+
pub mod mod2 {
28+
// @has - '//code' 'pub use tag::Portability;'
29+
// @!has - '//span' 'Deprecated'
30+
// @has - '//span' 'sync'
31+
pub use tag::Portability;
32+
}
33+
34+
// @has foo/mod3/index.html
35+
pub mod mod3 {
36+
// @has - '//code' 'pub use tag::Both;'
37+
// @has - '//span' 'Deprecated'
38+
// @has - '//span' 'sync'
39+
pub use tag::Both;
40+
}
41+
42+
// @has foo/mod4/index.html
43+
pub mod mod4 {
44+
// @has - '//code' 'pub use tag::None;'
45+
// @!has - '//span' 'Deprecated'
46+
// @!has - '//span' 'sync'
47+
pub use tag::None;
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#![crate_name = "foo"]
2+
#![feature(doc_cfg)]
3+
#![feature(staged_api)]
4+
#![stable(feature = "rust1", since = "1.0.0")]
5+
6+
#[stable(feature = "rust1", since = "1.0.0")]
7+
pub mod tag {
8+
#[unstable(feature = "humans", issue = "none")]
9+
pub trait Unstable {}
10+
11+
#[stable(feature = "rust1", since = "1.0.0")]
12+
#[doc(cfg(feature = "sync"))]
13+
pub trait Portability {}
14+
15+
#[unstable(feature = "humans", issue = "none")]
16+
#[doc(cfg(feature = "sync"))]
17+
pub trait Both {}
18+
19+
#[stable(feature = "rust1", since = "1.0.0")]
20+
pub trait None {}
21+
}
22+
23+
// @has foo/mod1/index.html
24+
#[stable(feature = "rust1", since = "1.0.0")]
25+
pub mod mod1 {
26+
// @has - '//code' 'pub use tag::Unstable;'
27+
// @has - '//span' 'Experimental'
28+
// @!has - '//span' 'sync'
29+
#[stable(feature = "rust1", since = "1.0.0")]
30+
pub use tag::Unstable;
31+
}
32+
33+
// @has foo/mod2/index.html
34+
#[stable(feature = "rust1", since = "1.0.0")]
35+
pub mod mod2 {
36+
// @has - '//code' 'pub use tag::Portability;'
37+
// @!has - '//span' 'Experimental'
38+
// @has - '//span' 'sync'
39+
#[stable(feature = "rust1", since = "1.0.0")]
40+
pub use tag::Portability;
41+
}
42+
43+
// @has foo/mod3/index.html
44+
#[stable(feature = "rust1", since = "1.0.0")]
45+
pub mod mod3 {
46+
// @has - '//code' 'pub use tag::Both;'
47+
// @has - '//span' 'Experimental'
48+
// @has - '//span' 'sync'
49+
#[stable(feature = "rust1", since = "1.0.0")]
50+
pub use tag::Both;
51+
}
52+
53+
// @has foo/mod4/index.html
54+
#[stable(feature = "rust1", since = "1.0.0")]
55+
pub mod mod4 {
56+
// @has - '//code' 'pub use tag::None;'
57+
// @!has - '//span' 'Experimental'
58+
// @!has - '//span' 'sync'
59+
#[stable(feature = "rust1", since = "1.0.0")]
60+
pub use tag::None;
61+
}

0 commit comments

Comments
 (0)