Out Of Bound compile error with .len() function call

I think that might be worth opening an issue to fix the lint (not sure how difficult that is though). I believe that taking a shared reference should have no impact here.

Edit: Done, see my post below.


See also Issue #90534. I added your example as a comment to that issue.

I opened a new issue #98444 with the following example code:

fn main() {
    let xs: [i32; 5] = [1, 2, 3, 4, 5];
    let _ = &xs; // this line suppresses the `unconditional_panic` lint
    let _ = xs[7];

This lint is emitted by the const propagation pass I believe. This pass forgets about the value of locals when a reference is taken.

Thank you for taking an action!
Glad I can help.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.