Closed
Description
What it does
If you assert before indexing, Rust will remove the bounds checks on the indexings.
An example: https://godbolt.org/z/fczP9YTbj (correctly optimizes at opt-level=1 and higher)
Lint Name
multiple-indexing-assert-length
Category
No response
Advantage
- Improved performance
Drawbacks
No response
Example
let _ = x[0]; // bounds check here
let _ = x[1..4]; // bounds check here
Could be written as:
assert!(x.len() >= 10);
let _ = x[0]; // no bounds check here
let _ = x[1..4]; // or here