Skip to content

Commit 598a02c

Browse files
committed
rustdoc: remove orphaned link on array bracket
This is 682889f, but for arrays instead. For non-generics, this retains links to the array page, but instead of trying to link it all, it only links the length part, which distinguishes arrays from slices. For generics, the entire thing becomes a link, just like slices.
1 parent 75d3027 commit 598a02c

6 files changed

+50
-8
lines changed

src/librustdoc/html/format.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -1010,15 +1010,25 @@ fn fmt_type<'cx>(
10101010
write!(f, "]")
10111011
}
10121012
},
1013-
clean::Array(ref t, ref n) => {
1014-
primitive_link(f, PrimitiveType::Array, "[", cx)?;
1015-
fmt::Display::fmt(&t.print(cx), f)?;
1016-
if f.alternate() {
1017-
primitive_link(f, PrimitiveType::Array, &format!("; {}]", n), cx)
1018-
} else {
1019-
primitive_link(f, PrimitiveType::Array, &format!("; {}]", Escape(n)), cx)
1013+
clean::Array(ref t, ref n) => match **t {
1014+
clean::Generic(name) if !f.alternate() => primitive_link(
1015+
f,
1016+
PrimitiveType::Array,
1017+
&format!("[{name}; {n}]", n = Escape(n)),
1018+
cx,
1019+
),
1020+
_ => {
1021+
write!(f, "[")?;
1022+
fmt::Display::fmt(&t.print(cx), f)?;
1023+
if f.alternate() {
1024+
write!(f, "; {n}")?;
1025+
} else {
1026+
write!(f, "; ")?;
1027+
primitive_link(f, PrimitiveType::Array, &format!("{n}", n = Escape(n)), cx)?;
1028+
}
1029+
write!(f, "]")
10201030
}
1021-
}
1031+
},
10221032
clean::RawPointer(m, ref t) => {
10231033
let m = match m {
10241034
hir::Mutability::Mut => "mut",
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.array.html">[T; 1]</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.u32.html">u32</a>; <a class="primitive" href="{{channel}}/core/primitive.array.html">1</a>]&gt;</code>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<code>pub fn beta&lt;T&gt;() -&gt; &amp;'static <a class="primitive" href="{{channel}}/core/primitive.array.html">[T; 1]</a></code>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<code>pub fn alpha() -&gt; &amp;'static [<a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a>; <a class="primitive" href="{{channel}}/core/primitive.array.html">1</a>]</code>

src/test/rustdoc/array-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; 1] {
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; 1] {
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; 1]> {
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; 1]> {
27+
loop {}
28+
}

0 commit comments

Comments
 (0)