Skip to content

Compile time bounds checking doesn't work anymore for passed array references #114840

Closed as not planned
@bluec0re

Description

@bluec0re

Code

I tried this code:

fn bar(a: &mut [usize; 5]) {
    a[5] = 7;
}

pub fn main() {
    let mut a = [0usize; 5];
    bar(&mut a);
}

I expected to see this happen (as it did with 1.60):

error: this operation will panic at runtime
 --> <source>:2:5
  |
2 |     a[5] = 7;
  |     ^^^^ index out of bounds: the length is 5 but the index is 5
  |
  = note: `#[deny(unconditional_panic)]` on by default

Instead, this happened:

Compiles and than fails at runtime

thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 5', /app/example.rs:2:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Version it worked on

It most recently worked on: 1.60

Version with regression

1.61 onwards

Looks similar to this older bug report: #98444

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions