From 4f238503d8730486fd9c72c71f1043a2f925299d Mon Sep 17 00:00:00 2001 From: Zack Corr Date: Thu, 14 Mar 2013 16:39:36 +1000 Subject: [PATCH 1/3] rustdoc: Document explicit self in methods. Closes #5254 --- src/librustdoc/tystr_pass.rs | 5 ++++- src/libsyntax/print/pprust.rs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index e5f304ee8aca1..916101709fed9 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -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") @@ -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() )) @@ -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() )) @@ -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() )) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 724e61daea7e7..f74b8eb42b860 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -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, 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); From d597a19b3062327f5fc26bc963bc5859ad3f6c04 Mon Sep 17 00:00:00 2001 From: Zack Corr Date: Sat, 16 Mar 2013 17:36:39 +1000 Subject: [PATCH 2/3] syntax: Fix fun_to_str test --- src/libsyntax/print/pprust.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f74b8eb42b860..9ae8798d4fabe 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2259,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()"); } From 246573d5ae1024193914de8c9be9230860781410 Mon Sep 17 00:00:00 2001 From: Zack Corr Date: Sun, 17 Mar 2013 11:45:22 +1000 Subject: [PATCH 3/3] rustdoc: Fix method printing tests --- src/librustdoc/markdown_pass.rs | 8 ++++---- src/librustdoc/tystr_pass.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index d7dd288ed8969..70d5c730569e7 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -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) { @@ -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( diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index 916101709fed9..54197e316da94 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -259,9 +259,9 @@ fn get_method_sig( #[test] fn should_add_trait_method_sigs() { - let doc = test::mk_doc(~"trait i { fn a() -> int; }"); + let doc = test::mk_doc(~"trait i { fn a(&mut self) -> int; }"); fail_unless!(doc.cratemod().traits()[0].methods[0].sig - == Some(~"fn a() -> int")); + == Some(~"fn a(&mut self) -> int")); } fn fold_impl( @@ -318,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() -> int { fail!() } }"); + let doc = test::mk_doc(~"impl int { fn a(&self) -> int { fail!() } }"); fail_unless!(doc.cratemod().impls()[0].methods[0].sig - == Some(~"fn a() -> int")); + == Some(~"fn a(&self) -> int")); } fn fold_type(