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: remove link on slice brackets #98069

Merged
merged 1 commit into from
Jun 14, 2022

Conversation

notriddle
Copy link
Contributor

@notriddle notriddle commented Jun 13, 2022

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.

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.
@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jun 13, 2022
@rust-highfive
Copy link
Collaborator

r? @GuillaumeGomez

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 13, 2022
@eggyal
Copy link
Contributor

eggyal commented Jun 13, 2022

I said it on the original issue and I'll say it again here: I do find those links to slice docs occasionally useful—I don't entirely understand what is to be gained from removing them?

@GuillaumeGomez
Copy link
Member

I think the problem is that for [u32], either you click on u32 or the brackets, you end up on different pages and there is no UI distinction. Am I right @jsha? If I guessed it right, shouldn't we underline it on hover instead?

@notriddle
Copy link
Contributor Author

notriddle commented Jun 13, 2022

@GuillaumeGomez

If I guessed it right, shouldn't we underline it on hover instead?

  • That won't work on touchscreens.
  • It requires someone to pay very close attention to the exact span of the underline, which is a bit much to expect.
  • In a lot of web pages, there won't be any visible underline below square brackets in any case, if they have text-decoration-skip-ink turned on and use a font where square brackets descend below the baseline. Even if we turn that off in rustdoc, we can't expect people to know that we turned it off.

@eggyal

I don't entirely understand what is to be gained from removing them?

It should reduce misclicks.

@eggyal
Copy link
Contributor

eggyal commented Jun 13, 2022

Okay, well it's not something I'm going to lose any sleep over though it is a minor niggle.

Maybe there's an alternative solution to the problem of ambiguous links? I rather like a recent update in VSCode that is colouring brackets differently according to their nesting depth (it cycles over three colours): perhaps the same might be a solution here, where each level of type nesting is coloured differently?

@GuillaumeGomez
Copy link
Member

Apart from the debate, the code changes look good to me, thanks!

Let's just wait confirmation from @jsha and then it's good to go. :)

@jsha
Copy link
Contributor

jsha commented Jun 13, 2022

I agree with @notriddle's assessment. Single-character links are hard to click for anyone who doesn't have precise mouse control (for example consider tremors) and high visual acuity. And putting multiple links adjacent to each other makes it hard to discern where one begins and the next ends, making it easy to accidentally click the wrong one. Also: this allows the type inside the brackets to visually stand out better.

FWIW, there will still be a good number of links to the slice page: they will show up any time the slice is fully generic, as @notriddle says in the PR description. For instance, Vec's as_mut_slice:

image

I realize that probably doesn't cover every where you've found a link to the slice docs useful, @eggyal, but hopefully it provides at least some on-ramps.

Another change we've been discussing separately that might help: It would be nice search across std's items from any rustdoc output. That would allow a very quick way to access the slice page: s (to focus the search box), [ (to search for slice).

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jun 13, 2022

📌 Commit 682889f has been approved by jsha

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 13, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 14, 2022
…, r=jsha

rustdoc:  remove link on slice brackets

This is rust-lang#91778, take two.

Fixes rust-lang#91173

The reason I'm reevaluating this change is rust-lang#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.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 14, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#97869 (BTree: tweak internal comments)
 - rust-lang#97935 (Rename the `ConstS::val` field as `kind`.)
 - rust-lang#97948 (lint: add diagnostic translation migration lints)
 - rust-lang#98042 (Fix compat_fn option method on miri)
 - rust-lang#98069 (rustdoc:  remove link on slice brackets)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 27f7805 into rust-lang:master Jun 14, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 14, 2022
@notriddle notriddle deleted the notriddle/square-brackets branch June 14, 2022 15:02
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 19, 2022
…jsha

rustdoc: remove tuple link on round braces

This is rust-lang#98069 but for tuples. The reasoning is the same:

* This PR also changes it so that tuples with all-generic elements still link to the primitive.tuple.html page, just like slices. So there still plenty of on-ramps for anybody who doesn't know about it.
* It's too hard to see when round braces are a separate link from the type inside of them.
* It's too hard to click even if you do notice them.

Before:

* impl [ToSocketAddrs](https://doc.rust-lang.org/nightly/std/net/trait.ToSocketAddrs.html) for [(](https://doc.rust-lang.org/nightly/std/primitive.tuple.html)[IpAddr](https://doc.rust-lang.org/nightly/std/net/enum.IpAddr.html), [u16](https://doc.rust-lang.org/nightly/std/primitive.u16.html)[)](https://doc.rust-lang.org/nightly/std/primitive.tuple.html)
* impl<K, V> [FromIterator](https://notriddle.com/notriddle-rustdoc-test/std/iter/trait.FromIterator.html)<[(](https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html)K, V[)](https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html)> for [BTreeMap](https://notriddle.com/notriddle-rustdoc-test/std/collections/struct.BTreeMap.html)<K, V>

After:

* impl [ToSocketAddrs](https://doc.rust-lang.org/nightly/std/net/trait.ToSocketAddrs.html) for ([IpAddr](https://doc.rust-lang.org/nightly/std/net/enum.IpAddr.html), [u16](https://doc.rust-lang.org/nightly/std/primitive.u16.html))
* impl<K, V> [FromIterator](https://notriddle.com/notriddle-rustdoc-test/std/iter/trait.FromIterator.html)<[(K, V)](https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html)> for [BTreeMap](https://notriddle.com/notriddle-rustdoc-test/std/collections/struct.BTreeMap.html)<K, V>
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 19, 2022
…jsha

rustdoc: remove tuple link on round braces

This is rust-lang#98069 but for tuples. The reasoning is the same:

* This PR also changes it so that tuples with all-generic elements still link to the primitive.tuple.html page, just like slices. So there still plenty of on-ramps for anybody who doesn't know about it.
* It's too hard to see when round braces are a separate link from the type inside of them.
* It's too hard to click even if you do notice them.

Before:

* impl [ToSocketAddrs](https://doc.rust-lang.org/nightly/std/net/trait.ToSocketAddrs.html) for [(](https://doc.rust-lang.org/nightly/std/primitive.tuple.html)[IpAddr](https://doc.rust-lang.org/nightly/std/net/enum.IpAddr.html), [u16](https://doc.rust-lang.org/nightly/std/primitive.u16.html)[)](https://doc.rust-lang.org/nightly/std/primitive.tuple.html)
* impl<K, V> [FromIterator](https://notriddle.com/notriddle-rustdoc-test/std/iter/trait.FromIterator.html)<[(](https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html)K, V[)](https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html)> for [BTreeMap](https://notriddle.com/notriddle-rustdoc-test/std/collections/struct.BTreeMap.html)<K, V>

After:

* impl [ToSocketAddrs](https://doc.rust-lang.org/nightly/std/net/trait.ToSocketAddrs.html) for ([IpAddr](https://doc.rust-lang.org/nightly/std/net/enum.IpAddr.html), [u16](https://doc.rust-lang.org/nightly/std/primitive.u16.html))
* impl<K, V> [FromIterator](https://notriddle.com/notriddle-rustdoc-test/std/iter/trait.FromIterator.html)<[(K, V)](https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html)> for [BTreeMap](https://notriddle.com/notriddle-rustdoc-test/std/collections/struct.BTreeMap.html)<K, V>
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 2, 2022
…GuillaumeGomez,jsha

rustdoc: remove orphaned link on array bracket

This is rust-lang#98069, 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.

| Type | Before | After |
|--|--|--|
| u32 | <code>pub fn alpha() -&gt; &amp;'static <a class="primitive" href="http://doc.rust-lang.org/nightly/core/primitive.array.html">[</a><a class="primitive" href="http://doc.rust-lang.org/nightly/core/primitive.u32.html">u32</a><a class="primitive" href="http://doc.rust-lang.org/nightly/core/primitive.array.html">; 1]</a></code> | <code>pub fn alpha() -&gt; &amp;'static [<a class="primitive" href="http://doc.rust-lang.org/nightly/core/primitive.u32.html">u32</a>; <a class="primitive" href="http://doc.rust-lang.org/nightly/core/primitive.array.html">1</a>]</code>
| generic | <code>pub fn beta&lt;T&gt;() -&gt; &amp;'static <a class="primitive" href="http://doc.rust-lang.org/nightly/core/primitive.array.html">[</a>T<a class="primitive" href="http://doc.rust-lang.org/nightly/core/primitive.array.html">; 1]</a></code> | <code>pub fn beta&lt;T&gt;() -&gt; &amp;'static <a class="primitive" href="http://doc.rust-lang.org/nightly/core/primitive.array.html">[T; 1]</a></code>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc: don't hyperlink square brackets in method signatures
7 participants