Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
j16sdiz opened this issue Jan 12, 2019 · 1 comment
Closed

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

j16sdiz opened this issue Jan 12, 2019 · 1 comment
Labels

Comments

@j16sdiz
Copy link

j16sdiz commented Jan 12, 2019

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.

@chrisbirster
Copy link

I have version rustc below:
rustc 1.33.0 (2aa4c46cf 2019-02-28)

I reran the example above and got the following error:

thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 10', src/main.rs:5:19
note: Run with RUST_BACKTRACE=1 environment variable to display a backtrace

I think this is fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants