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

Improve documentation for slice strip_* functions #75078

Merged
merged 5 commits into from
Oct 30, 2020

Conversation

ijackson
Copy link
Contributor

@ijackson ijackson commented Aug 3, 2020

Prompted by the stabilisation tracking issue #73413 I looked at the docs for strip_prefix and strip_suffix for both str and slice, and I felt they could be slightly improved.

Thanks for your attention.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 3, 2020
@sfackler
Copy link
Member

sfackler commented Aug 3, 2020

r? @rust-lang/docs

Copy link
Member

@steveklabnik steveklabnik left a comment

Choose a reason for hiding this comment

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

Seems fine, but I have a few questions :)

/// If the string starts with the pattern `prefix`, `Some` is returned with the substring where
/// the prefix is removed. Unlike `trim_start_matches`, this method removes the prefix exactly
/// once.
/// If the string starts with the pattern `prefix`, returns
Copy link
Member

Choose a reason for hiding this comment

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

these lines are wrapped much, much shorter than the old ones were. What column did you wrap these to?

///
/// If the slice does not start with `prefix`, returns `None`.
///
/// (If `prefix` is empty, simply returns the original slice.)
Copy link
Member

Choose a reason for hiding this comment

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

No need for parenthesis around these.

@ijackson
Copy link
Contributor Author

ijackson commented Aug 4, 2020 via email

@LeSeulArtichaut
Copy link
Contributor

Ping from triage: @steveklabnik could you provide feedback/guidance about the last comment? Thanks in advance!

@crlf0710 crlf0710 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 12, 2020
@tesuji
Copy link
Contributor

tesuji commented Sep 13, 2020

r? @jyn514 for reviewing documentation improvement for unstable slice methods: strip_*.

@jyn514 jyn514 added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Sep 13, 2020
@jyn514
Copy link
Member

jyn514 commented Sep 13, 2020

IME line length is one of the major areas of
style dispute so I expected rustfmt to wrap my comment if it disagreed
with my preference of 75.

I think rustfmt will wrap comments if they're longer, but not if they're shorter. So you should match the existing style and only trim it down as necessary (I think the standard library uses 100 columns?)

No need for parenthesis around these.
Without the parens, it reads as if this is a third case

Maybe make it a doc-test instead of a parenthetical? Then it will be tested, too.

@steveklabnik
Copy link
Member

Yes. 75.

If I weren't effectively rewriting it I wouldn't have reformatted it. I ran it through rustfmt and it didn't change the line length. Did I miss a style rule ? IME line length is one of the major areas of style dispute so I expected rustfmt to wrap my comment if it disagreed with my preference of 75.

So here's my recollection: the standard rustfmt style is 100, but the standard library uses 80. However, the rustfmt.toml doesn't include a setting here; that may be something they overlooked. Additionally, I think rustfmt only reformats things that are too long, not too short. Which is maybe not ideal, but I don't think it expects people to manually wrap shorter.

@rust-lang/libs should really answer this, I think.

Without the parens, it reads as if this is a third case,

It pretty much is, though. Regardless, it being both its own paragraph and in ()s feels very strange.

@jyn514 jyn514 changed the title Slice strip Improve documentation for slice strip_* functions Sep 14, 2020
@ijackson
Copy link
Contributor Author

ijackson commented Sep 14, 2020 via email

@LukasKalbertodt
Copy link
Member

I don't mind rewrapping to 100, if that's the house style.

Yes please 😋 The doc comments wrapping in this file is a bit inconsistent unfortunately. Some are wrapped at column 80, others at 100. So either are fine, I guess.


Regarding the "number of cases" discussion: I would simply put all of the sentences in one paragraph and remove the parenthesis. Three sentences is certainly not too long for a paragraph.

@crlf0710 crlf0710 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 8, 2020
@crlf0710
Copy link
Member

crlf0710 commented Oct 8, 2020

@ijackson Ping from triage: any updates on this?

@ijackson
Copy link
Contributor Author

ijackson commented Oct 8, 2020 via email

"Some is returned with <some value>" is an awkward construction.
The use of the passive voice is a bit odd, and doesn't seem like the
house style.

