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

Chapter 9.1: Using a panic! Backtrace. Code in listing 9-1 is wrong/outdated. #2550

Closed
ExpressGradient opened this issue Dec 29, 2020 · 3 comments

Comments

@ExpressGradient
Copy link

There's this code snippet in this section which is an attempt to access an element of a vector using an invalid index.

fn main() {
    let v = vec![1, 2, 3];
    
    v[99];
}

The explanation says, "This error points at a file we didn't write, libcore/slice/mod.rs. That's the implementation of slice in the Rust source code."

But when I run the listing in the browser and also on my local machine, the error points directly at the line where v[99]; is there, thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 99', src/main.rs:4:5, to be precise.

According to the community discord server, the reason for this behavior was, slice was not included in the scope in prelude at the time of writing that part in the book.

@shepmaster
Copy link
Member

I don't believe the previous rationale is correct; my guess is that this is due to rust-lang/rust#47809

@ExpressGradient
Copy link
Author

ahh makes sense.
But anyhow, the panic message should be updated accordingly then.

@carols10cents
Copy link
Member

Thanks, fixed!

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

No branches or pull requests

3 participants