Skip to content

Commit

Permalink
Auto merge of rust-lang#110945 - wackbyte:doc-vis-on-inherent-assoc-t…
Browse files Browse the repository at this point in the history
…ypes, r=jsha

rustdoc: render visibility on associated types

This should only affect inherent associated types (rust-lang#8995).
  • Loading branch information
bors committed Jun 5, 2023
2 parents e410606 + 16749d1 commit 51f714c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,10 +787,12 @@ fn assoc_type(
indent: usize,
cx: &Context<'_>,
) {
let tcx = cx.tcx();
write!(
w,
"{indent}type <a{href} class=\"associatedtype\">{name}</a>{generics}",
"{indent}{vis}type <a{href} class=\"associatedtype\">{name}</a>{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),
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc/anchors.no_type_anchor2.html
Original file line number Diff line number Diff line change
@@ -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>
<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>
25 changes: 25 additions & 0 deletions tests/rustdoc/visibility.rs
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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() {}
}

0 comments on commit 51f714c

Please sign in to comment.