Uh oh!
There was an error while loading. Please reload this page.
Std module docs improvements - #93162
Conversation
rust-highfive
commented
Jan 21, 2022
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
m-ou-se
commented
Jan 22, 2022
It makes me super happy to see someone working on documentation consistency. I'll try to make the time to review this soon. |
m-ou-se
left a comment
There was a problem hiding this comment.
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. :)
There was a problem hiding this comment.
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.
| /// 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. |
There was a problem hiding this comment.
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.
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.
"Slices" might be important to not cause confusion with the String type.
I'm not how sure "slice" applies to a
const &'static strfor 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.
I'll just revert this.
There was a problem hiding this comment.
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.
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.
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.
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.
There was a problem hiding this comment.
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; | |
| /// } | |
| /// ``` |
JohnCSimon
commented
Mar 6, 2022
ping from triage: FYI: when a PR is ready for review, post a message containing |
camsteffen
commented
Mar 6, 2022
My bad. Waiting for feedback. @rustbot ready |
bors
commented
Mar 11, 2022
☔ The latest upstream changes (presumably #94824) made this pull request unmergeable. Please resolve the merge conflicts. |
camsteffen
commented
Apr 30, 2022
@rustbot ready Rebased and addressed comments. |
camsteffen
commented
Apr 30, 2022
Threw in a fix for variable capturing in |
bors
commented
May 26, 2022
☔ 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 |
bors
commented
Jun 10, 2022
☔ The latest upstream changes (presumably #91970) made this pull request unmergeable. Please resolve the merge conflicts. |
JohnCSimon
commented
Jul 3, 2022
ping from triage: |
This comment was marked as resolved.
This comment was marked as resolved.
camsteffen
commented
Jul 3, 2022
Rebased. I decided to bulldoze the header line added to |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
camsteffen
commented
Aug 20, 2022
Addressed @Mark-Simulacrum's comments. @rustbot ready |
Uh oh!
There was an error while loading. Please reload this page.
Mark-Simulacrum
commented
Aug 20, 2022
r=me with commits squashed and the unrelated tidy change dropped. |
camsteffen
commented
Aug 20, 2022
@bors r=Mark-Simulacrum |
bors
commented
Aug 20, 2022
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
yaahc
commented
Aug 22, 2022
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::ptrshould be inpointerbut I did not address this.