Skip to content

Commit 27f7805

Browse files
authored
Rollup merge of #98069 - notriddle:notriddle/square-brackets, r=jsha
rustdoc: remove link on slice brackets This is #91778, take two. Fixes #91173 The reason I'm reevaluating this change is #97668, which makes fully-generic slices link to the slice docs page. This fixes some downsides in the original PR, where `Box<[T]>`, for example, was not linked to the primitive.slice.html page. In this PR, the `[T]` inside is still a link. The other major reason for wanting to reevaluate this is the changed color scheme. When this feature was first introduced in rustdoc, primitives were a different color from structs and enums. This way, eagle-eyed users could figure out that the square brackets were separate links from the structs inside. Now, all types have the same color, so a significant fraction of users won't even know the links are there unless they pay close attention to the status bar or use an accessibility tool that lists all links on the page.
2 parents e565541 + 682889f commit 27f7805

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)