Skip to content

Commit 7dd3861

Browse files
committed
rustdoc: clean up primitive.slice.html links
1 parent e714405 commit 7dd3861

6 files changed

+48
-22
lines changed

src/librustdoc/html/format.rs

+16-22
Original file line numberDiff line numberDiff line change
@@ -881,11 +881,16 @@ fn fmt_type<'cx>(
881881
}
882882
}
883883
}
884-
clean::Slice(ref t) => {
885-
primitive_link(f, PrimitiveType::Slice, "[", cx)?;
886-
fmt::Display::fmt(&t.print(cx), f)?;
887-
primitive_link(f, PrimitiveType::Slice, "]", cx)
888-
}
884+
clean::Slice(ref t) => match **t {
885+
clean::Generic(name) => {
886+
primitive_link(f, PrimitiveType::Slice, &format!("[{name}]"), cx)
887+
}
888+
_ => {
889+
primitive_link(f, PrimitiveType::Slice, "[", cx)?;
890+
fmt::Display::fmt(&t.print(cx), f)?;
891+
primitive_link(f, PrimitiveType::Slice, "]", cx)
892+
}
893+
},
889894
clean::Array(ref t, ref n) => {
890895
primitive_link(f, PrimitiveType::Array, "[", cx)?;
891896
fmt::Display::fmt(&t.print(cx), f)?;
@@ -924,23 +929,12 @@ fn fmt_type<'cx>(
924929
clean::Slice(ref bt) => {
925930
// `BorrowedRef{ ... Slice(T) }` is `&[T]`
926931
match **bt {
927-
clean::Generic(_) => {
928-
if f.alternate() {
929-
primitive_link(
930-
f,
931-
PrimitiveType::Slice,
932-
&format!("{}{}{}[{:#}]", amp, lt, m, bt.print(cx)),
933-
cx,
934-
)
935-
} else {
936-
primitive_link(
937-
f,
938-
PrimitiveType::Slice,
939-
&format!("{}{}{}[{}]", amp, lt, m, bt.print(cx)),
940-
cx,
941-
)
942-
}
943-
}
932+
clean::Generic(name) => primitive_link(
933+
f,
934+
PrimitiveType::Slice,
935+
&format!("{amp}{lt}{m}[{name}]"),
936+
cx,
937+
),
944938
_ => {
945939
primitive_link(
946940
f,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<code>pub fn beta&lt;T&gt;() -&gt; <a class="primitive" href="{{channel}}/core/primitive.slice.html">&amp;'static [T]</a></code>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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>

src/test/rustdoc/slice-links.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![crate_name = "foo"]
2+
#![no_std]
3+
4+
pub struct MyBox<T: ?Sized>(*const T);
5+
6+
// @has 'foo/fn.alpha.html'
7+
// @snapshot link_slice_u32 - '//pre[@class="rust fn"]/code'
8+
pub fn alpha() -> &'static [u32] {
9+
loop {}
10+
}
11+
12+
// @has 'foo/fn.beta.html'
13+
// @snapshot link_slice_generic - '//pre[@class="rust fn"]/code'
14+
pub fn beta<T>() -> &'static [T] {
15+
loop {}
16+
}
17+
18+
// @has 'foo/fn.gamma.html'
19+
// @snapshot link_box_u32 - '//pre[@class="rust fn"]/code'
20+
pub fn gamma() -> MyBox<[u32]> {
21+
loop {}
22+
}
23+
24+
// @has 'foo/fn.delta.html'
25+
// @snapshot link_box_generic - '//pre[@class="rust fn"]/code'
26+
pub fn delta<T>() -> MyBox<[T]> {
27+
loop {}
28+
}

0 commit comments

Comments
 (0)