Skip to content

Commit b588f69

Browse files
committed
Rollup merge of #33160 - euclio:rustdoc-unstable-deprecated, r=alexcrichton
show unstable status for deprecated items Fixes #32374.
2 parents 5fba2bf + c7c34fd commit b588f69

File tree

2 files changed

+63
-29
lines changed

2 files changed

+63
-29
lines changed

src/librustdoc/html/render.rs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,8 +1640,8 @@ fn plain_summary_line(s: Option<&str>) -> String {
16401640
}
16411641

16421642
fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result {
1643-
if let Some(s) = short_stability(item, cx, true) {
1644-
write!(w, "<div class='stability'>{}</div>", s)?;
1643+
for stability in short_stability(item, cx, true) {
1644+
write!(w, "<div class='stability'>{}</div>", stability)?;
16451645
}
16461646
if let Some(s) = item.doc_value() {
16471647
write!(w, "<div class='docblock'>{}</div>", Markdown(s))?;
@@ -1761,8 +1761,15 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
17611761

17621762
_ => {
17631763
if myitem.name.is_none() { continue }
1764-
let stab_docs = if let Some(s) = short_stability(myitem, cx, false) {
1765-
format!("[{}]", s)
1764+
1765+
let stabilities = short_stability(myitem, cx, false);
1766+
1767+
let stab_docs = if !stabilities.is_empty() {
1768+
stabilities.iter()
1769+
.map(|s| format!("[{}]", s))
1770+
.collect::<Vec<_>>()
1771+
.as_slice()
1772+
.join(" ")
17661773
} else {
17671774
String::new()
17681775
};
@@ -1789,21 +1796,26 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
17891796
write!(w, "</table>")
17901797
}
17911798

1792-
fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Option<String> {
1793-
item.stability.as_ref().and_then(|stab| {
1799+
fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<String> {
1800+
let mut stability = vec![];
1801+
1802+
if let Some(stab) = item.stability.as_ref() {
17941803
let reason = if show_reason && !stab.reason.is_empty() {
17951804
format!(": {}", stab.reason)
17961805
} else {
17971806
String::new()
17981807
};
1799-
let text = if !stab.deprecated_since.is_empty() {
1808+
if !stab.deprecated_since.is_empty() {
18001809
let since = if show_reason {
18011810
format!(" since {}", Escape(&stab.deprecated_since))
18021811
} else {
18031812
String::new()
18041813
};
1805-
format!("Deprecated{}{}", since, Markdown(&reason))
1806-
} else if stab.level == stability::Unstable {
1814+
let text = format!("Deprecated{}{}", since, Markdown(&reason));
1815+
stability.push(format!("<em class='stab deprecated'>{}</em>", text))
1816+
};
1817+
1818+
if stab.level == stability::Unstable {
18071819
let unstable_extra = if show_reason {
18081820
match (!stab.feature.is_empty(), &cx.shared.issue_tracker_base_url, stab.issue) {
18091821
(true, &Some(ref tracker_url), Some(issue_no)) if issue_no > 0 =>
@@ -1819,29 +1831,26 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Optio
18191831
} else {
18201832
String::new()
18211833
};
1822-
format!("Unstable{}{}", unstable_extra, Markdown(&reason))
1834+
let text = format!("Unstable{}{}", unstable_extra, Markdown(&reason));
1835+
stability.push(format!("<em class='stab unstable'>{}</em>", text))
1836+
};
1837+
} else if let Some(depr) = item.deprecation.as_ref() {
1838+
let note = if show_reason && !depr.note.is_empty() {
1839+
format!(": {}", depr.note)
18231840
} else {
1824-
return None
1841+
String::new()
1842+
};
1843+
let since = if show_reason && !depr.since.is_empty() {
1844+
format!(" since {}", Escape(&depr.since))
1845+
} else {
1846+
String::new()
18251847
};
1826-
Some(format!("<em class='stab {}'>{}</em>",
1827-
item.stability_class(), text))
1828-
}).or_else(|| {
1829-
item.deprecation.as_ref().and_then(|depr| {
1830-
let note = if show_reason && !depr.note.is_empty() {
1831-
format!(": {}", depr.note)
1832-
} else {
1833-
String::new()
1834-
};
1835-
let since = if show_reason && !depr.since.is_empty() {
1836-
format!(" since {}", Escape(&depr.since))
1837-
} else {
1838-
String::new()
1839-
};
18401848

1841-
let text = format!("Deprecated{}{}", since, Markdown(&note));
1842-
Some(format!("<em class='stab deprecated'>{}</em>", text))
1843-
})
1844-
})
1849+
let text = format!("Deprecated{}{}", since, Markdown(&note));
1850+
stability.push(format!("<em class='stab deprecated'>{}</em>", text))
1851+
}
1852+
1853+
stability
18451854
}
18461855

18471856
struct Initializer<'a>(&'a str);

src/test/rustdoc/issue-32374.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(staged_api)]
12+
#![doc(issue_tracker_base_url = "http://issue_url/")]
13+
14+
#![unstable(feature="test", issue = "32374")]
15+
16+
// @has issue_32374/index.html '//*[@class="docblock short"]' \
17+
// '[Deprecated] [Unstable]'
18+
19+
// @has issue_32374/struct.T.html '//*[@class="stab deprecated"]' \
20+
// 'Deprecated since 1.0.0: text'
21+
// @has - '<code>test</code>'
22+
// @has - '<a href="http://issue_url/32374">#32374</a>'
23+
#[rustc_deprecated(since = "1.0.0", reason = "text")]
24+
#[unstable(feature = "test", issue = "32374")]
25+
pub struct T;

0 commit comments

Comments
 (0)