Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: clean up primitive.slice.html links #97668

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/etc/htmldocck.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ def check_snapshot(snapshot_name, actual_tree, normalize_to_text):
else:
actual_str = flatten(actual_tree)

expected_str = expected_str.replace("{{channel}}", channel)

# Conditions:
# 1. Is --bless
# 2. Are actual and expected tree different
Expand Down
38 changes: 16 additions & 22 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,11 +881,16 @@ fn fmt_type<'cx>(
}
}
}
clean::Slice(ref t) => {
primitive_link(f, PrimitiveType::Slice, "[", cx)?;
fmt::Display::fmt(&t.print(cx), f)?;
primitive_link(f, PrimitiveType::Slice, "]", cx)
}
clean::Slice(ref t) => match **t {
clean::Generic(name) => {
primitive_link(f, PrimitiveType::Slice, &format!("[{name}]"), cx)
}
_ => {
primitive_link(f, PrimitiveType::Slice, "[", cx)?;
fmt::Display::fmt(&t.print(cx), f)?;
primitive_link(f, PrimitiveType::Slice, "]", cx)
}
},
clean::Array(ref t, ref n) => {
primitive_link(f, PrimitiveType::Array, "[", cx)?;
fmt::Display::fmt(&t.print(cx), f)?;
Expand Down Expand Up @@ -924,23 +929,12 @@ fn fmt_type<'cx>(
clean::Slice(ref bt) => {
// `BorrowedRef{ ... Slice(T) }` is `&[T]`
match **bt {
clean::Generic(_) => {
if f.alternate() {
primitive_link(
f,
PrimitiveType::Slice,
&format!("{}{}{}[{:#}]", amp, lt, m, bt.print(cx)),
cx,
)
} else {
primitive_link(
f,
PrimitiveType::Slice,
&format!("{}{}{}[{}]", amp, lt, m, bt.print(cx)),
cx,
)
}
}
clean::Generic(name) => primitive_link(
f,
PrimitiveType::Slice,
&format!("{amp}{lt}{m}[{name}]"),
cx,
),
_ => {
primitive_link(
f,
Expand Down
1 change: 1 addition & 0 deletions src/test/rustdoc/slice-links.link_box_generic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<code>pub fn delta&lt;T&gt;() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;<a class="primitive" href="{{channel}}/core/primitive.slice.html">[T]</a>&gt;</code>
1 change: 1 addition & 0 deletions src/test/rustdoc/slice-links.link_box_u32.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<code>pub fn gamma() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;<a class="primitive" href="{{channel}}/core/primitive.slice.html">[</a><a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a><a class="primitive" href="{{channel}}/core/primitive.slice.html">]</a>&gt;</code>
1 change: 1 addition & 0 deletions src/test/rustdoc/slice-links.link_slice_generic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<code>pub fn beta&lt;T&gt;() -&gt; <a class="primitive" href="{{channel}}/core/primitive.slice.html">&amp;'static [T]</a></code>
1 change: 1 addition & 0 deletions src/test/rustdoc/slice-links.link_slice_u32.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<code>pub fn alpha() -&gt; <a class="primitive" href="{{channel}}/core/primitive.slice.html">&amp;'static [</a><a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a><a class="primitive" href="{{channel}}/core/primitive.slice.html">]</a></code>
28 changes: 28 additions & 0 deletions src/test/rustdoc/slice-links.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![crate_name = "foo"]
#![no_std]

pub struct MyBox<T: ?Sized>(*const T);

// @has 'foo/fn.alpha.html'
// @snapshot link_slice_u32 - '//pre[@class="rust fn"]/code'
pub fn alpha() -> &'static [u32] {
loop {}
}

// @has 'foo/fn.beta.html'
// @snapshot link_slice_generic - '//pre[@class="rust fn"]/code'
pub fn beta<T>() -> &'static [T] {
loop {}
}

// @has 'foo/fn.gamma.html'
// @snapshot link_box_u32 - '//pre[@class="rust fn"]/code'
pub fn gamma() -> MyBox<[u32]> {
loop {}
}

// @has 'foo/fn.delta.html'
// @snapshot link_box_generic - '//pre[@class="rust fn"]/code'
pub fn delta<T>() -> MyBox<[T]> {
loop {}
}