add note to lines docs about empty str behavior#148912
Merged
bors merged 2 commits intorust-lang:mainfrom Nov 17, 2025
Merged
Conversation
Collaborator
Kivooeo
reviewed
Nov 13, 2025
library/core/src/str/mod.rs
Outdated
| /// ending will return the same lines as an otherwise identical string | ||
| /// without a final line ending. | ||
| /// | ||
| /// An empty string returns no lines. |
Member
There was a problem hiding this comment.
imho, "no lines" feels not obvious what does that mean, like, would it be better to have wording like "returns None"?
Contributor
Author
There was a problem hiding this comment.
Hmm, I think that might be a bit confusing since the method itself returns a Lines object instead of an Option and saying "returns None" makes it sound like it returns an Option. A few possible alternatives:
- "An empty string returns an empty iterator"
- "Returns an empty iterator when called on an empty string"
- "Empty strings produce no lines"
Member
There was a problem hiding this comment.
Ah, sure it's an iterator
Empty iterator instead None then, should be clear enough
Member
|
Sounds good -- agreed this is really useful to have as an explicit @bors r+ rollup |
Collaborator
JaclynCodes
added a commit
to JaclynCodes/rust
that referenced
this pull request
Nov 17, 2025
add note to `lines` docs about empty str behavior This pull request adds a short note to the documentation for `str::lines` that describes the behavior of the resulting iterator when called on an empty string. I tripped over this a few days ago because I thought (incorrectly) that the iterator would return a single line with an empty string. I don't doubt that the actual behavior (return no lines) is the correct behavior, but in the absence of explicit documentation describing it, I came to the wrong conclusion about it and maybe others will too. If this is so obvious as to be not worth including, I'm happy to withdraw the pull request! Thanks for taking a look.
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Nov 17, 2025
add note to `lines` docs about empty str behavior This pull request adds a short note to the documentation for `str::lines` that describes the behavior of the resulting iterator when called on an empty string. I tripped over this a few days ago because I thought (incorrectly) that the iterator would return a single line with an empty string. I don't doubt that the actual behavior (return no lines) is the correct behavior, but in the absence of explicit documentation describing it, I came to the wrong conclusion about it and maybe others will too. If this is so obvious as to be not worth including, I'm happy to withdraw the pull request! Thanks for taking a look.
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Nov 17, 2025
add note to `lines` docs about empty str behavior This pull request adds a short note to the documentation for `str::lines` that describes the behavior of the resulting iterator when called on an empty string. I tripped over this a few days ago because I thought (incorrectly) that the iterator would return a single line with an empty string. I don't doubt that the actual behavior (return no lines) is the correct behavior, but in the absence of explicit documentation describing it, I came to the wrong conclusion about it and maybe others will too. If this is so obvious as to be not worth including, I'm happy to withdraw the pull request! Thanks for taking a look.
bors
added a commit
that referenced
this pull request
Nov 17, 2025
Rollup of 11 pull requests Successful merges: - #148505 (add larger test for `proc_macro` `FromStr` implementations) - #148752 (Constify `ManuallyDrop::take`) - #148757 (Constify `mem::take`) - #148855 (Error if an autodiff user does not set lto=fat) - #148912 (add note to `lines` docs about empty str behavior) - #148958 (Run codegen tests on a 32-bit target in PR CI) - #148994 (Abi compatibility test cleanup) - #148999 (Tweak Motor OS linker preset, fix `remote-test-server` for Motor OS) - #149004 (compiletest: Avoid race condition in file deletion) - #149008 (triagebot: remove jsha from notifications for rustdoc HTML) - #149010 (compiletest: Remove the "wasm32-bare" alias for `wasm32-unknown-unknown`) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
that referenced
this pull request
Nov 17, 2025
Rollup merge of #148912 - msmoiz:main, r=scottmcm add note to `lines` docs about empty str behavior This pull request adds a short note to the documentation for `str::lines` that describes the behavior of the resulting iterator when called on an empty string. I tripped over this a few days ago because I thought (incorrectly) that the iterator would return a single line with an empty string. I don't doubt that the actual behavior (return no lines) is the correct behavior, but in the absence of explicit documentation describing it, I came to the wrong conclusion about it and maybe others will too. If this is so obvious as to be not worth including, I'm happy to withdraw the pull request! Thanks for taking a look.
github-actions bot
pushed a commit
to rust-lang/rustc-dev-guide
that referenced
this pull request
Nov 17, 2025
Rollup of 11 pull requests Successful merges: - rust-lang/rust#148505 (add larger test for `proc_macro` `FromStr` implementations) - rust-lang/rust#148752 (Constify `ManuallyDrop::take`) - rust-lang/rust#148757 (Constify `mem::take`) - rust-lang/rust#148855 (Error if an autodiff user does not set lto=fat) - rust-lang/rust#148912 (add note to `lines` docs about empty str behavior) - rust-lang/rust#148958 (Run codegen tests on a 32-bit target in PR CI) - rust-lang/rust#148994 (Abi compatibility test cleanup) - rust-lang/rust#148999 (Tweak Motor OS linker preset, fix `remote-test-server` for Motor OS) - rust-lang/rust#149004 (compiletest: Avoid race condition in file deletion) - rust-lang/rust#149008 (triagebot: remove jsha from notifications for rustdoc HTML) - rust-lang/rust#149010 (compiletest: Remove the "wasm32-bare" alias for `wasm32-unknown-unknown`) r? `@ghost` `@rustbot` modify labels: rollup
github-actions bot
pushed a commit
to model-checking/verify-rust-std
that referenced
this pull request
Nov 30, 2025
add note to `lines` docs about empty str behavior This pull request adds a short note to the documentation for `str::lines` that describes the behavior of the resulting iterator when called on an empty string. I tripped over this a few days ago because I thought (incorrectly) that the iterator would return a single line with an empty string. I don't doubt that the actual behavior (return no lines) is the correct behavior, but in the absence of explicit documentation describing it, I came to the wrong conclusion about it and maybe others will too. If this is so obvious as to be not worth including, I'm happy to withdraw the pull request! Thanks for taking a look.
github-actions bot
pushed a commit
to model-checking/verify-rust-std
that referenced
this pull request
Nov 30, 2025
Rollup of 11 pull requests Successful merges: - rust-lang#148505 (add larger test for `proc_macro` `FromStr` implementations) - rust-lang#148752 (Constify `ManuallyDrop::take`) - rust-lang#148757 (Constify `mem::take`) - rust-lang#148855 (Error if an autodiff user does not set lto=fat) - rust-lang#148912 (add note to `lines` docs about empty str behavior) - rust-lang#148958 (Run codegen tests on a 32-bit target in PR CI) - rust-lang#148994 (Abi compatibility test cleanup) - rust-lang#148999 (Tweak Motor OS linker preset, fix `remote-test-server` for Motor OS) - rust-lang#149004 (compiletest: Avoid race condition in file deletion) - rust-lang#149008 (triagebot: remove jsha from notifications for rustdoc HTML) - rust-lang#149010 (compiletest: Remove the "wasm32-bare" alias for `wasm32-unknown-unknown`) r? `@ghost` `@rustbot` modify labels: rollup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds a short note to the documentation for
str::linesthat describes the behavior of the resulting iterator when called on an empty string. I tripped over this a few days ago because I thought (incorrectly) that the iterator would return a single line with an empty string. I don't doubt that the actual behavior (return no lines) is the correct behavior, but in the absence of explicit documentation describing it, I came to the wrong conclusion about it and maybe others will too. If this is so obvious as to be not worth including, I'm happy to withdraw the pull request! Thanks for taking a look.