-
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
Improve documentation for slice strip_* functions #75078
Conversation
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. |
r? @rust-lang/docs |
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.
Seems fine, but I have a few questions :)
library/core/src/str/mod.rs
Outdated
/// 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 |
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.
these lines are wrapped much, much shorter than the old ones were. What column did you wrap these to?
library/core/src/slice/mod.rs
Outdated
/// | ||
/// If the slice does not start with `prefix`, returns `None`. | ||
/// | ||
/// (If `prefix` is empty, simply returns the original 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.
No need for parenthesis around these.
Steve Klabnik writes ("Re: [rust-lang/rust] Slice strip (#75078)"):
Seems fine, but I have a few questions :)
Thanks for the review.
these lines are wrapped much, much shorter than the old ones were. What column
did you wrap these to?
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.
+ /// (If `prefix` is empty, simply returns the original slice.)
No need for parenthesis around these.
Without the parens, it reads as if this is a third case, "If X... .
If Y ... . If Z ...". If read as a third case, it's confusing
because it makes the cases not mutually exclusive, and because it
omits the fully formal language mentioning `Some`.
As a parenthetical comment it's much less susceptible to that
misreading. The parens also hint that maybe the reader can skip this
part.
I considered removing it entirely but that felt too austere. Perhaps
there is some other way to indicate its status. Prefixing it with
"Therefore;" or "Note:" or something maybe.
Thanks,
Ian.
…--
Ian Jackson <[email protected]> These opinions are my own.
Pronouns: they/he. If I emailed you from @fyvzl.net or @evade.org.uk,
that is a private address which bypasses my fierce spamfilter.
|
Ping from triage: @steveklabnik could you provide feedback/guidance about the last comment? Thanks in advance! |
r? @jyn514 for reviewing documentation improvement for unstable slice methods: |
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?)
Maybe make it a doc-test instead of a parenthetical? Then it will be tested, too. |
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.
It pretty much is, though. Regardless, it being both its own paragraph and in |
Steve Klabnik writes ("Re: [rust-lang/rust] Slice strip (#75078)"):
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.
I don't mind rewrapping to 100, if that's the house style. Unless I
hear otherwise I will do that.
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.
I'm afraid I must definitely disagree. It is not a third case: it is
a subset of the first case. The empty slice can be found at the start
of any slice and removing it leaves the original input. Treating
this as a separate case is confusing because it suggests to the reader
that they must have misunderstood the first case.
I will see if I can find a way to different way to write it that may
suit you better but also avoid what I see as confusing or awkward
phrases.
Thanks,
Ian.
…--
Ian Jackson <[email protected]> These opinions are my own.
Pronouns: they/he. If I emailed you from @fyvzl.net or @evade.org.uk,
that is a private address which bypasses my fierce spamfilter.
|
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. |
@ijackson Ping from triage: any updates on this? |
Charles Lew writes ("Re: [rust-lang/rust] Improve documentation for slice strip_* functions (#75078)"):
@ijackson Ping from triage: any updates on this?
Hi. Sorry, yes, this is still on my radar but I haven't got round to
it. Possibly at the weekend.
…--
Ian Jackson <[email protected]> These opinions are my own.
Pronouns: they/he. If I emailed you from @fyvzl.net or @evade.org.uk,
that is a private address which bypasses my fierce spamfilter.
|
"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]>
Requested-by: @LukasKalbertodt Signed-off-by: Ian Jackson <[email protected]>
Requested-by: @LukasKalbertodt 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]>
I have rewrapped and reorganised this now. I hope you like it better. Sorry for the delay... |
@steveklabnik Hi, did you get a chance to look at my revised version? Thanks. |
@ijackson FYI you can change the labels yourself with |
Thank you! @bors: r+ rollup |
📌 Commit 22358c6 has been approved by |
…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`
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.
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.
Prompted by the stabilisation tracking issue #73413 I looked at the docs for
strip_prefix
andstrip_suffix
for bothstr
andslice
, and I felt they could be slightly improved.Thanks for your attention.