Skip to content

std: make OsString::truncate a no-op when len > current_len#152998

Open
xtqqczze wants to merge 1 commit intorust-lang:mainfrom
xtqqczze:panic-truncate
Open

std: make OsString::truncate a no-op when len > current_len#152998
xtqqczze wants to merge 1 commit intorust-lang:mainfrom
xtqqczze:panic-truncate

Conversation

@xtqqczze
Copy link
Contributor

@xtqqczze xtqqczze commented Feb 23, 2026

Align OsString::truncate (and the underlying WTF-8 implementation) with String::truncate by making it a no-op when len > self.len().

Previously, OsString::truncate would panic if len > self.len(), while String::truncate treats such cases as a no-op.

Tracking (os_string_truncate): #133262
See also: #32977

cc: @alexcrichton, @lolbinarycat

@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 Feb 23, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 23, 2026

r? @jhpratt

rustbot has assigned @jhpratt.
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, jhpratt, joboet

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@xtqqczze xtqqczze marked this pull request as draft February 23, 2026 11:16
@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 Feb 23, 2026
@xtqqczze xtqqczze marked this pull request as ready for review February 23, 2026 13:25
@rustbot rustbot 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 Feb 23, 2026
@xtqqczze xtqqczze changed the title std: make OsString::truncate a no-op when len >= current_len std: make OsString::truncate a no-op when len > current_len Feb 27, 2026
Align `OsString::truncate` (and the underlying WTF-8 implementation) with `String::truncate` by making it a no-op when `len > self.len()`.

Previously, `OsString::truncate` would panic if `len > self.len()`, while `String::truncate` treats such cases as a no-op.
@jhpratt
Copy link
Member

jhpratt commented Mar 1, 2026

This seems reasonable, but has it been discussed anywhere?

@lolbinarycat
Copy link
Contributor

I don't think it was discussed anywhere to my knowledge, maybe in the original implementation PR?

Parity seems like a good idea, but should we ask t-libs-api for confirmation?

@jhpratt
Copy link
Member

jhpratt commented Mar 4, 2026

cc @rust-lang/libs-api; given that it's unstable I'm not sure what procedure is here.

@asder8215
Copy link
Contributor

Parity seems like a good idea, but should we ask t-libs-api for confirmation?

Yea, I would defer this to lib-api to make the call.

Copy link
Member

@Amanieu Amanieu left a comment

Choose a reason for hiding this comment

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

This is reasonable and makes it consistent with every other truncate method in the standard library.

View changes since this review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants