rust-lang / rust-lang/rust

`is_char_boundary` not elided when impl `pop` in terms of `truncate`

Open
#139,655 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-optimization I-slow T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I've implemented String::pop by using String::truncate internally. The UTF-8 boundary assertion check is still included in the release binary (for x86 targets). I can reproduce the lack of optimization on both 1.88.0-nightly (2025-04-07 e643f59f6da3a84f43e7) and stable (1.86.0)

Playground

I haven't tested if both functions are semantically-identical, but I've read the source-code (and docs) of both pop and truncate, so I am confident that pop_trunc is correct

@rustbot label: +I-slow

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing String::pop and String::truncate, then reproduce the release build with the linked Playground on an x86 target. Investigate why the UTF-8 boundary assertion remains in the generated binary; done means explaining the optimization difference and verifying that the assertion is eliminated without changing the semantics of either method.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.