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
It seems that rustc is able to check for invalid array indexing at compile-time under some circumstances.
For instance, let's consider a crate, with the following code in it.
fnmain(){let a = [42];// Incorrect indexingprintln!("{}", a[1]);}
cargo run and cargo build both report the following error:
error: this operation will panic at runtime
--> src/main.rs:4:20
|
4 | println!("{}", a[1]);
| ^^^^ index out of bounds: the length is 1 but the index is 1
|
= note: `#[deny(unconditional_panic)]` on by default
However, cargo check reports nothing.
Running cargo clean before each command does not change anything.
I have set up a repository, which may help people to test it by themselves.
Meta
While I discovered this on the stable channel, nightly and beta are also affected.
yea, in order to make cargo check as fast as possible, we skip the entire MIR optimization pipeline, which also includes const prop. This is obviously not ideal, but so far we haven't been able to come up with anything that won't either duplicate the const prop pass or make cargo check much more expensive to run in some cases.
It seems that
rustc
is able to check for invalid array indexing at compile-time under some circumstances.For instance, let's consider a crate, with the following code in it.
cargo run
andcargo build
both report the following error:However,
cargo check
reports nothing.Running
cargo clean
before each command does not change anything.I have set up a repository, which may help people to test it by themselves.
Meta
While I discovered this on the stable channel, nightly and beta are also affected.
rustc --version --verbose
:rustc +nightly --version --verbose
:rustc +beta --version --verbose
:The text was updated successfully, but these errors were encountered: