Skip to content

Commit 682889f

Browse files
committed
rustdoc: remove link on slice brackets
Since rust-lang#97668 was merged, the slice::get function now looks like this: ![image](https://user-images.githubusercontent.com/1593513/173430685-1dd2b275-2439-4392-b7d4-96bcb355a377.png) That whole thing, `[T]`, is a single link to `primitive.slice.html`. This definitely fixes it for this case, but it's not obvious what we should do for slices of concrete types: ![image](https://user-images.githubusercontent.com/1593513/173430968-7eed1aec-b688-4f84-a492-9210aff0037a.png) There are actually three links in that `[u8]`: the opening brace `[` is a link to `primitive.slice.html`, the `u8` is a link to `primitive.u8.html`, and the final `]` is a link to `primitive.slice.html`. This is a serious [usability bug](https://usability.yale.edu/web-accessibility/articles/links): the square braces are much too small for anyone who doesn't have perfect motor control using mouse or touch, provide an excessive number of tab stops for anyone using keyboard, and no visual indication whatsoever that they're separate links. Now that slices of generic types are linked, it seems reasonable to err on the side of less clutter and stop linking concrete slices to the slice page.
1 parent 083721a commit 682889f

File tree

4 files changed

+5
-30
lines changed

4 files changed

+5
-30
lines changed

src/librustdoc/html/format.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,9 @@ fn fmt_type<'cx>(
886886
primitive_link(f, PrimitiveType::Slice, &format!("[{name}]"), cx)
887887
}
888888
_ => {
889-
primitive_link(f, PrimitiveType::Slice, "[", cx)?;
889+
write!(f, "[")?;
890890
fmt::Display::fmt(&t.print(cx), f)?;
891-
primitive_link(f, PrimitiveType::Slice, "]", cx)
891+
write!(f, "]")
892892
}
893893
},
894894
clean::Array(ref t, ref n) => {
@@ -926,31 +926,6 @@ fn fmt_type<'cx>(
926926
let m = mutability.print_with_space();
927927
let amp = if f.alternate() { "&".to_string() } else { "&amp;".to_string() };
928928
match **ty {
929-
clean::Slice(ref bt) => {
930-
// `BorrowedRef{ ... Slice(T) }` is `&[T]`
931-
match **bt {
932-
clean::Generic(name) => primitive_link(
933-
f,
934-
PrimitiveType::Slice,
935-
&format!("{amp}{lt}{m}[{name}]"),
936-
cx,
937-
),
938-
_ => {
939-
primitive_link(
940-
f,
941-
PrimitiveType::Slice,
942-
&format!("{}{}{}[", amp, lt, m),
943-
cx,
944-
)?;
945-
if f.alternate() {
946-
write!(f, "{:#}", bt.print(cx))?;
947-
} else {
948-
write!(f, "{}", bt.print(cx))?;
949-
}
950-
primitive_link(f, PrimitiveType::Slice, "]", cx)
951-
}
952-
}
953-
}
954929
clean::DynTrait(ref bounds, ref trait_lt)
955930
if bounds.len() > 1 || trait_lt.is_some() =>
956931
{
Original file line numberDiff line numberDiff line change
@@ -1 +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>
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>]&gt;</code>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<code>pub fn beta&lt;T&gt;() -&gt; <a class="primitive" href="{{channel}}/core/primitive.slice.html">&amp;'static [T]</a></code>
1+
<code>pub fn beta&lt;T&gt;() -&gt; &amp;'static <a class="primitive" href="{{channel}}/core/primitive.slice.html">[T]</a></code>
Original file line numberDiff line numberDiff line change
@@ -1 +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>
1+
<code>pub fn alpha() -&gt; &amp;'static [<a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a>]</code>

0 commit comments

Comments
 (0)