Skip to content

ch 3.2 invalid-array-element-access example error #1764

@j16sdiz

Description

@j16sdiz

In the book ch 3.2 https://doc.rust-lang.org/book/ch03-02-data-types.html#invalid-array-element-access, there is an example:

fn main() {
    let a = [1, 2, 3, 4, 5];
    let index = 10;

    let element = a[index];

    println!("The value of element is: {}", element);
}

The error reads 'index out of bounds:.....src/main.rs:6.
It is unclear why the error is on line 6, because line 6 is empty. I think the compiler message need a fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions