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

Improve the tuple and unit trait docs #97842

Merged
merged 19 commits into from
Jun 16, 2022

Conversation

notriddle
Copy link
Contributor

  • Reduce duplicate impls; show only the (T,) and include a sentence saying that there exists ones up to twelve of them.
  • Show Copy and Clone.
  • Show auto traits like Send and Sync, and blanket impls like Any.

Here's the new version:

@rustbot rustbot added T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jun 7, 2022
@rust-highfive
Copy link
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs to request review from a libs-api team reviewer. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @m-ou-se

(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 7, 2022
@notriddle
Copy link
Contributor Author

CC @rust-lang/rustdoc

@GuillaumeGomez
Copy link
Member

I like the idea, but I'm not convinced by the approach here as I have no idea just from the reading the docs that it is also applied to (T, T1, T2,...).

Also it seems a bit strange to have only T11 in https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html#impl-Debug.

But I really think it's a good start!

@notriddle
Copy link
Contributor Author

@GuillaumeGomez What do you imagine a good approach to this would look like?

@GuillaumeGomez
Copy link
Member

I honestly have absolutely no idea. Providing this information unambigously and efficiently is gonna be the hard part I think.

cc @jsha @Manishearth

@vacuus
Copy link
Contributor

vacuus commented Jun 7, 2022

Perhaps
impl<T0,...> Debug for (T0,...)
This trait is implemented for tuples up to twelve items long, where all items implement Debug. The above syntax is (currently) invalid.

@Manishearth
Copy link
Member

I'm not sure either but yeah I do feel this is an area that could handle improvement.

I think ... is a good way of doing it. We could also do a lil * on the ... and have it show the "only implemented on tuples up till..." in a tooltip if we really want

@notriddle
Copy link
Contributor Author

So, custom unstable attribute that changes the presentation of tuples?

@jsha
Copy link
Contributor

jsha commented Jun 8, 2022

I think impl Foo for (T, ...) is good. The (T, ...) part should link to a subheading of the tuple page's top-doc that says:

(T, ...)

In this documentation the shorthand (T, ...) is used to represent all tuples up to length twelve. When that is used, any trait bounds expressed on T applies to each field of the tuple independently. Note that this is a convenience notation to avoid repetitive documentation, not valid Rust syntax.

This commit adds a new unstable attribute, `#[doc(tuple_varadic)]`, that
shows a 1-tuple as `(T, ...)` instead of just `(T,)`, and links to a section
in the tuple primitive docs that talks about these.
Before:

    impl<T, U> UnwindSafe for (T, ...) where
        T: UnwindSafe,
        U: UnwindSafe,

After:

    impl<T> UnwindSafe for (T, ...) where
        T: UnwindSafe,
@notriddle
Copy link
Contributor Author

@jsha Okay, here’s a new version with that idea implemented. It does look quite a bit better.

@vacuus
Copy link
Contributor

vacuus commented Jun 9, 2022

(I realize I'm being pedantic 😄 )

In the "Trait implementations" subheading:

In this documentation the shorthand (T, ...) is used to represent all tuples up to length twelve.

But in the impl Clone/impl Copy:

This trait is implemented on arbitrary-length tuples.

Instead, the subheading could say

In this documentation the shorthand (T, ...) is used to represent all tuples up to some length, depending on the trait.

or outright state that it's a length of twelve except for Clone/Copy

@notriddle
Copy link
Contributor Author

In this documentation the shorthand (T, ...) is used to represent tuples of varying length. Any trait bounds expressed on T applies to each field of the tuple independently. Note that this is a convenience notation to avoid repetitive documentation, not valid Rust syntax.

Due to a temporary restriction in Rust’s type system, most traits are only implemented on tuples of arity 12 or less. In the future, this may change.

Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The display and the text are looking good to me. Just to check: are the demo links up to date?

A note on consistency: the current demo has:

impl<T: Clone> Clone for (T, ...)
impl<T11> Debug for (T11, ...)
impl<L> Default for (L, ...)
impl<A> Hash for (A, ...)

I haven't fully grokked the macros yet, so it's not clear to me where the T, T11, L, and A are coming from. It would be nice for them to be consistently T unless the other type variable names mean something.

compiler/rustc_span/src/symbol.rs Outdated Show resolved Hide resolved
library/core/src/primitive_docs.rs Outdated Show resolved Hide resolved
library/std/src/primitive_docs.rs Outdated Show resolved Hide resolved
src/librustdoc/html/format.rs Outdated Show resolved Hide resolved
@notriddle
Copy link
Contributor Author

I like the idea of using Unicode ellipses.

Maybe, to avoid being overly verbose, it could use subscripts in the tuple, but not elsewhere?

impl<T: Copy> Copy for (T₁, T₂, …, Tₙ)

@m-ou-se
Copy link
Member

m-ou-se commented Jun 14, 2022

Yeah, I think that works well!

@fbstj
Copy link
Contributor

fbstj commented Jun 14, 2022

impl<Tᵢ: Copy> Copy for (T₁, T₂, …, Tₙ) too?

@m-ou-se
Copy link
Member

m-ou-se commented Jun 14, 2022

impl<Tᵢ: Copy> Copy for (T₁, T₂, …, Tₙ) too?

Hm, that might result in people wondering what the i represents. (And adding more notation with and i ∈ {1, 2, …, n} or something like that probably goes a bit too far. ^^)

But I don't have a strong opinion either way. It could also work nicely. :)

@GuillaumeGomez
Copy link
Member

Mathematical notation overload. :D

@jsha
Copy link
Contributor

jsha commented Jun 14, 2022

Maybe, to avoid being overly verbose, it could use subscripts in the tuple, but not elsewhere?
impl<T: Copy> Copy for (T₁, T₂, …, Tₙ)

I like this version. And the detail that T's bound must apply to each Tₙ individually can be explained in the linked paragraph in the documentation.

@notriddle
Copy link
Contributor Author

Okay, I've update the uploaded docs page to have the new unicode presentation: https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html#impl-Copy

image

@GuillaumeGomez
Copy link
Member

Looks almost all good to me. Can you add a test for the notation as well please?

@GuillaumeGomez
Copy link
Member

Looks good to me, thanks!

@GuillaumeGomez
Copy link
Member

Let's go then. Thanks everyone for the feedback!

@bors r=jsha,GuillaumeGomez

@bors
Copy link
Contributor

bors commented Jun 16, 2022

📌 Commit f1d24be has been approved by jsha,GuillaumeGomez

@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 16, 2022
@bors
Copy link
Contributor

bors commented Jun 16, 2022

⌛ Testing commit f1d24be with merge 6ec3993...

@bors
Copy link
Contributor

bors commented Jun 16, 2022

☀️ Test successful - checks-actions
Approved by: jsha,GuillaumeGomez
Pushing 6ec3993 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 16, 2022
@bors bors merged commit 6ec3993 into rust-lang:master Jun 16, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 16, 2022
@notriddle notriddle deleted the notriddle/tuple-docs branch June 16, 2022 14:01
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6ec3993): comparison url.

Instruction count

  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: 😿 relevant regressions found
mean1 max count2
Regressions 😿
(primary)
0.4% 0.6% 2
Regressions 😿
(secondary)
0.3% 0.4% 3
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) 0.4% 0.6% 2

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: 😿 relevant regression found
mean1 max count2
Regressions 😿
(primary)
0.6% 0.6% 1
Regressions 😿
(secondary)
3.0% 3.0% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) 0.6% 0.6% 1

