Stop including string content in index panics?
Rust Internals [Unofficial]
March 13, 2026
ais523:
Most commonly this includes terminal control characters like U+001B and U+009B, and Rust appears to print those both literally at present when a string operation produces a panic.
This is an interesting point. As a consequence, I’d pose it may be a good idea for the string to be Debug-printed (i.e. escaped) – rather than Display-printed as currently seems to be the case – thus behaving similar to e.q. what a failed assert_eq!("ab\u{1b}c\n\n\nd\u{9b}ef", "something else") would do (it also uses the Debug-printed representation of the string).
Discussion in the ATmosphere