1
Fork 0

show unstable status for deprecated items

This commit is contained in:
Andy Russell 2016-04-22 23:26:08 -04:00
parent af000a7bbf
commit c7c34fdace
No known key found for this signature in database
GPG key ID: BE2221033EDBC374
2 changed files with 64 additions and 30 deletions

View file

@ -1626,8 +1626,8 @@ fn plain_summary_line(s: Option<&str>) -> String {
} }
fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result { fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result {
if let Some(s) = short_stability(item, cx, true) { for stability in short_stability(item, cx, true) {
write!(w, "<div class='stability'>{}</div>", s)?; write!(w, "<div class='stability'>{}</div>", stability)?;
} }
if let Some(s) = item.doc_value() { if let Some(s) = item.doc_value() {
write!(w, "<div class='docblock'>{}</div>", Markdown(s))?; write!(w, "<div class='docblock'>{}</div>", Markdown(s))?;
@ -1747,8 +1747,15 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
_ => { _ => {
if myitem.name.is_none() { continue } if myitem.name.is_none() { continue }
let stab_docs = if let Some(s) = short_stability(myitem, cx, false) {
format!("[{}]", s) let stabilities = short_stability(myitem, cx, false);
let stab_docs = if !stabilities.is_empty() {
stabilities.iter()
.map(|s| format!("[{}]", s))
.collect::<Vec<_>>()
.as_slice()
.join(" ")
} else { } else {
String::new() String::new()
}; };
@ -1775,21 +1782,26 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
write!(w, "</table>") write!(w, "</table>")
} }
fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Option<String> { fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<String> {
item.stability.as_ref().and_then(|stab| { let mut stability = vec![];
if let Some(stab) = item.stability.as_ref() {
let reason = if show_reason && !stab.reason.is_empty() { let reason = if show_reason && !stab.reason.is_empty() {
format!(": {}", stab.reason) format!(": {}", stab.reason)
} else { } else {
String::new() String::new()
}; };
let text = if !stab.deprecated_since.is_empty() { if !stab.deprecated_since.is_empty() {
let since = if show_reason { let since = if show_reason {
format!(" since {}", Escape(&stab.deprecated_since)) format!(" since {}", Escape(&stab.deprecated_since))
} else { } else {
String::new() String::new()
}; };
format!("Deprecated{}{}", since, Markdown(&reason)) let text = format!("Deprecated{}{}", since, Markdown(&reason));
} else if stab.level == stability::Unstable { stability.push(format!("<em class='stab deprecated'>{}</em>", text))
};
if stab.level == stability::Unstable {
let unstable_extra = if show_reason { let unstable_extra = if show_reason {
match (!stab.feature.is_empty(), &cx.shared.issue_tracker_base_url, stab.issue) { 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 => (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
} else { } else {
String::new() String::new()
}; };
format!("Unstable{}{}", unstable_extra, Markdown(&reason)) let text = format!("Unstable{}{}", unstable_extra, Markdown(&reason));
} else { stability.push(format!("<em class='stab unstable'>{}</em>", text))
return None };
} else if let Some(depr) = item.deprecation.as_ref() {
let note = if show_reason && !depr.note.is_empty() {
format!(": {}", depr.note)
} else {
String::new()
};
let since = if show_reason && !depr.since.is_empty() {
format!(" since {}", Escape(&depr.since))
} else {
String::new()
}; };
Some(format!("<em class='stab {}'>{}</em>",
item.stability_class(), text))
}).or_else(|| {
item.deprecation.as_ref().and_then(|depr| {
let note = if show_reason && !depr.note.is_empty() {
format!(": {}", depr.note)
} else {
String::new()
};
let since = if show_reason && !depr.since.is_empty() {
format!(" since {}", Escape(&depr.since))
} else {
String::new()
};
let text = format!("Deprecated{}{}", since, Markdown(&note)); let text = format!("Deprecated{}{}", since, Markdown(&note));
Some(format!("<em class='stab deprecated'>{}</em>", text)) stability.push(format!("<em class='stab deprecated'>{}</em>", text))
}) }
})
stability
} }
struct Initializer<'a>(&'a str); struct Initializer<'a>(&'a str);

View file

@ -0,0 +1,25 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(staged_api)]
#![doc(issue_tracker_base_url = "http://issue_url/")]
#![unstable(feature="test", issue = "32374")]
// @has issue_32374/index.html '//*[@class="docblock short"]' \
// '[Deprecated] [Unstable]'
// @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>'
#[rustc_deprecated(since = "1.0.0", reason = "text")]
#[unstable(feature = "test", issue = "32374")]
pub struct T;