Skip to content

Implement OsStr::split_at#156444

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
ChrisDenton:os_str_split_at
May 18, 2026
Merged

Implement OsStr::split_at#156444
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
ChrisDenton:os_str_split_at

Conversation

@ChrisDenton

@ChrisDenton ChrisDenton commented May 11, 2026

Copy link
Copy Markdown
Member

See #156199

This allows splitting only on valid UTF-8 boundaries, regardless of the platform, which avoids cross-platform landmines.

@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 May 11, 2026
@rustbot

rustbot commented May 11, 2026

Copy link
Copy Markdown
Collaborator

r? @nia-e

rustbot has assigned @nia-e.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, nia-e

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@nia-e nia-e left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few small points of style, but looks good. Personally I'm not opposed to having platform-specific behaviour - it is called OsStr{ing} after all - but that's a libs-api question ultimately

View changes since this review

Comment thread library/std/src/ffi/os_str.rs Outdated
Comment thread library/std/src/ffi/os_str.rs Outdated
/// A valid `OsStr` boundary is one of:
/// - The start of the string
/// - The end of the string
/// - Immediately before a valid non-empty UTF-8 substring

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we also document that splitting is possible if the substrings aren't valid as long as the bytes at the split are (the test at tests.rs#347)?

@ChrisDenton ChrisDenton May 14, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm, that was what I was trying to get across by talking about "before" and "after" mid. But I can try to rephrase it. Something like:

Suggested change
/// - Immediately before a valid non-empty UTF-8 substring
/// - the start of a valid non-empty UTF-8 substring
/// - immediately follows a valid non-empty UTF-8 substring

Comment thread library/std/src/sys/os_str/bytes.rs
/// The argument, `mid`, should be a valid byte offset from the start of the string.
/// It must also be on a valid `OsStr` boundary.
/// The method returns `None` if that’s not the case.
/// A valid `OsStr` boundary is one of:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd rather we point to the docs of split_at or vice-versa, so these don't risk being out of sync

Comment thread library/std/src/ffi/os_str.rs Outdated
Comment thread library/std/src/ffi/os_str.rs Outdated
@rustbot rustbot 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 May 12, 2026
@nia-e

nia-e commented May 12, 2026

Copy link
Copy Markdown
Member

r=me if nothing more comes up

@ChrisDenton

Copy link
Copy Markdown
Member Author

@bors r=nia-e

@rust-bors

rust-bors Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 921b35b has been approved by nia-e

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 18, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 18, 2026
Implement `OsStr::split_at`

See rust-lang#156199

This allows splitting only on valid UTF-8 boundaries, regardless of the platform, which avoids cross-platform landmines.
rust-bors Bot pushed a commit that referenced this pull request May 18, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #156444 (Implement `OsStr::split_at`)
 - #156661 (Remove `UncheckedIterator`)
 - #156606 (Add pext/pdep as aliases for extract_bits/deposit_bits)
 - #156653 (Update `sysinfo` version to `0.39.2`)
rust-bors Bot pushed a commit that referenced this pull request May 18, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #156709 (stdarch subtree update)
 - #155006 (stabilize `feature(cfg_target_has_atomic_equal_alignment)`)
 - #156444 (Implement `OsStr::split_at`)
 - #156582 (Allow `global_asm!` in statement positions)
 - #156661 (Remove `UncheckedIterator`)
 - #152367 (Derives `Copy` for `ffi::FromBytesUntilNulError`)
 - #156443 (Fix invalid suggestion for parenthesized break)
 - #156606 (Add pext/pdep as aliases for extract_bits/deposit_bits)
 - #156630 (Replace `println!` with `assert!` in HashMap documentation examples)
 - #156644 (Widen the result of `widening_mul`.)
 - #156653 (Update `sysinfo` version to `0.39.2`)
 - #156697 (Add diagnostic items for IoBufReader and StdinLock)
 - #156704 (reduce usage of `box_patterns` in tests)
@rust-bors rust-bors Bot merged commit a6138ec into rust-lang:main May 18, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone May 18, 2026
rust-timer added a commit that referenced this pull request May 18, 2026
Rollup merge of #156444 - ChrisDenton:os_str_split_at, r=nia-e

Implement `OsStr::split_at`

See #156199

This allows splitting only on valid UTF-8 boundaries, regardless of the platform, which avoids cross-platform landmines.
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Jun 8, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#156709 (stdarch subtree update)
 - rust-lang/rust#155006 (stabilize `feature(cfg_target_has_atomic_equal_alignment)`)
 - rust-lang/rust#156444 (Implement `OsStr::split_at`)
 - rust-lang/rust#156582 (Allow `global_asm!` in statement positions)
 - rust-lang/rust#156661 (Remove `UncheckedIterator`)
 - rust-lang/rust#152367 (Derives `Copy` for `ffi::FromBytesUntilNulError`)
 - rust-lang/rust#156443 (Fix invalid suggestion for parenthesized break)
 - rust-lang/rust#156606 (Add pext/pdep as aliases for extract_bits/deposit_bits)
 - rust-lang/rust#156630 (Replace `println!` with `assert!` in HashMap documentation examples)
 - rust-lang/rust#156644 (Widen the result of `widening_mul`.)
 - rust-lang/rust#156653 (Update `sysinfo` version to `0.39.2`)
 - rust-lang/rust#156697 (Add diagnostic items for IoBufReader and StdinLock)
 - rust-lang/rust#156704 (reduce usage of `box_patterns` in tests)
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.

4 participants