Cycles

Results
  • Primary benchmarks: 🎉 relevant improvement found
  • Secondary benchmarks: 🎉 relevant improvement found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
-2.2% -2.2% 1
Improvements 🎉
(secondary)
-3.1% -3.1% 1
All 😿🎉 (primary) -2.2% -2.2% 1

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot added the perf-regression Performance regression. label Jun 16, 2022
@Mark-Simulacrum Mark-Simulacrum added the perf-regression-triaged The performance regression has been triaged. label Jun 21, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 19, 2022
…rochenkov,GuillaumeGomez

Improve the function pointer docs

This is rust-lang#97842 but for function pointers instead of tuples. The concept is basically the same.

* Reduce duplicate impls; show `fn (T₁, T₂, …, Tₙ)` and include a sentence saying that there exists up to twelve of them.
* Show `Copy` and `Clone`.
* Show auto traits like `Send` and `Sync`, and blanket impls like `Any`.

https://notriddle.com/notriddle-rustdoc-test/std/primitive.fn.html
@@ -125,4 +156,4 @@ macro_rules! last_type {
($a:ident, $($rest_a:ident,)+) => { last_type!($($rest_a,)+) };
}

tuple_impls!(A B C D E F G H I J K L);
tuple_impls!(E D C B A Z Y X W V U T);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it’s so that the tuple docs consistently show (T…) instead of (L…)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't s/L/T suffice then? The letters seem random...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work, yes.

@jsha
Copy link
Contributor

jsha commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. 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.