So say instead "returns X, wrapped in `Some`", for which there is some
other precedent in stdlib.

Instead of repeating "with the prefix removed", say "after the
prefix".  This is a bit clearer that the original is not modified.

Signed-off-by: Ian Jackson <[email protected]>
The stabilisation issue, rust-lang#73413, has an open item for documentation.
I looked at the docs and it is all there, but I felt it could do with
some minor wording improvement.

I looked at the `str::strip_prefix` docs for a template.  (That
resulted in me slightly changing that doc too.)

I de-linkified `None` and `Some`, as I felt that rather noisy..  I
searched stdlib, and these don't seem to be usually linkified.

Signed-off-by: Ian Jackson <[email protected]>
Roughly as requested by @LukasKalbertodt.  I still prefer clearly
making these two cases.

Signed-off-by: Ian Jackson <[email protected]>
@ijackson
Copy link
Contributor Author

I have rewrapped and reorganised this now. I hope you like it better. Sorry for the delay...

@ijackson
Copy link
Contributor Author

@steveklabnik Hi, did you get a chance to look at my revised version? Thanks.

@jyn514 jyn514 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 28, 2020
@jyn514
Copy link
Member

jyn514 commented Oct 28, 2020

@ijackson FYI you can change the labels yourself with @rustbot modify labels: +S-waiting-on-review -S-waiting-on-author. Then it shows up in the review queue and the reviewer doesn't have to look at each notification to know if the PR is waiting on them.

@steveklabnik
Copy link
Member

Thank you!

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Oct 29, 2020

📌 Commit 22358c6 has been approved by steveklabnik

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 29, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 29, 2020
…as-schievink

Rollup of 11 pull requests

Successful merges:

 - rust-lang#75078 (Improve documentation for slice strip_* functions)
 - rust-lang#76138 (Explain fully qualified syntax for `Rc` and `Arc`)
 - rust-lang#78244 (Dogfood {exclusive,half-open} ranges in compiler (nfc))
 - rust-lang#78422 (Do not ICE on invalid input)
 - rust-lang#78423 (rustc_span: improve bounds checks in byte_pos_to_line_and_col)
 - rust-lang#78431 (Prefer new associated numeric consts in float error messages)
 - rust-lang#78462 (Use unwrapDIPtr because the Scope may be null.)
 - rust-lang#78493 (Update cargo)
 - rust-lang#78499 (Prevent String::retain from creating non-utf8 strings when abusing panic)
 - rust-lang#78505 (Update Clippy - temporary_cstring_as_ptr deprecation)
 - rust-lang#78527 (Fix some more typos)

Failed merges:

r? `@ghost`
@bors bors merged commit 2168210 into rust-lang:master Oct 30, 2020
@rustbot rustbot added this to the 1.49.0 milestone Oct 30, 2020
@ijackson ijackson deleted the slice-strip branch December 1, 2020 11:36
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Jan 7, 2021
Stabilize slice::strip_prefix and slice::strip_suffix

These two methods are useful.  The corresponding methods on `str` are already stable.

I believe that stablising these now would not get in the way of, in the future, extending these to take a richer pattern API a la `str`'s patterns.

Tracking PR: rust-lang#73413.  I also have an outstanding PR to improve the docs for these two functions and the corresponding ones on `str`: rust-lang#75078

I have tried to follow the [instructions in the dev guide](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr).  The part to do with `compiler/rustc_feature` did not seem applicable.  I assume that's because these are just library features, so there is no corresponding machinery in rustc.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 7, 2021
Stabilize slice::strip_prefix and slice::strip_suffix

These two methods are useful.  The corresponding methods on `str` are already stable.

I believe that stablising these now would not get in the way of, in the future, extending these to take a richer pattern API a la `str`'s patterns.

Tracking PR: rust-lang#73413.  I also have an outstanding PR to improve the docs for these two functions and the corresponding ones on `str`: rust-lang#75078

I have tried to follow the [instructions in the dev guide](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr).  The part to do with `compiler/rustc_feature` did not seem applicable.  I assume that's because these are just library features, so there is no corresponding machinery in rustc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.