Skip to content

Commit c7c34fd

Browse files
committed
show unstable status for deprecated items
1 parent af000a7 commit c7c34fd

File tree

2 files changed

+63
-29
lines changed

2 files changed

+63
-29
lines changed

src/librustdoc/html/render.rs

+38-29
Original file line numberDiff line numberDiff line change
@@ -1626,8 +1626,8 @@ fn plain_summary_line(s: Option<&str>) -> String {
16261626
}
16271627

16281628
fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result {
1629-
if let Some(s) = short_stability(item, cx, true) {
1630-
write!(w, "<div class='stability'>{}</div>", s)?;
1629+
for stability in short_stability(item, cx, true) {
1630+
write!(w, "<div class='stability'>{}</div>", stability)?;
16311631
}
16321632
if let Some(s) = item.doc_value() {
16331633
write!(w, "<div class='docblock'>{}</div>", Markdown(s))?;
@@ -1747,8 +1747,15 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
17471747

17481748
_ => {
17491749
if myitem.name.is_none() { continue }
1750-
let stab_docs = if let Some(s) = short_stability(myitem, cx, false) {
1751-
format!("[{}]", s)
1750+
1751+
let stabilities = short_stability(myitem, cx, false);
1752+
1753+
let stab_docs = if !stabilities.is_empty() {
1754+
stabilities.iter()
1755+
.map(|s| format!("[{}]", s))
1756+
.collect::<Vec<_>>()
1757+
.as_slice()
1758+
.join(" ")
17521759
} else {
17531760
String::new()
17541761
};
@@ -1775,21 +1782,26 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
17751782
write!(w, "</table>")
17761783
}
17771784

1778-
fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Option<String> {
1779-
item.stability.as_ref().and_then(|stab| {
1785+
fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<String> {
1786+
let mut stability = vec![];
1787+
1788+
if let Some(stab) = item.stability.as_ref() {
17801789
let reason = if show_reason && !stab.reason.is_empty() {
17811790
format!(": {}", stab.reason)
17821791
} else {
17831792
String::new()
17841793
};
1785-
let text = if !stab.deprecated_since.is_empty() {
1794+
if !stab.deprecated_since.is_empty() {
17861795
let since = if show_reason {
17871796
format!(" since {}", Escape(&stab.deprecated_since))
17881797
} else {
17891798
String::new()
17901799
};
1791-
format!("Deprecated{}{}", since, Markdown(&reason))
1792-
} else if stab.level == stability::Unstable {
1800+
let text = format!("Deprecated{}{}", since, Markdown(&reason));
1801+
stability.push(format!("<em class='stab deprecated'>{}</em>", text))
1802+
};
1803+
1804+
if stab.level == stability::Unstable {
17931805
let unstable_extra = if show_reason {
17941806
match (!stab.feature.is_empty(), &cx.shared.issue_tracker_base_url, stab.issue) {
17951807
(true, &Some(ref tracker_url), Some(issue_no)) if issue_no > 0 =>
@@ -1805,29 +1817,26 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Optio
18051817
} else {
18061818
String::new()
18071819
};
1808-
format!("Unstable{}{}", unstable_extra, Markdown(&reason))
1820+
let text = format!("Unstable{}{}", unstable_extra, Markdown(&reason));
1821+
stability.push(format!("<em class='stab unstable'>{}</em>", text))
1822+
};
1823+
} else if let Some(depr) = item.deprecation.as_ref() {
1824+
let note = if show_reason && !depr.note.is_empty() {
1825+
format!(": {}", depr.note)
18091826
} else {
1810-
return None
1827+
String::new()
1828+
};
1829+
let since = if show_reason && !depr.since.is_empty() {
1830+
format!(" since {}", Escape(&depr.since))
1831+
} else {
1832+
String::new()
18111833
};
1812-
Some(format!("<em class='stab {}'>{}</em>",
1813-
item.stability_class(), text))
1814-
}).or_else(|| {
1815-
item.deprecation.as_ref().and_then(|depr| {
1816-
let note = if show_reason && !depr.note.is_empty() {
1817-
format!(": {}", depr.note)
1818-
} else {
1819-
String::new()
1820-
};
1821-
let since = if show_reason && !depr.since.is_empty() {
1822-
format!(" since {}", Escape(&depr.since))
1823-
} else {
1824-
String::new()
1825-
};
18261834

1827-
let text = format!("Deprecated{}{}", since, Markdown(&note));
1828-
Some(format!("<em class='stab deprecated'>{}</em>", text))
1829-
})
1830-
})
1835+
let text = format!("Deprecated{}{}", since, Markdown(&note));
1836+
stability.push(format!("<em class='stab deprecated'>{}</em>", text))
1837+
}
1838+
1839+
stability
18311840
}
18321841

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

src/test/rustdoc/issue-32374.rs

+25
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)