Skip to content

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

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
xtqqczze:panic-truncate
Mar 18, 2026
Merged

std: make OsString::truncate a no-op when len > current_len#152998
rust-bors[bot] merged 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

@jhpratt
Copy link
Member

jhpratt commented Mar 17, 2026

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 17, 2026

📌 Commit 3ecd18c has been approved by jhpratt

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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 17, 2026
@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Mar 17, 2026
std: make `OsString::truncate` a no-op when `len > current_len`

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
@rust-bors rust-bors bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 17, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 17, 2026

💔 Test for 57a5ee9 failed: CI. Failed job:

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-debug failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[1906/5488] Building CXX object lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LiveRangeCalc.cpp.o
[1907/5488] Building CXX object lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LiveIntervalCalc.cpp.o
[1908/5488] Building CXX object lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LiveRangeEdit.cpp.o

Session terminated, killing shell...::group::Clock drift check
##[error]The runner has received a shutdown signal. This can happen when the runner service is stopped, or a manually started runner is canceled.
  local time: Tue Mar 17 10:48:06 UTC 2026
  network time: [1909/5488] Building CXX object lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LiveRangeShrink.cpp.o
[1910/5488] Building CXX object lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LiveRegMatrix.cpp.o
[1911/5488] Building CXX object lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LiveRegUnits.cpp.o
Tue, 17 Mar 2026 10:48:06 GMT

@JonathanBrouwer
Copy link
Contributor

@bors retry
Spurious

@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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 17, 2026
rust-bors bot pushed a commit that referenced this pull request Mar 17, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #152998 (std: make `OsString::truncate` a no-op when `len > current_len`)
 - #153682 (Tweak E0599 note)
 - #153795 (Point turbofish inference errors at the uninferred generic arg)
 - #153994 (move `tests/ui/invalid` tests to new folders)
 - #154006 (attrs: Ignore ExprKind::Err when converting path attr expr to lit)
 - #154012 (unstable impl of `From<{i64, u64}> for f128`)
@rust-bors rust-bors bot merged commit b1050a7 into rust-lang:main Mar 18, 2026
11 of 12 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 18, 2026
@xtqqczze xtqqczze deleted the panic-truncate branch March 18, 2026 02:42
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.

8 participants