Count and show the deprecated attribute again

Since we don’t have Deprecated stability level anymore, the only other source of information is
deprecated-since version, which conveniently to us, only exists if the symbol is deprecated.

Fixes #21789
This commit is contained in:
Simonas Kazlauskas
2015-02-13 16:36:56 +02:00
parent ba2efe96ae
commit 6a67d86000
3 changed files with 37 additions and 13 deletions

View File

@@ -2490,6 +2490,7 @@ pub struct Stability {
pub level: attr::StabilityLevel, pub level: attr::StabilityLevel,
pub feature: String, pub feature: String,
pub since: String, pub since: String,
pub deprecated_since: String,
pub reason: String pub reason: String
} }
@@ -2500,6 +2501,8 @@ impl Clean<Stability> for attr::Stability {
feature: self.feature.to_string(), feature: self.feature.to_string(),
since: self.since.as_ref().map_or("".to_string(), since: self.since.as_ref().map_or("".to_string(),
|interned| interned.to_string()), |interned| interned.to_string()),
deprecated_since: self.deprecated_since.as_ref().map_or("".to_string(),
|istr| istr.to_string()),
reason: self.reason.as_ref().map_or("".to_string(), reason: self.reason.as_ref().map_or("".to_string(),
|interned| interned.to_string()), |interned| interned.to_string()),
} }

View File

@@ -711,7 +711,11 @@ impl<'a> fmt::Display for Stability<'a> {
match *stab { match *stab {
Some(ref stability) => { Some(ref stability) => {
write!(f, "<a class='stability {lvl}' title='{reason}'>{lvl}</a>", write!(f, "<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
lvl = stability.level, lvl = if stability.deprecated_since.is_empty() {
format!("{}", stability.level)
} else {
"Deprecated".to_string()
},
reason = stability.reason) reason = stability.reason)
} }
None => Ok(()) None => Ok(())
@@ -725,7 +729,11 @@ impl<'a> fmt::Display for ConciseStability<'a> {
match *stab { match *stab {
Some(ref stability) => { Some(ref stability) => {
write!(f, "<a class='stability {lvl}' title='{lvl}{colon}{reason}'></a>", write!(f, "<a class='stability {lvl}' title='{lvl}{colon}{reason}'></a>",
lvl = stability.level, lvl = if stability.deprecated_since.is_empty() {
format!("{}", stability.level)
} else {
"Deprecated".to_string()
},
colon = if stability.reason.len() > 0 { ": " } else { "" }, colon = if stability.reason.len() > 0 { ": " } else { "" },
reason = stability.reason) reason = stability.reason)
} }
@@ -763,6 +771,9 @@ impl fmt::Display for ModuleSummary {
try!(write!(f, "<span class='summary Unstable' \ try!(write!(f, "<span class='summary Unstable' \
style='width: {:.4}%; display: inline-block'>&nbsp</span>", style='width: {:.4}%; display: inline-block'>&nbsp</span>",
(100 * cnt.unstable) as f64/tot as f64)); (100 * cnt.unstable) as f64/tot as f64));
try!(write!(f, "<span class='summary Deprecated' \
style='width: {:.4}%; display: inline-block'>&nbsp</span>",
(100 * cnt.deprecated) as f64/tot as f64));
try!(write!(f, "<span class='summary Unmarked' \ try!(write!(f, "<span class='summary Unmarked' \
style='width: {:.4}%; display: inline-block'>&nbsp</span>", style='width: {:.4}%; display: inline-block'>&nbsp</span>",
(100 * cnt.unmarked) as f64/tot as f64)); (100 * cnt.unmarked) as f64/tot as f64));
@@ -778,11 +789,12 @@ impl fmt::Display for ModuleSummary {
let mut context = Vec::new(); let mut context = Vec::new();
let tot = self.counts.total(); let tot = self.counts.total();
let (stable, unstable, unmarked) = if tot == 0 { let (stable, unstable, deprecated, unmarked) = if tot == 0 {
(0, 0, 0) (0, 0, 0, 0)
} else { } else {
((100 * self.counts.stable)/tot, ((100 * self.counts.stable)/tot,
(100 * self.counts.unstable)/tot, (100 * self.counts.unstable)/tot,
(100 * self.counts.deprecated)/tot,
(100 * self.counts.unmarked)/tot) (100 * self.counts.unmarked)/tot)
}; };
@@ -794,11 +806,12 @@ its children (percentages total for {name}):
<blockquote> <blockquote>
<a class='stability Stable'></a> stable ({}%),<br/> <a class='stability Stable'></a> stable ({}%),<br/>
<a class='stability Unstable'></a> unstable ({}%),<br/> <a class='stability Unstable'></a> unstable ({}%),<br/>
<a class='stability Deprecated'></a> deprecated ({}%),<br/>
<a class='stability Unmarked'></a> unmarked ({}%) <a class='stability Unmarked'></a> unmarked ({}%)
</blockquote> </blockquote>
The counts do not include methods or trait The counts do not include methods or trait
implementations that are visible only through a re-exported type.", implementations that are visible only through a re-exported type.",
stable, unstable, unmarked, stable, unstable, deprecated, unmarked,
name=self.name)); name=self.name));
try!(write!(f, "<table>")); try!(write!(f, "<table>"));
try!(fmt_inner(f, &mut context, self)); try!(fmt_inner(f, &mut context, self));

