Closed
Description
I tried this code:
fn test(a: &[&[u8]]) -> u32 {
a
.iter()
.enumerate()
.map(|(y, b)| {
b.iter()
.enumerate()
.filter(|(_, c)| **c == b'A')
.map(|(x, _)| {
a[y][x] as u32
})
.sum::<u32>()
})
.sum()
}
I expected to see this happen: bounds checks are optimized out
Instead, this happened: bounds checks are not optimized out
https://godbolt.org/z/jsxvaeez7
Meta
rustc --version --verbose
:
rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1
Additional info
- This occurs from rust versions 1.56.0 to current nightly.
- Consistently utilizing either
a[y]
orb
(not both as seen above) removes the produced bounds checks. - Removing the
filter
also removes the bounds checks.