Skip to content

Count and show the deprecated attribute again #22273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2490,6 +2490,7 @@ pub struct Stability {
pub level: attr::StabilityLevel,
pub feature: String,
pub since: String,
pub deprecated_since: String,
pub reason: String
}

Expand All @@ -2500,6 +2501,8 @@ impl Clean<Stability> for attr::Stability {
feature: self.feature.to_string(),
since: self.since.as_ref().map_or("".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(),
|interned| interned.to_string()),
}
Expand Down
23 changes: 18 additions & 5 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,11 @@ impl<'a> fmt::Display for Stability<'a> {
match *stab {
Some(ref stability) => {
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)
}
None => Ok(())
Expand All @@ -725,7 +729,11 @@ impl<'a> fmt::Display for ConciseStability<'a> {
match *stab {
Some(ref stability) => {
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 { "" },
reason = stability.reason)
}
Expand Down Expand Up @@ -763,6 +771,9 @@ impl fmt::Display for ModuleSummary {
try!(write!(f, "<span class='summary Unstable' \
style='width: {:.4}%; display: inline-block'>&nbsp</span>",
(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' \
style='width: {:.4}%; display: inline-block'>&nbsp</span>",
(100 * cnt.unmarked) as f64/tot as f64));
Expand All @@ -778,11 +789,12 @@ impl fmt::Display for ModuleSummary {
let mut context = Vec::new();

let tot = self.counts.total();
let (stable, unstable, unmarked) = if tot == 0 {
(0, 0, 0)
let (stable, unstable, deprecated, unmarked) = if tot == 0 {
(0, 0, 0, 0)
} else {
((100 * self.counts.stable)/tot,
(100 * self.counts.unstable)/tot,
(100 * self.counts.deprecated)/tot,
(100 * self.counts.unmarked)/tot)
};

Expand All @@ -794,11 +806,12 @@ its children (percentages total for {name}):
<blockquote>
<a class='stability Stable'></a> stable ({}%),<br/>
<a class='stability Unstable'></a> unstable ({}%),<br/>
<a class='stability Deprecated'></a> deprecated ({}%),<br/>
<a class='stability Unmarked'></a> unmarked ({}%)
</blockquote>
The counts do not include methods or trait
implementations that are visible only through a re-exported type.",
stable, unstable, unmarked,
stable, unstable, deprecated, unmarked,
name=self.name));
try!(write!(f, "<table>"));
try!(fmt_inner(f, &mut context, self));
Expand Down
24 changes: 16 additions & 8 deletions src/librustdoc/stability_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ use html::render::cache;
/// The counts for each stability level.
#[derive(Copy)]
pub struct Counts {
pub unstable: uint,
pub stable: uint,
pub deprecated: u64,
pub unstable: u64,
pub stable: u64,

/// No stability level, inherited or otherwise.
pub unmarked: uint,
pub unmarked: u64,
}

impl Add for Counts {
type Output = Counts;

fn add(self, other: Counts) -> Counts {
Counts {
deprecated: self.deprecated + other.deprecated,
unstable: self.unstable + other.unstable,
stable: self.stable + other.stable,
unmarked: self.unmarked + other.unmarked,
Expand All @@ -51,14 +53,15 @@ impl Add for Counts {
impl Counts {
fn zero() -> Counts {
Counts {
deprecated: 0,
unstable: 0,
stable: 0,
unmarked: 0,
}
}

pub fn total(&self) -> uint {
self.unstable + self.stable + self.unmarked
pub fn total(&self) -> u64 {
self.deprecated + self.unstable + self.stable + self.unmarked
}
}

Expand Down Expand Up @@ -94,9 +97,14 @@ fn visible(item: &Item) -> bool {
fn count_stability(stab: Option<&Stability>) -> Counts {
match stab {
None => Counts { unmarked: 1, .. Counts::zero() },
Some(ref stab) => match stab.level {
Unstable => Counts { unstable: 1, .. Counts::zero() },
Stable => Counts { stable: 1, .. Counts::zero() },
Some(ref stab) => {
if !stab.deprecated_since.is_empty() {
return Counts { deprecated: 1, .. Counts::zero() };
}
match stab.level {
Unstable => Counts { unstable: 1, .. Counts::zero() },
Stable => Counts { stable: 1, .. Counts::zero() },
}
}
}
}
Expand Down