Skip to content

Commit 42bcf63

Browse files
committed
rustdoc: Render stability attributes
Closes #8965
1 parent 6a277dc commit 42bcf63

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

src/librustdoc/clean.rs

+20
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use its = syntax::parse::token::ident_to_str;
1616
use syntax;
1717
use syntax::ast;
1818
use syntax::ast_util;
19+
use syntax::attr;
1920
use syntax::attr::AttributeMethods;
2021

2122
use std;
@@ -206,6 +207,25 @@ impl Clean<Attribute> for ast::Attribute {
206207
}
207208
}
208209

210+
// This is a rough approximation that gets us what we want.
211+
impl<'self> attr::AttrMetaMethods for &'self Attribute {
212+
fn name(&self) -> @str {
213+
match **self {
214+
Word(ref n) | List(ref n, _) | NameValue(ref n, _) =>
215+
n.to_managed()
216+
}
217+
}
218+
219+
fn value_str(&self) -> Option<@str> {
220+
match **self {
221+
NameValue(_, ref v) => Some(v.to_managed()),
222+
_ => None,
223+
}
224+
}
225+
fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
226+
fn name_str_pair(&self) -> Option<(@str, @str)> { None }
227+
}
228+
209229
#[deriving(Clone, Encodable, Decodable)]
210230
pub struct TyParam {
211231
name: ~str,

src/librustdoc/html/render.rs

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use extra::json::ToJson;
2828
use extra::sort;
2929

3030
use syntax::ast;
31+
use syntax::attr;
3132

3233
use clean;
3334
use doctree;
@@ -568,6 +569,18 @@ impl<'self> Item<'self> {
568569

569570
impl<'self> fmt::Default for Item<'self> {
570571
fn fmt(it: &Item<'self>, fmt: &mut fmt::Formatter) {
572+
match attr::find_stability(it.item.attrs.iter()) {
573+
Some(stability) => {
574+
write!(fmt.buf,
575+
"<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
576+
lvl = stability.level.to_str(),
577+
reason = match stability.text {
578+
Some(s) => s, None => @"",
579+
});
580+
}
581+
None => {}
582+
}
583+
571584
// Write the breadcrumb trail header for the top
572585
write!(fmt.buf, "<h1 class='fqn'>");
573586
match it.item.inner {

src/librustdoc/html/static/main.css

+15
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,18 @@ a {
269269
float: left;
270270
padding: 20px;
271271
}
272+
273+
.stability {
274+
border-left: 5px solid #000;
275+
border-radius: 3px;
276+
padding: 0 3px;
277+
float: right;
278+
background: #fff;
279+
text-transform: lowercase;
280+
}
281+
.stability.Deprecated { border-color: #D60027; color: #880017; }
282+
.stability.Experimental { border-color: #EC5315; color: #a53c0e; }
283+
.stability.Unstable { border-color: #FFD700; color: #b39800; }
284+
.stability.Stable { border-color: #AEC516; color: #7c8b10; }
285+
.stability.Frozen { border-color: #009431; color: #007726; }
286+
.stability.Locked { border-color: #0084B6; color: #00668c; }

src/libsyntax/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pub struct Stability {
320320
}
321321

322322
/// The available stability levels.
323-
#[deriving(Eq,Ord,Clone)]
323+
#[deriving(Eq,Ord,Clone,ToStr)]
324324
pub enum StabilityLevel {
325325
Deprecated,
326326
Experimental,

0 commit comments

Comments
 (0)