]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #74510 - LukasKalbertodt:fix-range-from-index-panic, r=hanna-kruppe
authorbors <bors@rust-lang.org>
Sat, 25 Jul 2020 16:27:24 +0000 (16:27 +0000)
committerbors <bors@rust-lang.org>
Sat, 25 Jul 2020 16:27:24 +0000 (16:27 +0000)
Fix panic message when `RangeFrom` index is out of bounds

Before, the `Range` method was called with `end = slice.len()`. Unfortunately, because `Range::index` first checks the order of the indices (start has to be smaller than end), an out of bounds index leads to `core::slice::slice_index_order_fail` being called. This prints the message 'slice index starts at 27 but ends at 10', which is worse than 'index 27 out of range for slice of length 10'. This is not only useful to normal users reading panic messages, but also for people inspecting assembly and being confused by `slice_index_order_fail` calls.

You can see the produced assembly [here](https://rust.godbolt.org/z/GzMGWf) and try on Playground [here](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=aada5996b2f3848075a6d02cf4055743). (By the way. this is only about which panic function is called; I'm pretty sure it does not improve anything about performance).

1  2 
src/libcore/slice/mod.rs

Simple merge