rustdoc: Implement constant documentation
At the same time, migrate statics to constants.
This commit is contained in:
parent
1bfe450a5e
commit
01d58fe2cb
9 changed files with 121 additions and 47 deletions
|
@ -300,6 +300,7 @@ pub enum ItemEnum {
|
||||||
ModuleItem(Module),
|
ModuleItem(Module),
|
||||||
TypedefItem(Typedef),
|
TypedefItem(Typedef),
|
||||||
StaticItem(Static),
|
StaticItem(Static),
|
||||||
|
ConstantItem(Constant),
|
||||||
TraitItem(Trait),
|
TraitItem(Trait),
|
||||||
ImplItem(Impl),
|
ImplItem(Impl),
|
||||||
/// `use` and `extern crate`
|
/// `use` and `extern crate`
|
||||||
|
@ -347,6 +348,7 @@ impl Clean<Item> for doctree::Module {
|
||||||
self.mods.clean(cx),
|
self.mods.clean(cx),
|
||||||
self.typedefs.clean(cx),
|
self.typedefs.clean(cx),
|
||||||
self.statics.clean(cx),
|
self.statics.clean(cx),
|
||||||
|
self.constants.clean(cx),
|
||||||
self.traits.clean(cx),
|
self.traits.clean(cx),
|
||||||
self.impls.clean(cx),
|
self.impls.clean(cx),
|
||||||
self.view_items.clean(cx).into_iter()
|
self.view_items.clean(cx).into_iter()
|
||||||
|
@ -1741,6 +1743,29 @@ impl Clean<Item> for doctree::Static {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving(Clone, Encodable, Decodable)]
|
||||||
|
pub struct Constant {
|
||||||
|
pub type_: Type,
|
||||||
|
pub expr: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clean<Item> 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)]
|
#[deriving(Show, Clone, Encodable, Decodable, PartialEq)]
|
||||||
pub enum Mutability {
|
pub enum Mutability {
|
||||||
Mutable,
|
Mutable,
|
||||||
|
|
|
@ -30,6 +30,7 @@ pub struct Module {
|
||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
pub typedefs: Vec<Typedef>,
|
pub typedefs: Vec<Typedef>,
|
||||||
pub statics: Vec<Static>,
|
pub statics: Vec<Static>,
|
||||||
|
pub constants: Vec<Constant>,
|
||||||
pub traits: Vec<Trait>,
|
pub traits: Vec<Trait>,
|
||||||
pub vis: ast::Visibility,
|
pub vis: ast::Visibility,
|
||||||
pub stab: Option<attr::Stability>,
|
pub stab: Option<attr::Stability>,
|
||||||
|
@ -56,6 +57,7 @@ impl Module {
|
||||||
mods : Vec::new(),
|
mods : Vec::new(),
|
||||||
typedefs : Vec::new(),
|
typedefs : Vec::new(),
|
||||||
statics : Vec::new(),
|
statics : Vec::new(),
|
||||||
|
constants : Vec::new(),
|
||||||
traits : Vec::new(),
|
traits : Vec::new(),
|
||||||
impls : Vec::new(),
|
impls : Vec::new(),
|
||||||
view_items : Vec::new(),
|
view_items : Vec::new(),
|
||||||
|
@ -151,6 +153,17 @@ pub struct Static {
|
||||||
pub whence: Span,
|
pub whence: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Constant {
|
||||||
|
pub type_: P<ast::Ty>,
|
||||||
|
pub expr: P<ast::Expr>,
|
||||||
|
pub name: Ident,
|
||||||
|
pub attrs: Vec<ast::Attribute>,
|
||||||
|
pub vis: ast::Visibility,
|
||||||
|
pub stab: Option<attr::Stability>,
|
||||||
|
pub id: ast::NodeId,
|
||||||
|
pub whence: Span,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Trait {
|
pub struct Trait {
|
||||||
pub name: Ident,
|
pub name: Ident,
|
||||||
pub items: Vec<ast::TraitItem>, //should be TraitItem
|
pub items: Vec<ast::TraitItem>, //should be TraitItem
|
||||||
|
|
|
@ -38,10 +38,10 @@ mod imp {
|
||||||
pub l_sysid: libc::c_int,
|
pub l_sysid: libc::c_int,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static F_WRLCK: libc::c_short = 1;
|
pub const F_WRLCK: libc::c_short = 1;
|
||||||
pub static F_UNLCK: libc::c_short = 2;
|
pub const F_UNLCK: libc::c_short = 2;
|
||||||
pub static F_SETLK: libc::c_int = 6;
|
pub const F_SETLK: libc::c_int = 6;
|
||||||
pub static F_SETLKW: libc::c_int = 7;
|
pub const F_SETLKW: libc::c_int = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "freebsd")]
|
#[cfg(target_os = "freebsd")]
|
||||||
|
@ -57,10 +57,10 @@ mod imp {
|
||||||
pub l_sysid: libc::c_int,
|
pub l_sysid: libc::c_int,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static F_UNLCK: libc::c_short = 2;
|
pub const F_UNLCK: libc::c_short = 2;
|
||||||
pub static F_WRLCK: libc::c_short = 3;
|
pub const F_WRLCK: libc::c_short = 3;
|
||||||
pub static F_SETLK: libc::c_int = 12;
|
pub const F_SETLK: libc::c_int = 12;
|
||||||
pub static F_SETLKW: libc::c_int = 13;
|
pub const F_SETLKW: libc::c_int = 13;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "dragonfly")]
|
#[cfg(target_os = "dragonfly")]
|
||||||
|
@ -78,10 +78,10 @@ mod imp {
|
||||||
pub l_sysid: libc::c_int,
|
pub l_sysid: libc::c_int,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static F_UNLCK: libc::c_short = 2;
|
pub const F_UNLCK: libc::c_short = 2;
|
||||||
pub static F_WRLCK: libc::c_short = 3;
|
pub const F_WRLCK: libc::c_short = 3;
|
||||||
pub static F_SETLK: libc::c_int = 8;
|
pub const F_SETLK: libc::c_int = 8;
|
||||||
pub static F_SETLKW: libc::c_int = 9;
|
pub const F_SETLKW: libc::c_int = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
|
@ -99,10 +99,10 @@ mod imp {
|
||||||
pub l_sysid: libc::c_int,
|
pub l_sysid: libc::c_int,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static F_UNLCK: libc::c_short = 2;
|
pub const F_UNLCK: libc::c_short = 2;
|
||||||
pub static F_WRLCK: libc::c_short = 3;
|
pub const F_WRLCK: libc::c_short = 3;
|
||||||
pub static F_SETLK: libc::c_int = 8;
|
pub const F_SETLK: libc::c_int = 8;
|
||||||
pub static F_SETLKW: libc::c_int = 9;
|
pub const F_SETLKW: libc::c_int = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Lock {
|
pub struct Lock {
|
||||||
|
|
|
@ -39,6 +39,7 @@ pub enum ItemType {
|
||||||
Macro = 15,
|
Macro = 15,
|
||||||
Primitive = 16,
|
Primitive = 16,
|
||||||
AssociatedType = 17,
|
AssociatedType = 17,
|
||||||
|
Constant = 18,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ItemType {
|
impl ItemType {
|
||||||
|
@ -62,6 +63,7 @@ impl ItemType {
|
||||||
Macro => "macro",
|
Macro => "macro",
|
||||||
Primitive => "primitive",
|
Primitive => "primitive",
|
||||||
AssociatedType => "associatedtype",
|
AssociatedType => "associatedtype",
|
||||||
|
Constant => "constant",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,6 +88,7 @@ pub fn shortty(item: &clean::Item) -> ItemType {
|
||||||
clean::FunctionItem(..) => Function,
|
clean::FunctionItem(..) => Function,
|
||||||
clean::TypedefItem(..) => Typedef,
|
clean::TypedefItem(..) => Typedef,
|
||||||
clean::StaticItem(..) => Static,
|
clean::StaticItem(..) => Static,
|
||||||
|
clean::ConstantItem(..) => Constant,
|
||||||
clean::TraitItem(..) => Trait,
|
clean::TraitItem(..) => Trait,
|
||||||
clean::ImplItem(..) => Impl,
|
clean::ImplItem(..) => Impl,
|
||||||
clean::ViewItemItem(..) => ViewItem,
|
clean::ViewItemItem(..) => ViewItem,
|
||||||
|
|
|
@ -48,16 +48,16 @@ pub struct Markdown<'a>(pub &'a str);
|
||||||
/// table of contents.
|
/// table of contents.
|
||||||
pub struct MarkdownWithToc<'a>(pub &'a str);
|
pub struct MarkdownWithToc<'a>(pub &'a str);
|
||||||
|
|
||||||
static DEF_OUNIT: libc::size_t = 64;
|
const DEF_OUNIT: libc::size_t = 64;
|
||||||
static HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 10;
|
const HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 10;
|
||||||
static HOEDOWN_EXT_TABLES: libc::c_uint = 1 << 0;
|
const HOEDOWN_EXT_TABLES: libc::c_uint = 1 << 0;
|
||||||
static HOEDOWN_EXT_FENCED_CODE: libc::c_uint = 1 << 1;
|
const HOEDOWN_EXT_FENCED_CODE: libc::c_uint = 1 << 1;
|
||||||
static HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3;
|
const HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3;
|
||||||
static HOEDOWN_EXT_STRIKETHROUGH: libc::c_uint = 1 << 4;
|
const HOEDOWN_EXT_STRIKETHROUGH: libc::c_uint = 1 << 4;
|
||||||
static HOEDOWN_EXT_SUPERSCRIPT: libc::c_uint = 1 << 8;
|
const HOEDOWN_EXT_SUPERSCRIPT: libc::c_uint = 1 << 8;
|
||||||
static HOEDOWN_EXT_FOOTNOTES: libc::c_uint = 1 << 2;
|
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_NO_INTRA_EMPHASIS | HOEDOWN_EXT_TABLES |
|
||||||
HOEDOWN_EXT_FENCED_CODE | HOEDOWN_EXT_AUTOLINK |
|
HOEDOWN_EXT_FENCED_CODE | HOEDOWN_EXT_AUTOLINK |
|
||||||
HOEDOWN_EXT_STRIKETHROUGH | HOEDOWN_EXT_SUPERSCRIPT |
|
HOEDOWN_EXT_STRIKETHROUGH | HOEDOWN_EXT_SUPERSCRIPT |
|
||||||
|
|
|
@ -1471,6 +1471,8 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
||||||
(_, &clean::StructItem(..)) => Greater,
|
(_, &clean::StructItem(..)) => Greater,
|
||||||
(&clean::EnumItem(..), _) => Less,
|
(&clean::EnumItem(..), _) => Less,
|
||||||
(_, &clean::EnumItem(..)) => Greater,
|
(_, &clean::EnumItem(..)) => Greater,
|
||||||
|
(&clean::ConstantItem(..), _) => Less,
|
||||||
|
(_, &clean::ConstantItem(..)) => Greater,
|
||||||
(&clean::StaticItem(..), _) => Less,
|
(&clean::StaticItem(..), _) => Less,
|
||||||
(_, &clean::StaticItem(..)) => Greater,
|
(_, &clean::StaticItem(..)) => Greater,
|
||||||
(&clean::ForeignFunctionItem(..), _) => Less,
|
(&clean::ForeignFunctionItem(..), _) => Less,
|
||||||
|
@ -1507,6 +1509,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
||||||
clean::FunctionItem(..) => ("functions", "Functions"),
|
clean::FunctionItem(..) => ("functions", "Functions"),
|
||||||
clean::TypedefItem(..) => ("types", "Type Definitions"),
|
clean::TypedefItem(..) => ("types", "Type Definitions"),
|
||||||
clean::StaticItem(..) => ("statics", "Statics"),
|
clean::StaticItem(..) => ("statics", "Statics"),
|
||||||
|
clean::ConstantItem(..) => ("constants", "Constants"),
|
||||||
clean::TraitItem(..) => ("traits", "Traits"),
|
clean::TraitItem(..) => ("traits", "Traits"),
|
||||||
clean::ImplItem(..) => ("impls", "Implementations"),
|
clean::ImplItem(..) => ("impls", "Implementations"),
|
||||||
clean::ViewItemItem(..) => ("reexports", "Reexports"),
|
clean::ViewItemItem(..) => ("reexports", "Reexports"),
|
||||||
|
@ -1526,28 +1529,28 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
||||||
id = short, name = name));
|
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, "<code> = </code>"));
|
||||||
|
if s.contains("\n") {
|
||||||
|
match item.href() {
|
||||||
|
Some(url) => {
|
||||||
|
write!(f, "<a href='{}'>[definition]</a>",
|
||||||
|
url)
|
||||||
|
}
|
||||||
|
None => Ok(()),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
write!(f, "<code>{}</code>", s.as_slice())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match myitem.inner {
|
match myitem.inner {
|
||||||
clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => {
|
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, "<code> = </code>"));
|
|
||||||
if s.contains("\n") {
|
|
||||||
match item.href() {
|
|
||||||
Some(url) => {
|
|
||||||
write!(f, "<a href='{}'>[definition]</a>",
|
|
||||||
url)
|
|
||||||
}
|
|
||||||
None => Ok(()),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
write!(f, "<code>{}</code>", s.as_slice())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try!(write!(w, "
|
try!(write!(w, "
|
||||||
<tr>
|
<tr>
|
||||||
<td>{}<code>{}static {}{}: {}</code>{}</td>
|
<td>{}<code>{}static {}{}: {}</code>{}</td>
|
||||||
|
@ -1562,6 +1565,20 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
||||||
Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }),
|
Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }),
|
||||||
Markdown(blank(myitem.doc_value()))));
|
Markdown(blank(myitem.doc_value()))));
|
||||||
}
|
}
|
||||||
|
clean::ConstantItem(ref s) => {
|
||||||
|
try!(write!(w, "
|
||||||
|
<tr>
|
||||||
|
<td>{}<code>{}const {}: {}</code>{}</td>
|
||||||
|
<td class='docblock'>{} </td>
|
||||||
|
</tr>
|
||||||
|
",
|
||||||
|
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) => {
|
clean::ViewItemItem(ref item) => {
|
||||||
match item.inner {
|
match item.inner {
|
||||||
|
|
|
@ -569,7 +569,9 @@
|
||||||
"ffi",
|
"ffi",
|
||||||
"ffs",
|
"ffs",
|
||||||
"macro",
|
"macro",
|
||||||
"primitive"];
|
"primitive",
|
||||||
|
"associatedtype",
|
||||||
|
"constant"];
|
||||||
|
|
||||||
function itemTypeFromName(typename) {
|
function itemTypeFromName(typename) {
|
||||||
for (var i = 0; i < itemTypes.length; ++i) {
|
for (var i = 0; i < itemTypes.length; ++i) {
|
||||||
|
|
|
@ -134,7 +134,8 @@ impl<'a> fold::DocFolder for Stripper<'a> {
|
||||||
clean::StructItem(..) | clean::EnumItem(..) |
|
clean::StructItem(..) | clean::EnumItem(..) |
|
||||||
clean::TraitItem(..) | clean::FunctionItem(..) |
|
clean::TraitItem(..) | clean::FunctionItem(..) |
|
||||||
clean::VariantItem(..) | clean::MethodItem(..) |
|
clean::VariantItem(..) | clean::MethodItem(..) |
|
||||||
clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) => {
|
clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) |
|
||||||
|
clean::ConstantItem(..) => {
|
||||||
if ast_util::is_local(i.def_id) &&
|
if ast_util::is_local(i.def_id) &&
|
||||||
!self.exported_items.contains(&i.def_id.node) {
|
!self.exported_items.contains(&i.def_id.node) {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -308,6 +308,19 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
om.statics.push(s);
|
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) => {
|
ast::ItemTrait(ref gen, _, ref b, ref items) => {
|
||||||
let t = Trait {
|
let t = Trait {
|
||||||
name: name,
|
name: name,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue