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 09, Part 1, outdated panic explanation #2708

Closed
Oxygels opened this issue Apr 25, 2021 · 1 comment
Closed

Chapter 09, Part 1, outdated panic explanation #2708

Oxygels opened this issue Apr 25, 2021 · 1 comment

Comments

@Oxygels
Copy link

Oxygels commented Apr 25, 2021

In chapter 09-1, available here:
https://doc.rust-lang.org/book/ch09-01-unrecoverable-errors-with-panic.html

An explanation of the panic seems outdated.
The book refers to an error in a source file in core (here slice/mod.rs) but the error message instead refers to the caller (which is the indexing operation) in main.

The panic :

$ cargo run
   Compiling panic v0.1.0 (file:///projects/panic)
    Finished dev [unoptimized + debuginfo] target(s) in 0.27s
     Running `target/debug/panic`
thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 99', src/main.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The explanation:

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. The code that gets run when we use [] on our vector v is in libcore/slice/mod.rs, and that is where the panic! is actually happening.

I assume this is due to the introduction of #[track_caller].

@carols10cents
Copy link
Member

Thanks! This is a duplicate of #2550, which was fixed in 2250f51.

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

2 participants