1
Fork 0

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

View file

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

View file

@ -18,6 +18,7 @@ use clean;
use html::render::{cache_key, current_location_key}; use html::render::{cache_key, current_location_key};
pub struct VisSpace(Option<ast::visibility>); pub struct VisSpace(Option<ast::visibility>);
pub struct PuritySpace(ast::purity);
pub struct Method<'self>(&'self clean::SelfTy, &'self clean::FnDecl); pub struct Method<'self>(&'self clean::SelfTy, &'self clean::FnDecl);
impl fmt::Default for clean::Generics { impl fmt::Default for clean::Generics {
@ -228,11 +229,7 @@ impl fmt::Default for clean::Type {
None => {} None => {}
} }
write!(f.buf, "{}{}fn{}", write!(f.buf, "{}{}fn{}",
match decl.purity { PuritySpace(decl.purity),
ast::unsafe_fn => "unsafe ",
ast::extern_fn => "extern ",
ast::impure_fn => ""
},
match decl.onceness { match decl.onceness {
ast::Once => "once ", ast::Once => "once ",
ast::Many => "", ast::Many => "",
@ -242,11 +239,7 @@ impl fmt::Default for clean::Type {
} }
clean::BareFunction(ref decl) => { clean::BareFunction(ref decl) => {
write!(f.buf, "{}{}fn{}{}", write!(f.buf, "{}{}fn{}{}",
match decl.purity { PuritySpace(decl.purity),
ast::unsafe_fn => "unsafe ",
ast::extern_fn => "extern ",
ast::impure_fn => ""
},
match decl.abi { match decl.abi {
~"" | ~"\"Rust\"" => ~"", ~"" | ~"\"Rust\"" => ~"",
ref s => " " + *s + " ", 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 clean;
use doctree; use doctree;
use fold::DocFolder; use fold::DocFolder;
use html::format::{VisSpace, Method}; use html::format::{VisSpace, Method, PuritySpace};
use html::layout; use html::layout;
use html::markdown::Markdown; 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) { 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), vis = VisSpace(it.visibility),
purity = PuritySpace(f.purity),
name = it.name.get_ref().as_slice(), name = it.name.get_ref().as_slice(),
generics = f.generics, generics = f.generics,
decl = f.decl); 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 { _abi: &AbiSet, gen: &ast::Generics) -> Function {
debug!("Visiting fn"); debug!("Visiting fn");
Function { Function {
@ -86,6 +86,7 @@ impl RustdocVisitor {
name: item.ident, name: item.ident,
where: item.span, where: item.span,
generics: gen.clone(), generics: gen.clone(),
purity: *purity,
} }
} }