Index out of bounds panic should show line number + filename from our source code to be more helpful

Right now if I use a function with an index exception such as Vec's spilt_off() function, I will receive an error that would leave me searching around my code for the error.

thread 'main' panicked at 'at split index (is 4) should be <= len (is 3)', library/alloc/src/vec/

It would be much more ergonomic to point to the specific line within the calling code of my source code for this potentially error.

1 Like

There's a proposal to make many of Vec's functions do exactly that, at Add #[track_caller] to panicking Vec functions by Dylan-DPC · Pull Request #83359 · rust-lang/rust · GitHub . That proposal is currently being evaluated to make sure it doesn't have an excessive performance impact.