rustdoc: Emit purity to function dox for traits

Closes #3804
This commit is contained in:
Alex Crichton 2013-09-23 20:38:17 -07:00
parent eaaf2bd41f
commit acab4a8c8e
5 changed files with 21 additions and 13 deletions

View File

@ -345,6 +345,7 @@ impl Clean<SelfTy> for ast::explicit_self {
pub struct Function {
decl: FnDecl,
generics: Generics,
purity: ast::purity,
}
impl Clean<Item> for doctree::Function {
@ -358,6 +359,7 @@ impl Clean<Item> for doctree::Function {
inner: FunctionItem(Function {
decl: self.decl.clean(),
generics: self.generics.clean(),
purity: self.purity,
}),
}
}

View File

@ -107,6 +107,7 @@ pub struct Function {
id: NodeId,
name: Ident,
vis: ast::visibility,
purity: ast::purity,
where: Span,
generics: ast::Generics,
}

View File

@ -18,6 +18,7 @@ use clean;
use html::render::{cache_key, current_location_key};
pub struct VisSpace(Option<ast::visibility>);
pub struct PuritySpace(ast::purity);
pub struct Method<'self>(&'self clean::SelfTy, &'self clean::FnDecl);
impl fmt::Default for clean::Generics {
@ -228,11 +229,7 @@ impl fmt::Default for clean::Type {
None => {}
}
write!(f.buf, "{}{}fn{}",
match decl.purity {
ast::unsafe_fn => "unsafe ",
ast::extern_fn => "extern ",
ast::impure_fn => ""
},
PuritySpace(decl.purity),
match decl.onceness {
ast::Once => "once ",
ast::Many => "",
@ -242,11 +239,7 @@ impl fmt::Default for clean::Type {
}
clean::BareFunction(ref decl) => {
write!(f.buf, "{}{}fn{}{}",
match decl.purity {
ast::unsafe_fn => "unsafe ",
ast::extern_fn => "extern ",
ast::impure_fn => ""
},
PuritySpace(decl.purity),
match decl.abi {
~"" | ~"\"Rust\"" => ~"",
ref s => " " + *s + " ",
@ -362,3 +355,13 @@ impl fmt::Default for VisSpace {
}
}
}
impl fmt::Default for PuritySpace {
fn fmt(p: &PuritySpace, f: &mut fmt::Formatter) {
match **p {
ast::unsafe_fn => write!(f.buf, "unsafe "),
ast::extern_fn => write!(f.buf, "extern "),
ast::impure_fn => {}
}
}
}

View File

@ -32,7 +32,7 @@ use syntax::ast;
use clean;
use doctree;
use fold::DocFolder;
use html::format::{VisSpace, Method};
use html::format::{VisSpace, Method, PuritySpace};
use html::layout;
use html::markdown::Markdown;
@ -717,8 +717,9 @@ fn item_module(w: &mut io::Writer, cx: &Context,
}
fn item_function(w: &mut io::Writer, it: &clean::Item, f: &clean::Function) {
write!(w, "<pre class='fn'>{vis}fn {name}{generics}{decl}</pre>",
write!(w, "<pre class='fn'>{vis}{purity}fn {name}{generics}{decl}</pre>",
vis = VisSpace(it.visibility),
purity = PuritySpace(f.purity),
name = it.name.get_ref().as_slice(),
generics = f.generics,
decl = f.decl);

View File

@ -75,7 +75,7 @@ impl RustdocVisitor {
}
}
fn visit_fn(item: &ast::item, fd: &ast::fn_decl, _purity: &ast::purity,
fn visit_fn(item: &ast::item, fd: &ast::fn_decl, purity: &ast::purity,
_abi: &AbiSet, gen: &ast::Generics) -> Function {
debug!("Visiting fn");
Function {
@ -86,6 +86,7 @@ impl RustdocVisitor {
name: item.ident,
where: item.span,
generics: gen.clone(),
purity: *purity,
}
}