Skip to content

unconditional_panic array bounds check doesn't work through Deref #109260

Closed
@e2-71828

Description

@e2-71828

(Initially reported on URLO)

In the following program:

fn main() {
    let mut arr_0: [u32; 10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

    let ptr_0 = Box::new(arr_0);

    let ptr_v = ptr_0[11];
    let arr_v = arr_0[11];
    println!("v:{}", ptr_v);
}

The out-of-bounds access of ptr_0[11] is not flagged at compile time, but the similar access of arr_0[11] is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-unconditional_panicLint: unconditional_panicS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions