Skip to content

Commit

Permalink
Improved rustdoc rendering for unstable features
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jan 10, 2017
1 parent 26dc969 commit 0a1c9ae
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
29 changes: 18 additions & 11 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1871,8 +1871,10 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
};

if stab.level == stability::Unstable {
let unstable_extra = if show_reason {
match (!stab.feature.is_empty(), &cx.shared.issue_tracker_base_url, stab.issue) {
if show_reason {
let unstable_extra = match (!stab.feature.is_empty(),
&cx.shared.issue_tracker_base_url,
stab.issue) {
(true, &Some(ref tracker_url), Some(issue_no)) if issue_no > 0 =>
format!(" (<code>{}</code> <a href=\"{}{}\">#{}</a>)",
Escape(&stab.feature), tracker_url, issue_no, issue_no),
Expand All @@ -1882,17 +1884,22 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
(true, ..) =>
format!(" (<code>{}</code>)", Escape(&stab.feature)),
_ => String::new(),
};
if stab.unstable_reason.is_empty() {
stability.push(format!("<div class='stab unstable'>\
<span class=microscope>🔬</span> \
This is a nightly-only experimental API. {}</div>",
unstable_extra));
} else {
let text = format!("<summary><span class=microscope>🔬</span> \
This is a nightly-only experimental API. {}</summary>{}",
unstable_extra, MarkdownHtml(&stab.unstable_reason));
stability.push(format!("<div class='stab unstable'><details>{}</details></div>",
text));
}
} else {
String::new()
};
let unstable_reason = if show_reason && !stab.unstable_reason.is_empty() {
format!(": {}", stab.unstable_reason)
} else {
String::new()
};
let text = format!("Unstable{}{}", unstable_extra, MarkdownHtml(&unstable_reason));
stability.push(format!("<div class='stab unstable'>{}</div>", text))
stability.push(format!("<div class='stab unstable'>Experimental</div>"))
}
};
} else if let Some(depr) = item.deprecation.as_ref() {
let note = if show_reason && !depr.note.is_empty() {
Expand Down
8 changes: 8 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,14 @@ body.blur > :not(#help) {
display: inline;
}

.stab summary {
display: list-item;
}

.stab .microscope {
font-size: 1.5em;
}

.module-item .stab {
display: inline;
border-width: 0;
Expand Down
12 changes: 9 additions & 3 deletions src/test/rustdoc/issue-32374.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,28 @@
#![unstable(feature="test", issue = "32374")]

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

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

// @has issue_32374/struct.U.html '//*[@class="stab deprecated"]' \
// 'Deprecated since 1.0.0: deprecated'
// @has issue_32374/struct.U.html '//*[@class="stab unstable"]' \
// 'Unstable (test #32374): unstable'
// '🔬 This is a nightly-only experimental API. (test #32374)'
// @has issue_32374/struct.U.html '//details' \
// '🔬 This is a nightly-only experimental API. (test #32374)'
// @has issue_32374/struct.U.html '//summary' \
// '🔬 This is a nightly-only experimental API. (test #32374)'
// @has issue_32374/struct.U.html '//details/p' \
// 'unstable'
#[rustc_deprecated(since = "1.0.0", reason = "deprecated")]
#[unstable(feature = "test", issue = "32374", reason = "unstable")]
pub struct U;

0 comments on commit 0a1c9ae

Please sign in to comment.