View File

@@ -29,11 +29,12 @@ use html::render::cache;
/// The counts for each stability level. /// The counts for each stability level.
#[derive(Copy)] #[derive(Copy)]
pub struct Counts { pub struct Counts {
pub unstable: uint, pub deprecated: u64,
pub stable: uint, pub unstable: u64,
pub stable: u64,
/// No stability level, inherited or otherwise. /// No stability level, inherited or otherwise.
pub unmarked: uint, pub unmarked: u64,
} }
impl Add for Counts { impl Add for Counts {
@@ -41,6 +42,7 @@ impl Add for Counts {
fn add(self, other: Counts) -> Counts { fn add(self, other: Counts) -> Counts {
Counts { Counts {
deprecated: self.deprecated + other.deprecated,
unstable: self.unstable + other.unstable, unstable: self.unstable + other.unstable,
stable: self.stable + other.stable, stable: self.stable + other.stable,
unmarked: self.unmarked + other.unmarked, unmarked: self.unmarked + other.unmarked,
@@ -51,14 +53,15 @@ impl Add for Counts {
impl Counts { impl Counts {
fn zero() -> Counts { fn zero() -> Counts {
Counts { Counts {
deprecated: 0,
unstable: 0, unstable: 0,
stable: 0, stable: 0,
unmarked: 0, unmarked: 0,
} }
} }
pub fn total(&self) -> uint { pub fn total(&self) -> u64 {
self.unstable + self.stable + self.unmarked self.deprecated + self.unstable + self.stable + self.unmarked
} }
} }
@@ -94,11 +97,16 @@ fn visible(item: &Item) -> bool {
fn count_stability(stab: Option<&Stability>) -> Counts { fn count_stability(stab: Option<&Stability>) -> Counts {
match stab { match stab {
None => Counts { unmarked: 1, .. Counts::zero() }, None => Counts { unmarked: 1, .. Counts::zero() },
Some(ref stab) => match stab.level { Some(ref stab) => {
if !stab.deprecated_since.is_empty() {
return Counts { deprecated: 1, .. Counts::zero() };
}
match stab.level {
Unstable => Counts { unstable: 1, .. Counts::zero() }, Unstable => Counts { unstable: 1, .. Counts::zero() },
Stable => Counts { stable: 1, .. Counts::zero() }, Stable => Counts { stable: 1, .. Counts::zero() },
} }
} }
}
} }
fn summarize_methods(item: &Item) -> Counts { fn summarize_methods(item: &Item) -> Counts {