Hello
I am uncertain where to bring this up and the meta sub forum seemed the most suitable place.
Section "2.3 Arrays and Slices" in the Rust by example book finishes its example with these 2 lines:
// Out of bound indexing causes compile error
// println!("{}", xs[5]);
The comment states that the line below would cause a compiler error. I understand form what i see that the issue manifest itself first at runtime and is therefore a runtime error.
Here is what i see:
On my computer, with rustc 1.63.0 (Arch Linux rust 1:1.63.0-1)
having the last two lines like this:
// Out of bound indexing causes compile error
println!("{}", xs[5]);
does compile and when run gives me the following output:
first elemnet of the array: 1
second element fo the array 2
number of elements in array: 5
array occupies 20 bytes
borrow the whole array as a slice
first element of the slice: 1
the slive has 5 elements
borrow a section of the array as a slice
first element of the slice: 0
the slive has 3 elements
0: 1
1: 2
2: 3
3: 4
4: 5
Slow down! 5 is to far!
thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 5', 2-3_Arrays_Slices.rs:37:23
note: run withRUST_BACKTRACE=1
environment variable to display a backtrace
Ignoring all my typos, the program runs as expected, but ends with what i believe is a runtime error.
Doing the same on the website: Arrays and Slices - Rust By Example gives a similar warning, but printed before the program is run:
thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 5', src/main.rs:54:20
note: run withRUST_BACKTRACE=1
environment variable to display a backtrace