External Publication
Visit Post

Stop including string content in index panics?

Rust Internals [Unofficial] March 10, 2026
Source

I assume this is about not wanting to handle PI? Couldn't your crash reporter filter this out on the client side with a regex, at least as a stop-gap solution?

We definitely can, but I'm a bit reluctant to as a permanent solution in case someone (like me) messes with the panic messages more.

Echoing the whole string seems clearly wrong and unnecessary, so at least this one I think we should just do. Maybe make a PR for that part and we can nominate for libs/libs-api discussion? (Feel free to r? @scottmcm.)

It's currently limited to 256 bytes; reducing the size would help (but it'd be better to get rid of it I think). For the range being backward, it's nothing to do with the string content.

The single USV , however, does seem particularly useful as friendliness to the developer, especially the new developer not yet used to how rust does indexing, so I'd be more reticent to remove the "inside 'ã'" part. (Removing the "of ãchoo" part seems obvious, like the previous case.)

That seems like a reasonable compromise to me too.

So I think that would leave us with the following panic strings:

  • "byte index {} is out of bounds for string of length {}"
  • "byte range starts at {} but ends at {}"
  • "byte index {} inside multibyte character {:?} (bytes {}..{} of string)"

The first one is the main one where I think there's (maybe?) value in outputting the string content; but this does mirror what we do for slices already, so maybe it's OK to avoid it there too.

I'll send a PR and we can discuss more the trade-offs there

Discussion in the ATmosphere

Loading comments...