Skip to content

Commit acab4a8

Browse files
committed
rustdoc: Emit purity to function dox for traits
Closes #3804
1 parent eaaf2bd commit acab4a8

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

src/librustdoc/clean.rs

+2
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ impl Clean<SelfTy> for ast::explicit_self {
345345
pub struct Function {
346346
decl: FnDecl,
347347
generics: Generics,
348+
purity: ast::purity,
348349
}
349350

350351
impl Clean<Item> for doctree::Function {
@@ -358,6 +359,7 @@ impl Clean<Item> for doctree::Function {
358359
inner: FunctionItem(Function {
359360
decl: self.decl.clean(),
360361
generics: self.generics.clean(),
362+
purity: self.purity,
361363
}),
362364
}
363365
}

src/librustdoc/doctree.rs

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub struct Function {
107107
id: NodeId,
108108
name: Ident,
109109
vis: ast::visibility,
110+
purity: ast::purity,
110111
where: Span,
111112
generics: ast::Generics,
112113
}

src/librustdoc/html/format.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use clean;
1818
use html::render::{cache_key, current_location_key};
1919

2020
pub struct VisSpace(Option<ast::visibility>);
21+
pub struct PuritySpace(ast::purity);
2122
pub struct Method<'self>(&'self clean::SelfTy, &'self clean::FnDecl);
2223

2324
impl fmt::Default for clean::Generics {
@@ -228,11 +229,7 @@ impl fmt::Default for clean::Type {
228229
None => {}
229230
}
230231
write!(f.buf, "{}{}fn{}",
231-
match decl.purity {
232-
ast::unsafe_fn => "unsafe ",
233-
ast::extern_fn => "extern ",
234-
ast::impure_fn => ""
235-
},
232+
PuritySpace(decl.purity),
236233
match decl.onceness {
237234
ast::Once => "once ",
238235
ast::Many => "",
@@ -242,11 +239,7 @@ impl fmt::Default for clean::Type {
242239
}
243240
clean::BareFunction(ref decl) => {
244241
write!(f.buf, "{}{}fn{}{}",
245-
match decl.purity {
246-
ast::unsafe_fn => "unsafe ",
247-
ast::extern_fn => "extern ",
248-
ast::impure_fn => ""
249-
},
242+
PuritySpace(decl.purity),
250243
match decl.abi {
251244
~"" | ~"\"Rust\"" => ~"",
252245
ref s => " " + *s + " ",
@@ -362,3 +355,13 @@ impl fmt::Default for VisSpace {
362355
}
363356
}
364357
}
358+
359+
impl fmt::Default for PuritySpace {
360+
fn fmt(p: &PuritySpace, f: &mut fmt::Formatter) {
361+
match **p {
362+
ast::unsafe_fn => write!(f.buf, "unsafe "),
363+
ast::extern_fn => write!(f.buf, "extern "),
364+
ast::impure_fn => {}
365+
}
366+
}
367+
}

src/librustdoc/html/render.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use syntax::ast;
3232
use clean;
3333
use doctree;
3434
use fold::DocFolder;
35-
use html::format::{VisSpace, Method};
35+
use html::format::{VisSpace, Method, PuritySpace};
3636
use html::layout;
3737
use html::markdown::Markdown;
3838

@@ -717,8 +717,9 @@ fn item_module(w: &mut io::Writer, cx: &Context,
717717
}
718718

719719
fn item_function(w: &mut io::Writer, it: &clean::Item, f: &clean::Function) {
720-
write!(w, "<pre class='fn'>{vis}fn {name}{generics}{decl}</pre>",
720+
write!(w, "<pre class='fn'>{vis}{purity}fn {name}{generics}{decl}</pre>",
721721
vis = VisSpace(it.visibility),
722+
purity = PuritySpace(f.purity),
722723
name = it.name.get_ref().as_slice(),
723724
generics = f.generics,
724725
decl = f.decl);

src/librustdoc/visit_ast.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl RustdocVisitor {
7575
}
7676
}
7777

78-
fn visit_fn(item: &ast::item, fd: &ast::fn_decl, _purity: &ast::purity,
78+
fn visit_fn(item: &ast::item, fd: &ast::fn_decl, purity: &ast::purity,
7979
_abi: &AbiSet, gen: &ast::Generics) -> Function {
8080
debug!("Visiting fn");
8181
Function {
@@ -86,6 +86,7 @@ impl RustdocVisitor {
8686
name: item.ident,
8787
where: item.span,
8888
generics: gen.clone(),
89+
purity: *purity,
8990
}
9091
}
9192

0 commit comments

Comments
 (0)