-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
collections: update docs of slice get() and friends #38216
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
Looks like Travis found an error in a doc example. |
@@ -343,15 +343,17 @@ impl<T> [T] { | |||
core_slice::SliceExt::last_mut(self) | |||
} | |||
|
|||
/// Returns the element of a slice at the given index, or `None` if the | |||
/// index is out of bounds. | |||
/// Returns the element or subslice of a slice at the given position or |
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.
It might be more clear to spell out the overloading in more detail here -- that is, to say something like:
- If given a position, returns the element at that position of
None
if out of bounds. - If given a range, returns the subslice corresponding to that range, or
None
if out of bounds.
And similarly elsewhere.
Otherwise r=me once travis is happy.
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.
Tried to do that now without too much repetition. Let me know if you want the details in all the method docs.
/// Returns a pointer to the element at the given index, without doing | ||
/// bounds checking. So use it very carefully! | ||
/// Returns a reference to an element or subslice, without doing bounds | ||
/// checking. So use it very carefully! |
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.
Extra whitespace in here.
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.
Fixing.
/// index. | ||
/// | ||
/// - If given a position, returns a reference to the element at that | ||
/// position or `None` if out of bounds. |
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.
Missing url for None
.
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.
Huh? There are more instances of None
without a link in the file. Does it have to be linked every time?
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.
Not to mention that every reference to None
seems to be different. There's (all in non-std crates that get re-exported to std)
[`None`]: ../../std/option/enum.Option.html#variant.None
[`None`]: option/enum.Option.html#variant.None
[option]: ../../std/option/enum.Option.html
Which is the preferred one?
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.
The first one. And yes, every method/struct/enum/... should be linked. I'm currently fixing all this but when I see a PR, I try to enforce it there as well.
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.
Done!
/// - If given a position, returns a reference to the element at that | ||
/// position or `None` if out of bounds. | ||
/// - If given a range, returns the subslice corresponding to that range, | ||
/// or `None` if out of bounds. |
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.
Same.
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.
Just one last issue! :)
@@ -361,7 +370,10 @@ impl<T> [T] { | |||
core_slice::SliceExt::get(self, index) | |||
} | |||
|
|||
/// Returns a mutable reference to the element at the given index. | |||
/// Returns a mutable reference to an element or subslice depending on the | |||
/// type of index (see `get`) or [`None`] if the index is out of bounds. |
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.
Missing get
url. Also, should be get()
.
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.
So that's just #method.get
I assume?
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.
Normally yes.
5dcd548
to
6a80241
Compare
ping? |
Don't forget to ping people (just like you did) once you updated. :) Thanks for your work! @bors: r+ rollup |
📌 Commit 6a80241 has been approved by |
It looks like the
|
@bors r- |
No need to hold these changes up for the links, so feel free to remove them. The doc links are very fragile right now and need improvement. |
/// - If given a range, returns the subslice corresponding to that range, | ||
/// or [`None`] if out of bounds. | ||
/// | ||
/// [`None`]: ../../std/option/enum.Option.html#variant.None |
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.
There is an extra "..". Should be: ../std/option/enum.Option.html#variant.None
.
/// type of index (see [`get()`]) or [`None`] if the index is out of bounds. | ||
/// | ||
/// [`get()`]: #method.get | ||
/// [`None`]: ../../std/option/enum.Option.html#variant.None |
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.
Same as above.
Please fix the url. If this change doesn't work, then just remove them but I'd like to give it a try first. |
for the new SliceIndex trait. Also made the docs of the unchecked versions a bit clearer; they return a reference, not an "unsafe pointer".
6a80241
to
2c7bb2a
Compare
Ok, updated. If it is still not ok, you got access to the branch. I think project owners can do these small fixups much quicker on their own. |
Still broken urls. Well, let's just forget about them this time. I'll remove them from your PR in the next days (if you don't update it before). :) |
Aren't they now exactly how you said they should be? |
Yes, but now they need a supplementary ".." it said it wasn't needed previously (take a look at the CI for the details). Since I can't explain this behaviour, let's just forget about the urls (even if it pains me a lot...). |
Closing due to inactivity, but feel free to resubmit with tests fixed! |
collections: update docs of slice get() and friends Resubmit of rust-lang#38216. r? @GuillaumeGomez BTW, instead of closing a PR just because it is old and the team member who offered to fix it up did not have the time to do so, why not ping them instead? (cc @alexcrichton)
for the new SliceIndex trait. Also made the docs of the unchecked
versions a bit clearer; they return a reference, not an "unsafe
pointer".