Skip to content

rustdoc: Document explicit self in methods #5374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/librustdoc/markdown_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,8 @@ fn should_write_trait_method_header() {
#[test]
fn should_write_trait_method_signature() {
let markdown = test::render(
~"trait i { fn a(); }");
fail_unless!(str::contains(markdown, ~"\n fn a()"));
~"trait i { fn a(&self); }");
fail_unless!(str::contains(markdown, ~"\n fn a(&self)"));
}

fn write_impl(ctxt: &Ctxt, doc: doc::ImplDoc) {
Expand Down Expand Up @@ -773,8 +773,8 @@ fn should_write_impl_method_header() {
#[test]
fn should_write_impl_method_signature() {
let markdown = test::render(
~"impl int { fn a() { } }");
fail_unless!(str::contains(markdown, ~"\n fn a()"));
~"impl int { fn a(&mut self) { } }");
fail_unless!(str::contains(markdown, ~"\n fn a(&mut self)"));
}

fn write_type(
Expand Down
13 changes: 8 additions & 5 deletions src/librustdoc/tystr_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn get_fn_sig(srv: astsrv::Srv, fn_id: doc::AstId) -> Option<~str> {
ident: ident,
node: ast::foreign_item_fn(ref decl, _, ref tys), _
}, _, _) => {
Some(pprust::fun_to_str(decl, ident, tys,
Some(pprust::fun_to_str(decl, ident, None, tys,
extract::interner()))
}
_ => fail!(~"get_fn_sig: fn_id not bound to a fn item")
Expand Down Expand Up @@ -215,6 +215,7 @@ fn get_method_sig(
Some(pprust::fun_to_str(
&ty_m.decl,
ty_m.ident,
Some(ty_m.self_ty.node),
&ty_m.generics,
extract::interner()
))
Expand All @@ -223,6 +224,7 @@ fn get_method_sig(
Some(pprust::fun_to_str(
&m.decl,
m.ident,
Some(m.self_ty.node),
&m.generics,
extract::interner()
))
Expand All @@ -242,6 +244,7 @@ fn get_method_sig(
Some(pprust::fun_to_str(
&method.decl,
method.ident,
Some(method.self_ty.node),
&method.generics,
extract::interner()
))
Expand All @@ -256,9 +259,9 @@ fn get_method_sig(

#[test]
fn should_add_trait_method_sigs() {
let doc = test::mk_doc(~"trait i { fn a<T>() -> int; }");
let doc = test::mk_doc(~"trait i { fn a<T>(&mut self) -> int; }");
fail_unless!(doc.cratemod().traits()[0].methods[0].sig
== Some(~"fn a<T>() -> int"));
== Some(~"fn a<T>(&mut self) -> int"));
}

fn fold_impl(
Expand Down Expand Up @@ -315,9 +318,9 @@ fn should_add_impl_self_ty() {

#[test]
fn should_add_impl_method_sigs() {
let doc = test::mk_doc(~"impl int { fn a<T>() -> int { fail!() } }");
let doc = test::mk_doc(~"impl int { fn a<T>(&self) -> int { fail!() } }");
fail_unless!(doc.cratemod().impls()[0].methods[0].sig
== Some(~"fn a<T>() -> int"));
== Some(~"fn a<T>(&self) -> int"));
}

fn fold_type(
Expand Down
5 changes: 3 additions & 2 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ pub fn path_to_str(&&p: @ast::path, intr: @ident_interner) -> ~str {
}

pub fn fun_to_str(decl: &ast::fn_decl, name: ast::ident,
opt_self_ty: Option<ast::self_ty_>,
generics: &ast::Generics, intr: @ident_interner) -> ~str {
do io::with_str_writer |wr| {
let s = rust_printer(wr, intr);
print_fn(s, decl, None, name, generics, None, ast::inherited);
print_fn(s, decl, None, name, generics, opt_self_ty, ast::inherited);
end(s); // Close the head box
end(s); // Close the outer box
eof(s.s);
Expand Down Expand Up @@ -2258,7 +2259,7 @@ pub mod test {
cf: ast::return_val
};
let generics = ast_util::empty_generics();
check_equal (&fun_to_str(&decl, abba_ident, &generics, mock_interner),
check_equal (&fun_to_str(&decl, abba_ident, None, &generics, mock_interner),
&~"fn abba()");
}

Expand Down