diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5c78bb976f1e..7e9bb2844a7c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -300,6 +300,7 @@ pub enum ItemEnum { ModuleItem(Module), TypedefItem(Typedef), StaticItem(Static), + ConstantItem(Constant), TraitItem(Trait), ImplItem(Impl), /// `use` and `extern crate` @@ -347,6 +348,7 @@ impl Clean for doctree::Module { self.mods.clean(cx), self.typedefs.clean(cx), self.statics.clean(cx), + self.constants.clean(cx), self.traits.clean(cx), self.impls.clean(cx), self.view_items.clean(cx).into_iter() @@ -1741,6 +1743,29 @@ impl Clean for doctree::Static { } } +#[deriving(Clone, Encodable, Decodable)] +pub struct Constant { + pub type_: Type, + pub expr: String, +} + +impl Clean for doctree::Constant { + fn clean(&self, cx: &DocContext) -> Item { + Item { + name: Some(self.name.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), + def_id: ast_util::local_def(self.id), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), + inner: ConstantItem(Constant { + type_: self.type_.clean(cx), + expr: self.expr.span.to_src(cx), + }), + } + } +} + #[deriving(Show, Clone, Encodable, Decodable, PartialEq)] pub enum Mutability { Mutable, diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 72964609049b..b173f0f16e30 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -30,6 +30,7 @@ pub struct Module { pub id: NodeId, pub typedefs: Vec, pub statics: Vec, + pub constants: Vec, pub traits: Vec, pub vis: ast::Visibility, pub stab: Option, @@ -56,6 +57,7 @@ impl Module { mods : Vec::new(), typedefs : Vec::new(), statics : Vec::new(), + constants : Vec::new(), traits : Vec::new(), impls : Vec::new(), view_items : Vec::new(), @@ -151,6 +153,17 @@ pub struct Static { pub whence: Span, } +pub struct Constant { + pub type_: P, + pub expr: P, + pub name: Ident, + pub attrs: Vec, + pub vis: ast::Visibility, + pub stab: Option, + pub id: ast::NodeId, + pub whence: Span, +} + pub struct Trait { pub name: Ident, pub items: Vec, //should be TraitItem diff --git a/src/librustdoc/flock.rs b/src/librustdoc/flock.rs index d1cc37497dc4..ef921a84cfb8 100644 --- a/src/librustdoc/flock.rs +++ b/src/librustdoc/flock.rs @@ -38,10 +38,10 @@ mod imp { pub l_sysid: libc::c_int, } - pub static F_WRLCK: libc::c_short = 1; - pub static F_UNLCK: libc::c_short = 2; - pub static F_SETLK: libc::c_int = 6; - pub static F_SETLKW: libc::c_int = 7; + pub const F_WRLCK: libc::c_short = 1; + pub const F_UNLCK: libc::c_short = 2; + pub const F_SETLK: libc::c_int = 6; + pub const F_SETLKW: libc::c_int = 7; } #[cfg(target_os = "freebsd")] @@ -57,10 +57,10 @@ mod imp { pub l_sysid: libc::c_int, } - pub static F_UNLCK: libc::c_short = 2; - pub static F_WRLCK: libc::c_short = 3; - pub static F_SETLK: libc::c_int = 12; - pub static F_SETLKW: libc::c_int = 13; + pub const F_UNLCK: libc::c_short = 2; + pub const F_WRLCK: libc::c_short = 3; + pub const F_SETLK: libc::c_int = 12; + pub const F_SETLKW: libc::c_int = 13; } #[cfg(target_os = "dragonfly")] @@ -78,10 +78,10 @@ mod imp { pub l_sysid: libc::c_int, } - pub static F_UNLCK: libc::c_short = 2; - pub static F_WRLCK: libc::c_short = 3; - pub static F_SETLK: libc::c_int = 8; - pub static F_SETLKW: libc::c_int = 9; + pub const F_UNLCK: libc::c_short = 2; + pub const F_WRLCK: libc::c_short = 3; + pub const F_SETLK: libc::c_int = 8; + pub const F_SETLKW: libc::c_int = 9; } #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -99,10 +99,10 @@ mod imp { pub l_sysid: libc::c_int, } - pub static F_UNLCK: libc::c_short = 2; - pub static F_WRLCK: libc::c_short = 3; - pub static F_SETLK: libc::c_int = 8; - pub static F_SETLKW: libc::c_int = 9; + pub const F_UNLCK: libc::c_short = 2; + pub const F_WRLCK: libc::c_short = 3; + pub const F_SETLK: libc::c_int = 8; + pub const F_SETLKW: libc::c_int = 9; } pub struct Lock { diff --git a/src/librustdoc/html/item_type.rs b/src/librustdoc/html/item_type.rs index e18ab0bd14f5..0b35f8ddc696 100644 --- a/src/librustdoc/html/item_type.rs +++ b/src/librustdoc/html/item_type.rs @@ -39,6 +39,7 @@ pub enum ItemType { Macro = 15, Primitive = 16, AssociatedType = 17, + Constant = 18, } impl ItemType { @@ -62,6 +63,7 @@ impl ItemType { Macro => "macro", Primitive => "primitive", AssociatedType => "associatedtype", + Constant => "constant", } } } @@ -86,6 +88,7 @@ pub fn shortty(item: &clean::Item) -> ItemType { clean::FunctionItem(..) => Function, clean::TypedefItem(..) => Typedef, clean::StaticItem(..) => Static, + clean::ConstantItem(..) => Constant, clean::TraitItem(..) => Trait, clean::ImplItem(..) => Impl, clean::ViewItemItem(..) => ViewItem, diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index faf361f02905..a5c6f79ef6b1 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -48,16 +48,16 @@ pub struct Markdown<'a>(pub &'a str); /// table of contents. pub struct MarkdownWithToc<'a>(pub &'a str); -static DEF_OUNIT: libc::size_t = 64; -static HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 10; -static HOEDOWN_EXT_TABLES: libc::c_uint = 1 << 0; -static HOEDOWN_EXT_FENCED_CODE: libc::c_uint = 1 << 1; -static HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3; -static HOEDOWN_EXT_STRIKETHROUGH: libc::c_uint = 1 << 4; -static HOEDOWN_EXT_SUPERSCRIPT: libc::c_uint = 1 << 8; -static HOEDOWN_EXT_FOOTNOTES: libc::c_uint = 1 << 2; +const DEF_OUNIT: libc::size_t = 64; +const HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 10; +const HOEDOWN_EXT_TABLES: libc::c_uint = 1 << 0; +const HOEDOWN_EXT_FENCED_CODE: libc::c_uint = 1 << 1; +const HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3; +const HOEDOWN_EXT_STRIKETHROUGH: libc::c_uint = 1 << 4; +const HOEDOWN_EXT_SUPERSCRIPT: libc::c_uint = 1 << 8; +const HOEDOWN_EXT_FOOTNOTES: libc::c_uint = 1 << 2; -static HOEDOWN_EXTENSIONS: libc::c_uint = +const HOEDOWN_EXTENSIONS: libc::c_uint = HOEDOWN_EXT_NO_INTRA_EMPHASIS | HOEDOWN_EXT_TABLES | HOEDOWN_EXT_FENCED_CODE | HOEDOWN_EXT_AUTOLINK | HOEDOWN_EXT_STRIKETHROUGH | HOEDOWN_EXT_SUPERSCRIPT | diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index e9d65b0a40cf..497bbd3a1cd6 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1471,6 +1471,8 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, (_, &clean::StructItem(..)) => Greater, (&clean::EnumItem(..), _) => Less, (_, &clean::EnumItem(..)) => Greater, + (&clean::ConstantItem(..), _) => Less, + (_, &clean::ConstantItem(..)) => Greater, (&clean::StaticItem(..), _) => Less, (_, &clean::StaticItem(..)) => Greater, (&clean::ForeignFunctionItem(..), _) => Less, @@ -1507,6 +1509,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, clean::FunctionItem(..) => ("functions", "Functions"), clean::TypedefItem(..) => ("types", "Type Definitions"), clean::StaticItem(..) => ("statics", "Statics"), + clean::ConstantItem(..) => ("constants", "Constants"), clean::TraitItem(..) => ("traits", "Traits"), clean::ImplItem(..) => ("impls", "Implementations"), clean::ViewItemItem(..) => ("reexports", "Reexports"), @@ -1526,28 +1529,28 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, id = short, name = name)); } + struct Initializer<'a>(&'a str, Item<'a>); + impl<'a> fmt::Show for Initializer<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let Initializer(s, item) = *self; + if s.len() == 0 { return Ok(()); } + try!(write!(f, " = ")); + if s.contains("\n") { + match item.href() { + Some(url) => { + write!(f, "[definition]", + url) + } + None => Ok(()), + } + } else { + write!(f, "{}", s.as_slice()) + } + } + } + match myitem.inner { clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => { - struct Initializer<'a>(&'a str, Item<'a>); - impl<'a> fmt::Show for Initializer<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let Initializer(s, item) = *self; - if s.len() == 0 { return Ok(()); } - try!(write!(f, " = ")); - if s.contains("\n") { - match item.href() { - Some(url) => { - write!(f, "[definition]", - url) - } - None => Ok(()), - } - } else { - write!(f, "{}", s.as_slice()) - } - } - } - try!(write!(w, " {}{}static {}{}: {}{} @@ -1562,6 +1565,20 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }), Markdown(blank(myitem.doc_value())))); } + clean::ConstantItem(ref s) => { + try!(write!(w, " + + {}{}const {}: {}{} + {}  + + ", + ConciseStability(&myitem.stability), + VisSpace(myitem.visibility), + *myitem.name.get_ref(), + s.type_, + Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }), + Markdown(blank(myitem.doc_value())))); + } clean::ViewItemItem(ref item) => { match item.inner { diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 6992a9665929..7c6f7ed3fe23 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -569,7 +569,9 @@ "ffi", "ffs", "macro", - "primitive"]; + "primitive", + "associatedtype", + "constant"]; function itemTypeFromName(typename) { for (var i = 0; i < itemTypes.length; ++i) { diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 3c66a7c78509..1a9dd226f87d 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -134,7 +134,8 @@ impl<'a> fold::DocFolder for Stripper<'a> { clean::StructItem(..) | clean::EnumItem(..) | clean::TraitItem(..) | clean::FunctionItem(..) | clean::VariantItem(..) | clean::MethodItem(..) | - clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) => { + clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) | + clean::ConstantItem(..) => { if ast_util::is_local(i.def_id) && !self.exported_items.contains(&i.def_id.node) { return None; diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index d4a1a3579093..6456f4acd30c 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -308,6 +308,19 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { }; om.statics.push(s); }, + ast::ItemConst(ref ty, ref exp) => { + let s = Constant { + type_: ty.clone(), + expr: exp.clone(), + id: item.id, + name: name, + attrs: item.attrs.clone(), + whence: item.span, + vis: item.vis, + stab: self.stability(item.id), + }; + om.constants.push(s); + }, ast::ItemTrait(ref gen, _, ref b, ref items) => { let t = Trait { name: name,