Skip to content

Commit 203d71f

Browse files
Add pub visibility for methods as well
1 parent fd4bef5 commit 203d71f

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/librustdoc/html/render.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,8 @@ fn render_assoc_item(w: &mut fmt::Formatter,
25882588
href(did).map(|p| format!("{}#{}.{}", p.0, ty, name)).unwrap_or(anchor)
25892589
}
25902590
};
2591-
let mut head_len = format!("{}{}{:#}fn {}{:#}",
2591+
let mut head_len = format!("{}{}{}{:#}fn {}{:#}",
2592+
VisSpace(&meth.visibility),
25922593
ConstnessSpace(constness),
25932594
UnsafetySpace(unsafety),
25942595
AbiSpace(abi),
@@ -2600,8 +2601,9 @@ fn render_assoc_item(w: &mut fmt::Formatter,
26002601
} else {
26012602
(0, true)
26022603
};
2603-
write!(w, "{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
2604+
write!(w, "{}{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
26042605
{generics}{decl}{where_clause}",
2606+
VisSpace(&meth.visibility),
26052607
ConstnessSpace(constness),
26062608
UnsafetySpace(unsafety),
26072609
AbiSpace(abi),

src/test/rustdoc/pub-method.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-tidy-linelength
12+
// compile-flags: --no-defaults --passes collapse-docs --passes unindent-comments --passes strip-priv-imports
13+
14+
#![crate_name = "foo"]
15+
16+
// @has foo/fn.bar.html
17+
// @has - '//*[@class="rust fn"]' 'pub fn bar() -> '
18+
/// foo
19+
pub fn bar() -> usize {
20+
2
21+
}
22+
23+
// @has foo/struct.Foo.html
24+
// @has - '//*[@class="method"]' 'pub fn new()'
25+
// @has - '//*[@class="method"]' 'fn not_pub()'
26+
pub struct Foo(usize);
27+
28+
impl Foo {
29+
pub fn new() -> Foo { Foo(0) }
30+
fn not_pub() {}
31+
}

0 commit comments

Comments
 (0)