-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Std module docs improvements #93162
Std module docs improvements #93162
Conversation
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
It makes me super happy to see someone working on documentation consistency. I'll try to make the time to review this soon. |
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 great. Thanks for doing this.
I have a few small comments, but all of them are basically comments about the old documentation that you moved, so not really comments on your changes. If you feel like addressing them, go ahead. But r=me
either way. :)
library/core/src/primitive_docs.rs
Outdated
/// ``` | ||
/// | ||
/// They are `'static` because they're stored directly in the final binary, and | ||
/// so will be valid for the `'static` duration. | ||
/// Here we have declared a string literal, also known as a string slice. |
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.
While every string literal is a string slice, not every string slice is a literal, so let's avoid implying they are the same thing. (A 'string slice' could also refer to (a part of) a String
, for example.)
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.
/// Here we have declared a string literal, also known as a string slice. | |
/// Here we have declared a string slice initialized with a string literal. |
library/core/src/primitive_docs.rs
Outdated
#[stable(feature = "rust1", since = "1.0.0")] | ||
mod prim_slice {} | ||
|
||
#[doc(primitive = "str")] | ||
// | ||
/// String slices. | ||
/// Unicode string slices. |
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.
I'd be careful with using the term 'unicode string'. That's used in some other languages/on other platforms to refer to [u32]
or [u16]
string representations. You could mention UTF-8 specifically, but that's already mentioned below and might be a bit too much detail for the first line.
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.
I could just undo this change. Also is "slices" a bit over-technical or confusing? I'm not how sure "slice" applies to a const &'static str
for example. How about "The primitive string type"?
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.
"Slices" might be important to not cause confusion with the String
type.
I'm not how sure "slice" applies to a
const &'static str
for example.
That's still a pointer+size to a 'slice' of the program (where the string is stored). But I suppose the main point is that if you take any substring, you still have the same type.
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.
I'll just revert this.
library/core/src/any.rs
Outdated
//! The `Any` trait enables dynamic typing of any `'static` type through runtime | ||
//! reflection. |
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 module also provides TypeId
and type_name
. While related to Any
, they're also useful without directly using that trait.
Not entirely sure how to summarize these together in one line though. Something about type erasure or dynamic typing or reflection maybe?
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.
How about
Utilities for dynamic typing or working with any type.
supposing Any
and TypeId
falls under "dynamic typing" and type_name
is a util that works with any type.
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.
Yeah that could work. Or maybe "Utilities related to type erasure."? Either way is fine, as long as it doesn't imply it's only the Any
type.
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.
Currently landed on "Utilities for dynamic typing or type reflection." I feel that "erasure" is a sub-concept of "dynamic typing", and TypeId
and type_name
are both utilities for "reflection", so that word is good to include.
library/core/src/primitive_docs.rs
Outdated
/// ``` | ||
/// let numbers = &[0, 1, 2]; | ||
/// for n in numbers { | ||
/// println!("{} is a number!", n); | ||
/// } | ||
/// ``` | ||
/// | ||
/// The mutable slice yields mutable references to the elements: | ||
/// | ||
/// ``` | ||
/// let mut scores = [7, 8, 9]; | ||
/// for score in &mut scores[..] { | ||
/// *score += 1; | ||
/// } | ||
/// ``` |
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.
Both of these examples work with and without [..]
, but only the mut
version uses that now. The first one now iterates over a reference to an array, not over the (unsized) slice.
Maybe these should coerce the type explicitly to a slice, and then iterate over that without any [..]
?
/// ``` | |
/// let numbers = &[0, 1, 2]; | |
/// for n in numbers { | |
/// println!("{} is a number!", n); | |
/// } | |
/// ``` | |
/// | |
/// The mutable slice yields mutable references to the elements: | |
/// | |
/// ``` | |
/// let mut scores = [7, 8, 9]; | |
/// for score in &mut scores[..] { | |
/// *score += 1; | |
/// } | |
/// ``` | |
/// ``` | |
/// let numbers: &[i32] = &[0, 1, 2]; | |
/// for n in numbers { | |
/// println!("{} is a number!", n); | |
/// } | |
/// ``` | |
/// | |
/// The mutable slice yields mutable references to the elements: | |
/// | |
/// ``` | |
/// let scores: &mut [i32] = &mut [7, 8, 9]; | |
/// for score in scores { | |
/// *score += 1; | |
/// } | |
/// ``` |
ping from triage: FYI: when a PR is ready for review, post a message containing |
My bad. Waiting for feedback. @rustbot ready |
☔ The latest upstream changes (presumably #94824) made this pull request unmergeable. Please resolve the merge conflicts. |
84bec7d
to
fb046bf
Compare
@rustbot ready Rebased and addressed comments. |
fb046bf
to
796af21
Compare
Threw in a fix for variable capturing in |
☔ The latest upstream changes (presumably #97434) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased. I'm not sure if I'm conflicting with the intent of #96033 which seems to make |
☔ The latest upstream changes (presumably #91970) made this pull request unmergeable. Please resolve the merge conflicts. |
ping from triage: |
This comment was marked as resolved.
This comment was marked as resolved.
Rebased. I decided to bulldoze the header line added to |
Addressed @Mark-Simulacrum's comments. @rustbot ready |
r=me with commits squashed and the unrelated tidy change dropped. |
39c3bea
to
17ddcb4
Compare
@bors r=Mark-Simulacrum |
Rollup of 5 pull requests Successful merges: - rust-lang#93162 (Std module docs improvements) - rust-lang#99386 (Add tests that check `Vec::retain` predicate execution order.) - rust-lang#99915 (Recover keywords in trait bounds) - rust-lang#100694 (Migrate rustc_ast_passes diagnostics to `SessionDiagnostic` and translatable messages (first part)) - rust-lang#100757 (Catch overflow early) Failed merges: - rust-lang#99917 (Move Error trait into core) r? `@ghost` `@rustbot` modify labels: rollup
Looks like the answer is yes 😅, I'm going to go ahead and revert the change you made to the module description since I intend to have more than just the |
My primary goal is to create a cleaner separation between primitive types and primitive type helper modules (fixes #92777). I also changed a few header lines in other top-level std modules (seen at https://doc.rust-lang.org/std/) for consistency.
Some conventions used/established:
I wonder if some content in
std::ptr
should be inpointer
but I did not address this.