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

ch03-02-data-types - mistaken description of the code snippet #2654

Closed
MaksimDanilau opened this issue Mar 18, 2021 · 2 comments
Closed

ch03-02-data-types - mistaken description of the code snippet #2654

MaksimDanilau opened this issue Mar 18, 2021 · 2 comments

Comments

@MaksimDanilau
Copy link

In the Invalid Array Element Access section there is a phrase:

The compilation didn’t produce any errors, but the program resulted in a runtime error and didn’t exit successfully.

But according to the code snippet above in the book exactly compiling stage is producing the error.

Also, I've tried to run the build locally.

❯ cargo build
   Compiling variables v0.1.0 (/Users/maksim/Projects/Rust/variables)
error: this operation will panic at runtime
 --> src/main.rs:8:5
  |
8 |     a[10];
  |     ^^^^^ index out of bounds: the length is 3 but the index is 10
  |
  = note: `#[deny(unconditional_panic)]` on by default

error: aborting due to previous error

error: could not compile `variables`

To learn more, run the command again with --verbose.

Is there a mistake in the book? Is it my misunderstanding?

@MaksimDanilau MaksimDanilau changed the title ch03-02-data-types ch03-02-data-types - mistaken description of the code snippet Mar 18, 2021
@carols10cents
Copy link
Member

Yes, the compiler got smarter and the book was incorrect. See this issue and this PR. The book has been fixed, but the fix hasn't ridden the Rust release trains to stable yet. You can read the new text at https://doc.rust-lang.org/nightly/book/ch03-02-data-types.html#invalid-array-element-access (note nightly in the URL instead of stable).

Thanks!

@MaksimDanilau
Copy link
Author

@carols10cents Great!

My bad, I've not found the same issue. Thanks for nightly tip!

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