Skip to content

Commit 51f714c

Browse files
committed
Auto merge of rust-lang#110945 - wackbyte:doc-vis-on-inherent-assoc-types, r=jsha
rustdoc: render visibility on associated types This should only affect inherent associated types (rust-lang#8995).
2 parents e410606 + 16749d1 commit 51f714c

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

Diff for: src/librustdoc/html/render/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,12 @@ fn assoc_type(
787787
indent: usize,
788788
cx: &Context<'_>,
789789
) {
790+
let tcx = cx.tcx();
790791
write!(
791792
w,
792-
"{indent}type <a{href} class=\"associatedtype\">{name}</a>{generics}",
793+
"{indent}{vis}type <a{href} class=\"associatedtype\">{name}</a>{generics}",
793794
indent = " ".repeat(indent),
795+
vis = visibility_print_with_space(it.visibility(tcx), it.item_id, cx),
794796
href = assoc_href_attr(it, link, cx),
795797
name = it.name.as_ref().unwrap(),
796798
generics = generics.print(cx),

Diff for: tests/rustdoc/anchors.no_type_anchor2.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<section id="associatedtype.Y" class="associatedtype"><h4 class="code-header">type <a href="#associatedtype.Y" class="associatedtype">Y</a> = <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>
1+
<section id="associatedtype.Y" class="associatedtype"><h4 class="code-header">pub type <a href="#associatedtype.Y" class="associatedtype">Y</a> = <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>

Diff for: tests/rustdoc/visibility.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// compile-flags: --document-private-items
22

33
#![crate_name = "foo"]
4+
#![feature(inherent_associated_types)]
5+
#![allow(incomplete_features)]
46

57
// @!has 'foo/index.html' '//a[@href="struct.FooPublic.html"]/..' 'FooPublic 🔒'
68
// @has 'foo/struct.FooPublic.html' '//pre' 'pub struct FooPublic'
@@ -103,3 +105,26 @@ impl PubTrait for FooPublic {
103105
const CONST: usize = 0;
104106
fn function() {}
105107
}
108+
109+
pub struct Assoc;
110+
111+
// @has foo/struct.Assoc.html
112+
impl Assoc {
113+
// @has - '//*[@id="associatedtype.TypePub"]' 'pub type TypePub'
114+
pub type TypePub = usize;
115+
116+
// @has - '//*[@id="associatedtype.TypePriv"]' 'pub(crate) type TypePriv'
117+
type TypePriv = usize;
118+
119+
// @has - '//*[@id="associatedconstant.CONST_PUB"]' 'pub const CONST_PUB'
120+
pub const CONST_PUB: usize = 0;
121+
122+
// @has - '//*[@id="associatedconstant.CONST_PRIV"]' 'pub(crate) const CONST_PRIV'
123+
const CONST_PRIV: usize = 0;
124+
125+
// @has - '//*[@id="method.function_pub"]' 'pub fn function_pub()'
126+
pub fn function_pub() {}
127+
128+
// @has - '//*[@id="method.function_priv"]' 'pub(crate) fn function_priv()'
129+
fn function_priv() {}
130+
}

0 commit comments

Comments
 (0)