diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index 97a599196e72f..0b5c0b8da95b8 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -345,6 +345,7 @@ impl Clean for ast::explicit_self { pub struct Function { decl: FnDecl, generics: Generics, + purity: ast::purity, } impl Clean for doctree::Function { @@ -358,6 +359,7 @@ impl Clean for doctree::Function { inner: FunctionItem(Function { decl: self.decl.clean(), generics: self.generics.clean(), + purity: self.purity, }), } } diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 67722b1e1777a..a4e3f79549824 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -107,6 +107,7 @@ pub struct Function { id: NodeId, name: Ident, vis: ast::visibility, + purity: ast::purity, where: Span, generics: ast::Generics, } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 4d0f6928d50e3..75d6cb588e8ec 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -18,6 +18,7 @@ use clean; use html::render::{cache_key, current_location_key}; pub struct VisSpace(Option); +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 => {} + } + } +} diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 96b118051df64..69c01cf8a45a2 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -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, "
{vis}fn {name}{generics}{decl}
", + write!(w, "
{vis}{purity}fn {name}{generics}{decl}
", vis = VisSpace(it.visibility), + purity = PuritySpace(f.purity), name = it.name.get_ref().as_slice(), generics = f.generics, decl = f.decl); diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 14be80f0f1533..c4b9b9efe566e 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -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, } }