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

collections: update docs of slice get() and friends #38216

Closed
wants to merge 1 commit into from

Conversation

birkenfeld
Copy link
Contributor

for the new SliceIndex trait. Also made the docs of the unchecked
versions a bit clearer; they return a reference, not an "unsafe
pointer".

@rust-highfive
Copy link
Collaborator

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@frewsxcv
Copy link
Member

frewsxcv commented Dec 7, 2016

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
Copy link
Member

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.

Copy link
Contributor Author

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!
Copy link
Member

Choose a reason for hiding this comment

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

Extra whitespace in here.

Copy link
Contributor Author

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.
Copy link
Member

Choose a reason for hiding this comment

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

Missing url for None.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.
Copy link
Member

Choose a reason for hiding this comment

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

Same.

Copy link
Member

@GuillaumeGomez GuillaumeGomez left a 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.
Copy link
Member

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().

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

Normally yes.

@birkenfeld
Copy link
Contributor Author

ping?

@GuillaumeGomez
Copy link
Member

Don't forget to ping people (just like you did) once you updated. :)

Thanks for your work!

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Dec 15, 2016

📌 Commit 6a80241 has been approved by GuillaumeGomez

@frewsxcv
Copy link
Member

It looks like the Option links are broken in this PR:

Linkcheck stage2 (x86_64-unknown-linux-gnu)
std/primitive.slice.html:185: broken link - /checkout/obj/build/x86_64-unknown-linux-gnu/std/option/enum.Option.html
std/primitive.slice.html:187: broken link - /checkout/obj/build/x86_64-unknown-linux-gnu/std/option/enum.Option.html
std/primitive.slice.html:199: broken link - /checkout/obj/build/x86_64-unknown-linux-gnu/std/option/enum.Option.html

@frewsxcv
Copy link
Member

@bors r-

@frewsxcv
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

@GuillaumeGomez
Copy link
Member

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".
@birkenfeld
Copy link
Contributor Author

birkenfeld commented Dec 16, 2016

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.

@GuillaumeGomez
Copy link
Member

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). :)

@birkenfeld
Copy link
Contributor Author

Aren't they now exactly how you said they should be?

@GuillaumeGomez
Copy link
Member

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...).

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to resubmit with tests fixed!

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 19, 2017
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants