`char::EscapeDebug` displays a char it's already yielded
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
The issue points to library/core/src/escape.rs around the EscapeDebug display logic. Read how next() updates the iterator state and how Display writes printable characters, then add a regression test for consuming the character before formatting the exhausted iterator. Done when the exhausted iterator formats as an empty string while existing escaping behavior remains covered.
Written by the indexing model from the issue text.
Description
Code
I tried this code:
fn main() {
let mut e = 'a'.escape_debug();
assert_eq!(e.next(), Some('a'));
assert_eq!(e.len(), 0);
println!("{:?}", e.to_string());
}
I expected to see this happen: "" (the iterator is exhausted).
Instead, this happened: "a"
scope:
- It only affects chars that
char::escape_debugprints as-is (e.g. 'a', 'é'). Escaped characters like\nwork correctly str::escape_debugworks correctly. For example, callingnext()on"a".escape_debug()correctly exhausts the iterator
cause:
- I think this came from #138237
- Before,
EscabeDebug::nextcalledclear()after yielding a printable char - Now, the char is stored in
EscapeIterInner, andnext()only advancesalive.start.alive.endstill marks the char as present, soDisplaywrites it again.
how i found this:
- I found this while writing Kani proofs for
core::escapeas part of verify-rust-std
proposed fix:
- return f.write_char(c);
+ return if self.alive.is_empty() { Ok(()) } else { f.write_char(c) };
Version it worked on
It most recently worked on: 1.88.0
Version with regression
rustc --version --verbose: 1.89.0
rustc 1.89.0 (29483883e 2025-08-04)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: aarch64-apple-darwin
release: 1.89.0
LLVM version: 20.1.7
@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged
- Dominant language
- Rust
- Stars
- 121k
- Forks
- 17.3k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 534
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-lang/rust
-
A-run-make relnotes relnotes-needs-review relnotes-tracking-issue T-lang T-libs
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-libs
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
A-LLVM O-Arm O-UEFI O-x86_64 relnotes relnotes-needs-review relnotes-tracking-issue T-compiler
Difficulty 1/5 Under an hour Newbie friendliness 72/100
rust-lang/rust#165504 · 1 comment ·
Maintainers usually reply within 1 day
-
relnotes relnotes-tracking-issue T-libs
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
unclear wording in vec macroPossibly taken @Suhird claimed this 4 days ago. OpenA-docs A-slice-vec T-libs
Difficulty 1/5 1-3 hours Newbie friendliness 70/100
rust-lang/rust#165360 · 6 comments · 1 assignee ·
Maintainers usually reply within 1 day
Similar issues
-
crate: spate-kafka documentation priority: medium
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
balovess/aria2_rust#88 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
agent-self
Difficulty 1/5 Under an hour Newbie friendliness 88/100
yologdev/yoyo-evolve#1154 ·