3 ms·
I believe the compiler can't do that, since the bounds check panic is a side effect that can be observed - the message tells which index that failed the check!
by kzrdude 7y ago
I believe the compiler can't do that, since the bounds check panic is a side effect that can be observed - the message tells which index that failed the check! For that reason, non-elided checks will not be reordered.
However, I believe a future Rust RFC could turn that around and validate the idea that in some cases such things could change execution order, even if it has noticeable side effects.
(No idea if it's technically feasible!)