Skip to content

out_of_bounds_indexing false positive #1668

Open
@leonardo-m

Description

@leonardo-m

This comes from a code reduction, so it's reasonable in its original context:

#![allow(unused_variables)]
fn main() {
    const N: usize = 1_000;
    let data = [0, 0, 0, 0];
    if N <= 4 {
        let result = data[N - 1];
    }
}
error: index out of bounds: the len is 4 but the index is 999
 --> src/main.rs:6:22
  |
6 |         let result = data[N - 1];
  |                      ^^^^^^^^^^^
  |
  = note: #[deny(const_err)] on by default

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onT-MIRType: This lint will require working with the MIRT-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions