Skip to content

Conversation

@msmoiz
Copy link
Contributor

@msmoiz msmoiz commented Nov 13, 2025

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.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 13, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 13, 2025

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

/// ending will return the same lines as an otherwise identical string
/// without a final line ending.
///
/// An empty string returns no lines.
Copy link
Member

Choose a reason for hiding this comment

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

imho, "no lines" feels not obvious what does that mean, like, would it be better to have wording like "returns 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.

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"

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sure it's an iterator

Empty iterator instead None then, should be clear enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay cool, updated

@scottmcm
Copy link
Member

Sounds good -- agreed this is really useful to have as an explicit # Example.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 17, 2025

📌 Commit e628b05 has been approved by scottmcm

It is now in the queue for this repository.

@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 Nov 17, 2025
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
@bors bors merged commit 47585c9 into rust-lang:main Nov 17, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 17, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants