From ca697d370594aaed020fb252a216b632abc56d33 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 26 Sep 2013 11:57:25 -0700 Subject: rustdoc: Generate documentation for foreign items This slurps up everything inside of an 'extern' block into the enclosing module in order to document them. The documentation must be on the items themselves, and they'll show up next to everything else on the module index pages. Closes #5953 --- src/libsyntax/parse/parser.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 74447b5dae1..7bea1f098c3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4204,9 +4204,9 @@ impl Parser { } // parse a function declaration from a foreign module - fn parse_item_foreign_fn(&self, attrs: ~[Attribute]) -> @foreign_item { + fn parse_item_foreign_fn(&self, vis: ast::visibility, + attrs: ~[Attribute]) -> @foreign_item { let lo = self.span.lo; - let vis = self.parse_visibility(); // Parse obsolete purity. let purity = self.parse_fn_purity(); @@ -4740,7 +4740,7 @@ impl Parser { if (self.is_keyword(keywords::Fn) || self.is_keyword(keywords::Pure) || self.is_keyword(keywords::Unsafe)) { // FOREIGN FUNCTION ITEM - let item = self.parse_item_foreign_fn(attrs); + let item = self.parse_item_foreign_fn(visibility, attrs); return iovi_foreign_item(item); } self.parse_macro_use_or_failure(attrs,macros_allowed,lo,visibility) -- cgit 1.4.1-3-g733a5 From 42bcf638b0213747e01af87353413755b9ebc270 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 26 Sep 2013 12:53:06 -0700 Subject: rustdoc: Render stability attributes Closes #8965 --- src/librustdoc/clean.rs | 20 ++++++++++++++++++++ src/librustdoc/html/render.rs | 13 +++++++++++++ src/librustdoc/html/static/main.css | 15 +++++++++++++++ src/libsyntax/attr.rs | 2 +- 4 files changed, 49 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index bfd71345c15..623ac82486d 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -16,6 +16,7 @@ use its = syntax::parse::token::ident_to_str; use syntax; use syntax::ast; use syntax::ast_util; +use syntax::attr; use syntax::attr::AttributeMethods; use std; @@ -206,6 +207,25 @@ impl Clean for ast::Attribute { } } +// This is a rough approximation that gets us what we want. +impl<'self> attr::AttrMetaMethods for &'self Attribute { + fn name(&self) -> @str { + match **self { + Word(ref n) | List(ref n, _) | NameValue(ref n, _) => + n.to_managed() + } + } + + fn value_str(&self) -> Option<@str> { + match **self { + NameValue(_, ref v) => Some(v.to_managed()), + _ => None, + } + } + fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None } + fn name_str_pair(&self) -> Option<(@str, @str)> { None } +} + #[deriving(Clone, Encodable, Decodable)] pub struct TyParam { name: ~str, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 70f433ff2a3..3320842c046 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -28,6 +28,7 @@ use extra::json::ToJson; use extra::sort; use syntax::ast; +use syntax::attr; use clean; use doctree; @@ -568,6 +569,18 @@ impl<'self> Item<'self> { impl<'self> fmt::Default for Item<'self> { fn fmt(it: &Item<'self>, fmt: &mut fmt::Formatter) { + match attr::find_stability(it.item.attrs.iter()) { + Some(stability) => { + write!(fmt.buf, + "{lvl}", + lvl = stability.level.to_str(), + reason = match stability.text { + Some(s) => s, None => @"", + }); + } + None => {} + } + // Write the breadcrumb trail header for the top write!(fmt.buf, "

"); match it.item.inner { diff --git a/src/librustdoc/html/static/main.css b/src/librustdoc/html/static/main.css index 97f59798240..11ca7a09311 100644 --- a/src/librustdoc/html/static/main.css +++ b/src/librustdoc/html/static/main.css @@ -269,3 +269,18 @@ a { float: left; padding: 20px; } + +.stability { + border-left: 5px solid #000; + border-radius: 3px; + padding: 0 3px; + float: right; + background: #fff; + text-transform: lowercase; +} +.stability.Deprecated { border-color: #D60027; color: #880017; } +.stability.Experimental { border-color: #EC5315; color: #a53c0e; } +.stability.Unstable { border-color: #FFD700; color: #b39800; } +.stability.Stable { border-color: #AEC516; color: #7c8b10; } +.stability.Frozen { border-color: #009431; color: #007726; } +.stability.Locked { border-color: #0084B6; color: #00668c; } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 295485d6f6e..47a7d0fbf9e 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -320,7 +320,7 @@ pub struct Stability { } /// The available stability levels. -#[deriving(Eq,Ord,Clone)] +#[deriving(Eq,Ord,Clone,ToStr)] pub enum StabilityLevel { Deprecated, Experimental, -- cgit 1.4.1-3-g733a5