You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if this is the right place or labels for this and didn't find any specific format for errors in "The book", but hope someone can direct me if needed. I'm new to rust completely but excited to learn and contribute where I can.
In "The book" chapter 3 section two, towards the end of the section (https://doc.rust-lang.org/book/ch03-02-data-types.html#invalid-array-element-access), it claims that a certain code snippet will compile fine, but panic at runtime, but the code snippet actually doesn't compile. I imagine it's important to mention that panicking happens at runtime with similar conditions that aren't catchable at compile-time, but it's inaccurate. Here's the error that I get.
$ cargo run
Compiling book_error v0.1.0 (D:\DDocuments\PersonalProjects\LearningRust\book_error)
error: this operation will panic at runtime
--> src\main.rs:5:19
|
5 | let element = a[index];
| ^^^^^^^^ index out of bounds: the len is 5 but the index is 10
|
= note: `#[deny(unconditional_panic)]` on by default
error: aborting due to previous error
error: could not compile `book_error`.
To learn more, run the command again with --verbose.
Here's the error mentioned in the book:
$ cargo run
Compiling arrays v0.1.0 (file:///projects/arrays)
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
Running `target/debug/arrays`
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.
The text was updated successfully, but these errors were encountered:
csmoe
added
the
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
label
Aug 23, 2020
Rust got smarter constant evaluation since that was written it seems. The following doesn't fail to compile but errors at runtime:
fnget_index() -> usize{10}fnmain(){let a = [1,2,3,4,5];let index = get_index();let element = a[index];println!("The value of element is: {}", element);}
It does make the example a tiny bit worse, but showcases the point.
I'm not sure if this is the right place or labels for this and didn't find any specific format for errors in "The book", but hope someone can direct me if needed. I'm new to rust completely but excited to learn and contribute where I can.
In "The book" chapter 3 section two, towards the end of the section (https://doc.rust-lang.org/book/ch03-02-data-types.html#invalid-array-element-access), it claims that a certain code snippet will compile fine, but panic at runtime, but the code snippet actually doesn't compile. I imagine it's important to mention that panicking happens at runtime with similar conditions that aren't catchable at compile-time, but it's inaccurate. Here's the error that I get.
Here's the error mentioned in the book:
The text was updated successfully, but these errors were encountered: