From db5d3f04c6796f7081550de590e860a6350eefda Mon Sep 17 00:00:00 2001 From: wackbyte Date: Thu, 27 Apr 2023 23:03:08 -0400 Subject: [PATCH 1/3] rustdoc: render visibility on associated types This should only affect inherent associated types. --- src/librustdoc/html/render/mod.rs | 4 +++- tests/rustdoc/anchors.no_type_anchor2.html | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index a5f08fdac11..9bac1b93f0d 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -787,10 +787,12 @@ fn assoc_type( indent: usize, cx: &Context<'_>, ) { + let tcx = cx.tcx(); write!( w, - "{indent}type {name}{generics}", + "{indent}{vis}type {name}{generics}", indent = " ".repeat(indent), + vis = visibility_print_with_space(it.visibility(tcx), it.item_id, cx), href = assoc_href_attr(it, link, cx), name = it.name.as_ref().unwrap(), generics = generics.print(cx), diff --git a/tests/rustdoc/anchors.no_type_anchor2.html b/tests/rustdoc/anchors.no_type_anchor2.html index f8b59160f15..9b70da68e78 100644 --- a/tests/rustdoc/anchors.no_type_anchor2.html +++ b/tests/rustdoc/anchors.no_type_anchor2.html @@ -1 +1 @@ -

type Y = u32

\ No newline at end of file +

pub type Y = u32

\ No newline at end of file From c40498422c288b95735c182f99062bb838f728fd Mon Sep 17 00:00:00 2001 From: wackbyte Date: Sat, 29 Apr 2023 15:36:03 -0400 Subject: [PATCH 2/3] Restore channel placeholder --- tests/rustdoc/anchors.no_type_anchor2.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rustdoc/anchors.no_type_anchor2.html b/tests/rustdoc/anchors.no_type_anchor2.html index 9b70da68e78..71e93990e29 100644 --- a/tests/rustdoc/anchors.no_type_anchor2.html +++ b/tests/rustdoc/anchors.no_type_anchor2.html @@ -1 +1 @@ -

pub type Y = u32

\ No newline at end of file +

pub type Y = u32

\ No newline at end of file From 16749d1d999c03014b2fd5d646675c3f6f55afac Mon Sep 17 00:00:00 2001 From: wackbyte Date: Sat, 29 Apr 2023 16:19:57 -0400 Subject: [PATCH 3/3] Add visibility tests for associated items --- tests/rustdoc/visibility.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/rustdoc/visibility.rs b/tests/rustdoc/visibility.rs index 4099b54f081..4f9b06fd7a2 100644 --- a/tests/rustdoc/visibility.rs +++ b/tests/rustdoc/visibility.rs @@ -1,6 +1,8 @@ // compile-flags: --document-private-items #![crate_name = "foo"] +#![feature(inherent_associated_types)] +#![allow(incomplete_features)] // @!has 'foo/index.html' '//a[@href="struct.FooPublic.html"]/..' 'FooPublic 🔒' // @has 'foo/struct.FooPublic.html' '//pre' 'pub struct FooPublic' @@ -103,3 +105,26 @@ impl PubTrait for FooPublic { const CONST: usize = 0; fn function() {} } + +pub struct Assoc; + +// @has foo/struct.Assoc.html +impl Assoc { + // @has - '//*[@id="associatedtype.TypePub"]' 'pub type TypePub' + pub type TypePub = usize; + + // @has - '//*[@id="associatedtype.TypePriv"]' 'pub(crate) type TypePriv' + type TypePriv = usize; + + // @has - '//*[@id="associatedconstant.CONST_PUB"]' 'pub const CONST_PUB' + pub const CONST_PUB: usize = 0; + + // @has - '//*[@id="associatedconstant.CONST_PRIV"]' 'pub(crate) const CONST_PRIV' + const CONST_PRIV: usize = 0; + + // @has - '//*[@id="method.function_pub"]' 'pub fn function_pub()' + pub fn function_pub() {} + + // @has - '//*[@id="method.function_priv"]' 'pub(crate) fn function_priv()' + fn function_priv() {} +}