Skip to content

Commit 40ccb63

Browse files
Rollup merge of rust-lang#83900 - torhovland:issue-83832, r=jyn514,GuillaumeGomez
Add stability tags to ImportItem. Fixes rust-lang#83832.
2 parents 3541fd2 + e2a77b3 commit 40ccb63

10 files changed

+152
-13
lines changed

src/librustdoc/clean/inline.rs

+1
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ fn build_module(
477477
}],
478478
},
479479
did: None,
480+
attrs: None,
480481
},
481482
true,
482483
)),

src/librustdoc/clean/types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,7 @@ crate enum ImportKind {
20812081
crate struct ImportSource {
20822082
crate path: Path,
20832083
crate did: Option<DefId>,
2084+
crate attrs: Option<Attributes>,
20842085
}
20852086

20862087
#[derive(Clone, Debug)]

src/librustdoc/clean/utils.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,10 @@ crate fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
468468
}
469469

470470
crate fn resolve_use_source(cx: &mut DocContext<'_>, path: Path) -> ImportSource {
471-
ImportSource {
472-
did: if path.res.opt_def_id().is_none() { None } else { Some(register_res(cx, path.res)) },
473-
path,
474-
}
471+
let did = if path.res.opt_def_id().is_none() { None } else { Some(register_res(cx, path.res)) };
472+
let attrs = did.map(|did| cx.tcx.get_attrs(did).clean(cx));
473+
474+
ImportSource { did, path, attrs }
475475
}
476476

477477
crate fn enter_impl_trait<F, R>(cx: &mut DocContext<'_>, f: F) -> R

src/librustdoc/html/render/print_item.rs

+27-4
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,34 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
282282
}
283283

284284
clean::ImportItem(ref import) => {
285+
let (stab, stab_tags) = if let (Some(def_id), Some(attrs)) =
286+
(import.source.did, import.source.attrs.clone())
287+
{
288+
let attrs = Box::new(attrs);
289+
290+
// Just need an item with the correct def_id and attrs
291+
let import_item = clean::Item { def_id, attrs, ..myitem.clone() };
292+
293+
let stab = import_item.stability_class(cx.tcx());
294+
let stab_tags = Some(extra_info_tags(&import_item, item, cx.tcx()));
295+
(stab, stab_tags)
296+
} else {
297+
(None, None)
298+
};
299+
300+
let add = if stab.is_some() { " " } else { "" };
301+
285302
write!(
286303
w,
287-
"<tr><td><code>{}{}</code></td></tr>",
288-
myitem.visibility.print_with_space(myitem.def_id, cx),
289-
import.print(cx),
304+
"<tr class=\"{stab}{add}import-item\">\
305+
<td><code>{vis}{imp}</code></td>\
306+
<td class=\"docblock-short\">{stab_tags}</td>\
307+
</tr>",
308+
stab = stab.unwrap_or_default(),
309+
add = add,
310+
vis = myitem.visibility.print_with_space(myitem.def_id, cx),
311+
imp = import.print(cx),
312+
stab_tags = stab_tags.unwrap_or_default(),
290313
);
291314
}
292315

@@ -320,7 +343,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
320343
docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(),
321344
class = myitem.type_(),
322345
add = add,
323-
stab = stab.unwrap_or_else(String::new),
346+
stab = stab.unwrap_or_default(),
324347
unsafety_flag = unsafety_flag,
325348
href = item_path(myitem.type_(), &myitem.name.unwrap().as_str()),
326349
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)