diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 500b75ec659a1..9d1bf6663ffd1 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2588,7 +2588,8 @@ fn render_assoc_item(w: &mut fmt::Formatter, href(did).map(|p| format!("{}#{}.{}", p.0, ty, name)).unwrap_or(anchor) } }; - let mut head_len = format!("{}{}{:#}fn {}{:#}", + let mut head_len = format!("{}{}{}{:#}fn {}{:#}", + VisSpace(&meth.visibility), ConstnessSpace(constness), UnsafetySpace(unsafety), AbiSpace(abi), @@ -2600,8 +2601,9 @@ fn render_assoc_item(w: &mut fmt::Formatter, } else { (0, true) }; - write!(w, "{}{}{}fn {name}\ + write!(w, "{}{}{}{}fn {name}\ {generics}{decl}{where_clause}", + VisSpace(&meth.visibility), ConstnessSpace(constness), UnsafetySpace(unsafety), AbiSpace(abi), diff --git a/src/test/rustdoc/pub-method.rs b/src/test/rustdoc/pub-method.rs new file mode 100644 index 0000000000000..5998734e4a20c --- /dev/null +++ b/src/test/rustdoc/pub-method.rs @@ -0,0 +1,31 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-tidy-linelength +// compile-flags: --no-defaults --passes collapse-docs --passes unindent-comments --passes strip-priv-imports + +#![crate_name = "foo"] + +// @has foo/fn.bar.html +// @has - '//*[@class="rust fn"]' 'pub fn bar() -> ' +/// foo +pub fn bar() -> usize { + 2 +} + +// @has foo/struct.Foo.html +// @has - '//*[@class="method"]' 'pub fn new()' +// @has - '//*[@class="method"]' 'fn not_pub()' +pub struct Foo(usize); + +impl Foo { + pub fn new() -> Foo { Foo(0) } + fn not_pub() {} +}