-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Missing index out of bounds error #48920
Comments
Yea, there's a FIXME comment in |
I imagine it was specific to the old implementation, but just a note that we want to make sure #48900 doesn't reappear when this is reimplemented. |
…ck, r=oli-obk Check array indices in constant propagation Previously, uses of constant weren't correctly propagated. This fixes rust-lang#48920. r? @oli-obk because you suggested it
This code still errors, but this case doesn't: fn main() {
let a = [1, 2, 3];
let index = 10;
let element = a[index];
println!("element is {}", element);
} is this expected? |
yes. Constant propagation does not cross variables (for now). To do this correctly we'll need to detect loops and conditions. Without such a detection mechanism our current implemementation will do a few bogus things. |
Since rustc 1.61, the following code is not giving a compile-time error:
If I uncomment the last line, the compile-time error shows up. cc @oli-obk |
The following example no longer throws a warning about indices being out of bounds, on master:
I expect a
index out of bounds: the len is 1 but the index is 1
error. I suspect this is due to #46882.cc @oli-obk
The text was updated successfully, but these errors were encountered: