Skip to content

Commit

Permalink
rustdoc: Emit purity to function dox for traits
Browse files Browse the repository at this point in the history
Closes #3804
  • Loading branch information
alexcrichton committed Sep 25, 2013
1 parent eaaf2bd commit acab4a8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/librustdoc/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -358,6 +359,7 @@ impl Clean<Item> for doctree::Function {
inner: FunctionItem(Function {
decl: self.decl.clean(),
generics: self.generics.clean(),
purity: self.purity,
}),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub struct Function {
id: NodeId,
name: Ident,
vis: ast::visibility,
purity: ast::purity,
where: Span,
generics: ast::Generics,
}
Expand Down
23 changes: 13 additions & 10 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 => "",
Expand All @@ -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 + " ",
Expand Down Expand Up @@ -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 => {}
}
}
}
5 changes: 3 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -86,6 +86,7 @@ impl RustdocVisitor {
name: item.ident,
where: item.span,
generics: gen.clone(),
purity: *purity,
}
}

Expand Down

0 comments on commit acab4a8

Please sign in to comment.