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
{{ message }}
Repository navigation
index out of bound in slice not caught at compilation #38035
Hi! I'm just learning Rust! I saw this odd behavior, where the compiler will nicely tell me that an index in an array is impossible at compile time, but won't tell me that an index in a slice of known size is also impossible.
I thought I'd share.
This fails at compile time:
let y = [1];println!("y={}", y[1]);
This fails at runtime:
let y = [1];println!("y={}",&y[0..1][1]);
Would be cool if &y[0..1][1] also failed at compile time.
Activity
leonardo-m commentedon Nov 28, 2016
This may need a significant improvement of the compiler, but it's worth doing.
clarfonthey commentedon Nov 28, 2016
There are currently lints in clippy for this, I believe. Not sure if the compiler ever plans to add these.
Rollup merge of rust-lang#129517 - cjgillot:known-panic-array, r=pnkf…
Unrolled build for rust-lang#129517
Rollup merge of #129517 - cjgillot:known-panic-array, r=pnkfelix