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 am currently working through the Rust By Example collection. On the Arrays and Slices page, the last line of the example is supposed to cause an "index out of bounds" compile error when un-commented, but this does not happen. Instead, the code compiles with no error and a thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 5' error shows up at runtime.
Here is a shortened version of this example that erroneously compiles:
fnmain(){let xs:[i32;5] = [1,2,3,4,5];for i in0..xs.len() + 1{match xs.get(i){Some(xval) => println!("{}: {}", i, xval),None => println!("Slow down! {} is too far!", i),}}println!("{}", xs[5]);}
If you remove the for loop then the compiler properly complains. This problem occurs with both the latest stable (1.64.0) and nightly versions. Because this issue exists with nightly, I do not think that it is the same as #103385. Nightly information is given below.
thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 5', main.rs:9:20
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library\std\src\panicking.rs:584
1: core::panicking::panic_fmt
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library\core\src\panicking.rs:142
2: core::panicking::panic_bounds_check
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library\core\src\panicking.rs:84
3: core::fmt::Arguments::new_v1
4: core::ops::function::FnOnce::call_once
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
The text was updated successfully, but these errors were encountered:
I apologize. Although nightly was installed, it was not my default toolchain (hence why the meta version above is stable). This issue is solved in nightly, so it likely is the same as #103385. I will go ahead and close this issue. Again, I apologize for the spam.
I am currently working through the
Rust By Example
collection. On the Arrays and Slices page, the last line of the example is supposed to cause an "index out of bounds" compile error when un-commented, but this does not happen. Instead, the code compiles with no error and athread 'main' panicked at 'index out of bounds: the len is 5 but the index is 5'
error shows up at runtime.Here is a shortened version of this example that erroneously compiles:
If you remove the
for
loop then the compiler properly complains. This problem occurs with both the latest stable (1.64.0) and nightly versions. Because this issue exists with nightly, I do not think that it is the same as #103385. Nightly information is given below.Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: