Skip to content

Commit 0a1c9ae

Browse files
committed
Improved rustdoc rendering for unstable features
1 parent 26dc969 commit 0a1c9ae

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/librustdoc/html/render.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -1871,8 +1871,10 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
18711871
};
18721872

18731873
if stab.level == stability::Unstable {
1874-
let unstable_extra = if show_reason {
1875-
match (!stab.feature.is_empty(), &cx.shared.issue_tracker_base_url, stab.issue) {
1874+
if show_reason {
1875+
let unstable_extra = match (!stab.feature.is_empty(),
1876+
&cx.shared.issue_tracker_base_url,
1877+
stab.issue) {
18761878
(true, &Some(ref tracker_url), Some(issue_no)) if issue_no > 0 =>
18771879
format!(" (<code>{}</code> <a href=\"{}{}\">#{}</a>)",
18781880
Escape(&stab.feature), tracker_url, issue_no, issue_no),
@@ -1882,17 +1884,22 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
18821884
(true, ..) =>
18831885
format!(" (<code>{}</code>)", Escape(&stab.feature)),
18841886
_ => String::new(),
1887+
};
1888+
if stab.unstable_reason.is_empty() {
1889+
stability.push(format!("<div class='stab unstable'>\
1890+
<span class=microscope>🔬</span> \
1891+
This is a nightly-only experimental API. {}</div>",
1892+
unstable_extra));
1893+
} else {
1894+
let text = format!("<summary><span class=microscope>🔬</span> \
1895+
This is a nightly-only experimental API. {}</summary>{}",
1896+
unstable_extra, MarkdownHtml(&stab.unstable_reason));
1897+
stability.push(format!("<div class='stab unstable'><details>{}</details></div>",
1898+
text));
18851899
}
18861900
} else {
1887-
String::new()
1888-
};
1889-
let unstable_reason = if show_reason && !stab.unstable_reason.is_empty() {
1890-
format!(": {}", stab.unstable_reason)
1891-
} else {
1892-
String::new()
1893-
};
1894-
let text = format!("Unstable{}{}", unstable_extra, MarkdownHtml(&unstable_reason));
1895-
stability.push(format!("<div class='stab unstable'>{}</div>", text))
1901+
stability.push(format!("<div class='stab unstable'>Experimental</div>"))
1902+
}
18961903
};
18971904
} else if let Some(depr) = item.deprecation.as_ref() {
18981905
let note = if show_reason && !depr.note.is_empty() {

src/librustdoc/html/static/rustdoc.css

+8
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,14 @@ body.blur > :not(#help) {
535535
display: inline;
536536
}
537537

538+
.stab summary {
539+
display: list-item;
540+
}
541+
542+
.stab .microscope {
543+
font-size: 1.5em;
544+
}
545+
538546
.module-item .stab {
539547
display: inline;
540548
border-width: 0;

src/test/rustdoc/issue-32374.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,28 @@
1414
#![unstable(feature="test", issue = "32374")]
1515

1616
// @has issue_32374/index.html '//*[@class="docblock-short"]' \
17-
// '[Deprecated] [Unstable]'
17+
// '[Deprecated] [Experimental]'
1818

1919
// @has issue_32374/struct.T.html '//*[@class="stab deprecated"]' \
2020
// 'Deprecated since 1.0.0: text'
2121
// @has - '<code>test</code>'
2222
// @has - '<a href="http://issue_url/32374">#32374</a>'
2323
// @matches issue_32374/struct.T.html '//*[@class="stab unstable"]' \
24-
// 'Unstable \(test #32374\)$'
24+
// '🔬 This is a nightly-only experimental API. \(test #32374\)$'
2525
#[rustc_deprecated(since = "1.0.0", reason = "text")]
2626
#[unstable(feature = "test", issue = "32374")]
2727
pub struct T;
2828

2929
// @has issue_32374/struct.U.html '//*[@class="stab deprecated"]' \
3030
// 'Deprecated since 1.0.0: deprecated'
3131
// @has issue_32374/struct.U.html '//*[@class="stab unstable"]' \
32-
// 'Unstable (test #32374): unstable'
32+
// '🔬 This is a nightly-only experimental API. (test #32374)'
33+
// @has issue_32374/struct.U.html '//details' \
34+
// '🔬 This is a nightly-only experimental API. (test #32374)'
35+
// @has issue_32374/struct.U.html '//summary' \
36+
// '🔬 This is a nightly-only experimental API. (test #32374)'
37+
// @has issue_32374/struct.U.html '//details/p' \
38+
// 'unstable'
3339
#[rustc_deprecated(since = "1.0.0", reason = "deprecated")]
3440
#[unstable(feature = "test", issue = "32374", reason = "unstable")]
3541
pub struct U;

0 commit comments

Comments
 (0)