Skip to content

Commit 0a46933

Browse files
committed
rustdoc: Overhaul stability displays
This commit is an overhaul to how rustdoc deals with stability of the standard library. The handling has all been revisited with respect to Rust's current approach to stability in terms of implementation as well as the state of the standard library today. The high level changes made were: * Stable items now have no marker by default * Color-based small stability markers have been removed * Module listings now fade out unstable/deprecated items slightly * Trait methods have a separate background color based on stability and also list the reason that they are unstable. * `impl` blocks with stability no longer render at all. This may be re-added once the compiler recognizes stability on `impl` blocks. * `impl` blocks no longer have stability of the methods implemente indicated * The stability summary has been removed Closes #15468 Closes #21674 Closes #24201
1 parent 5576b05 commit 0a46933

File tree

6 files changed

+132
-447
lines changed

6 files changed

+132
-447
lines changed

src/librustdoc/clean/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,22 @@ impl Item {
313313
pub fn is_fn(&self) -> bool {
314314
match self.inner { FunctionItem(..) => true, _ => false }
315315
}
316+
317+
pub fn stability_class(&self) -> String {
318+
match self.stability {
319+
Some(ref s) => {
320+
let mut base = match s.level {
321+
attr::Unstable => "unstable".to_string(),
322+
attr::Stable => String::new(),
323+
};
324+
if s.deprecated_since.len() > 0 {
325+
base.push_str(" deprecated");
326+
}
327+
base
328+
}
329+
_ => String::new(),
330+
}
331+
}
316332
}
317333

318334
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]

src/librustdoc/html/format.rs

-122
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ use syntax::ast;
2323
use syntax::ast_util;
2424

2525
use clean;
26-
use stability_summary::ModuleSummary;
2726
use html::item_type::ItemType;
2827
use html::render;
29-
use html::escape::Escape;
3028
use html::render::{cache, CURRENT_LOCATION_KEY};
3129

3230
/// Helper to render an optional visibility with a space after it (if the
@@ -45,10 +43,6 @@ pub struct MutableSpace(pub clean::Mutability);
4543
/// Similar to VisSpace, but used for mutability
4644
#[derive(Copy, Clone)]
4745
pub struct RawMutableSpace(pub clean::Mutability);
48-
/// Wrapper struct for properly emitting the stability level.
49-
pub struct Stability<'a>(pub &'a Option<clean::Stability>);
50-
/// Wrapper struct for emitting the stability level concisely.
51-
pub struct ConciseStability<'a>(pub &'a Option<clean::Stability>);
5246
/// Wrapper struct for emitting a where clause from Generics.
5347
pub struct WhereClause<'a>(pub &'a clean::Generics);
5448
/// Wrapper struct for emitting type parameter bounds.
@@ -702,119 +696,3 @@ impl fmt::Display for AbiSpace {
702696
}
703697
}
704698
}
705-
706-
impl<'a> fmt::Display for Stability<'a> {
707-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
708-
let Stability(stab) = *self;
709-
match *stab {
710-
Some(ref stability) => {
711-
let lvl = if stability.deprecated_since.is_empty() {
712-
format!("{}", stability.level)
713-
} else {
714-
"Deprecated".to_string()
715-
};
716-
write!(f, "<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
717-
lvl = Escape(&*lvl),
718-
reason = Escape(&*stability.reason))
719-
}
720-
None => Ok(())
721-
}
722-
}
723-
}
724-
725-
impl<'a> fmt::Display for ConciseStability<'a> {
726-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
727-
let ConciseStability(stab) = *self;
728-
match *stab {
729-
Some(ref stability) => {
730-
let lvl = if stability.deprecated_since.is_empty() {
731-
format!("{}", stability.level)
732-
} else {
733-
"Deprecated".to_string()
734-
};
735-
write!(f, "<a class='stability {lvl}' title='{lvl}{colon}{reason}'></a>",
736-
lvl = Escape(&*lvl),
737-
colon = if !stability.reason.is_empty() { ": " } else { "" },
738-
reason = Escape(&*stability.reason))
739-
}
740-
None => {
741-
write!(f, "<a class='stability Unmarked' title='No stability level'></a>")
742-
}
743-
}
744-
}
745-
}
746-
747-
impl fmt::Display for ModuleSummary {
748-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
749-
fn fmt_inner<'a>(f: &mut fmt::Formatter,
750-
context: &mut Vec<&'a str>,
751-
m: &'a ModuleSummary)
752-
-> fmt::Result {
753-
let cnt = m.counts;
754-
let tot = cnt.total();
755-
if tot == 0 { return Ok(()) }
756-
757-
context.push(&m.name);
758-
let path = context.connect("::");
759-
760-
try!(write!(f, "<tr>"));
761-
try!(write!(f, "<td><a href='{}'>{}</a></td>", {
762-
let mut url = context[1..].to_vec();
763-
url.push("index.html");
764-
url.connect("/")
765-
},
766-
path));
767-
try!(write!(f, "<td class='summary-column'>"));
768-
try!(write!(f, "<span class='summary Stable' \
769-
style='width: {:.4}%; display: inline-block'>&nbsp</span>",
770-
(100 * cnt.stable) as f64/tot as f64));
771-
try!(write!(f, "<span class='summary Unstable' \
772-
style='width: {:.4}%; display: inline-block'>&nbsp</span>",
773-
(100 * cnt.unstable) as f64/tot as f64));
774-
try!(write!(f, "<span class='summary Deprecated' \
775-
style='width: {:.4}%; display: inline-block'>&nbsp</span>",
776-
(100 * cnt.deprecated) as f64/tot as f64));
777-
try!(write!(f, "<span class='summary Unmarked' \
778-
style='width: {:.4}%; display: inline-block'>&nbsp</span>",
779-
(100 * cnt.unmarked) as f64/tot as f64));
780-
try!(write!(f, "</td></tr>"));
781-
782-
for submodule in &m.submodules {
783-
try!(fmt_inner(f, context, submodule));
784-
}
785-
context.pop();
786-
Ok(())
787-
}
788-
789-
let mut context = Vec::new();
790-
791-
let tot = self.counts.total();
792-
let (stable, unstable, deprecated, unmarked) = if tot == 0 {
793-
(0, 0, 0, 0)
794-
} else {
795-
((100 * self.counts.stable)/tot,
796-
(100 * self.counts.unstable)/tot,
797-
(100 * self.counts.deprecated)/tot,
798-
(100 * self.counts.unmarked)/tot)
799-
};
800-
801-
try!(write!(f,
802-
r"<h1 class='fqn'>Stability dashboard: crate <a class='mod' href='index.html'>{name}</a></h1>
803-
This dashboard summarizes the stability levels for all of the public modules of
804-
the crate, according to the total number of items at each level in the module and
805-
its children (percentages total for {name}):
806-
<blockquote>
807-
<a class='stability Stable'></a> stable ({}%),<br/>
808-
<a class='stability Unstable'></a> unstable ({}%),<br/>
809-
<a class='stability Deprecated'></a> deprecated ({}%),<br/>
810-
<a class='stability Unmarked'></a> unmarked ({}%)
811-
</blockquote>
812-
The counts do not include methods or trait
813-
implementations that are visible only through a re-exported type.",
814-
stable, unstable, deprecated, unmarked,
815-
name=self.name));
816-
try!(write!(f, "<table>"));
817-
try!(fmt_inner(f, &mut context, self));
818-
write!(f, "</table>")
819-
}
820-
}

0 commit comments

Comments
 (0)