-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve the documentation of primitive types #11409
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Adding these lang items probably requires further discussion. |
This is pretty darn cool. |
Tuples are not supported either? (For vectors and strings, maybe the easiest path is have lang items for the actual types (to give the sugar) and have |
@@ -4979,3 +4983,39 @@ impl substs { | |||
} | |||
} | |||
} | |||
|
|||
/// Register a primitive type as having it's lang-item implementation in this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "its"
Aha, you are more astute than I @huonw! I forgot to mention that yes, this doesn't cover tuples as well. The general idea is that I'm not sure how to deal with type parameters right now. I think that In the future it sounds like the "vector builder" will be a documentable type, but slices and fixed-size arrays will always be able to have methods on them and we should be able to document them somehow. I think that the threshold for knowing whether the docs are sufficient is currently answering the question "What can I do with |
It's not just to get better documentation, having a large number of one-implementation traits isn't exactly nice from a maintainability perspective. (Although documentation is the big problem.) Also, this lang-items-on-impls approach means that you can only have one impl uint {
fn some_method(&self) {}
}
impl uint {
fn some_other_method(&self) {}
} This isn't too problematic for plain types like |
Can we attach the lang items them to private placeholder types and then permit an |
It's true, and I certainly don't think we should take the state of the standard library as-is today and document it. I totally agree that we need to remove all the one-off traits for vectors and strings. I probably should have phrased that along the lines of avoiding rearchitecting all of libstd, but small reorganizations like collecting everything in one impl seems fine to me. It is a little limiting that you can only have on My initial reaction for vectors was |
Hm, so rustdoc will always have to do something special in order to deal with primitive types, but there's also a question to what degree rustc itself needs to be modified as well. That may work though having a private I haven't really given these too much thought, my main goal was to get something reasonable for primitive types, but perhaps for vectors some sort of lang item not on the impl may work best. |
@alexcrichton: I was thinking that there just needs to be a single dummy lang item ( |
/// A convenience form for basic repetition. Given a uint `x`, | ||
/// `x.times(|| { ... })` executes the given block x times. | ||
/// | ||
/// Equivalent to `for uint::range(0, x) |_| { ... }`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just range
now rather than uint::range
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also, the syntax is all wrong.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
What's the point of the lang items? Surely the compiler and rustdoc can recognize an "impl u8" without the lang item? At most it seems one might need a single lang item to mark libstd as the crate to lookup those impls in / allow it to provide impls for primitives. Or perhaps a single "primitive_impl" lang item on each impl. |
The current coherence infrastructure can't handle multiple |
ping, from what it sounds like there's no consensus on whether this is the right approach to take, and I'd like to get something like this merged. This will greatly improve the experience for looking at primitive docs. (I'll rebase this soon as well). |
Let's talk about it at the meeting tomorrow. |
r? We decided in today's meeting that we'd like to merge this, and we can revisit str/vec when DST comes about. |
Repeating my comment in response to the meeting:
|
This solves horrible diffs where all you do is renumber literally everything.
These impls are mostly currently blank, but they will get filled out in the future with implementations as we remove satellite traits in favor of inherent methods on primitives.
This piggybacks on the previous commits to add impls of primitives directly.
This ended up hitting coherence difficulties, I'll try to get back to this |
In today's rustdoc world, if you have the simple question of "What can I do with
i8
?" it turns out the answer is "good luck". The reason for this is that there is no page in the rustdoc documentation which shows any information about primitive types.This commit adds support for a lang item per primitive which is allowed to define inherent methods of primitive types. This alleviates concerns of duplicate inherent impls for primitive types, and also allows in theory removal of lots of satellite traits lying around.
Additionally, I have added support to rustdoc to render pretty pages for all primitive types. Additionally, all mentions of primitive types are hyperlinked to their definition (as one might expect).
I didn't remove any traits other than
Times
(for a direct inherent impl onuint
), but in theory many more can be removed in the future.The astute may notice that this is not done for string and vector types yet. I haven't quite figured out how to do that just yet.