Skip to content
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

Out-of-bound array access not reported when checking the crate #81224

Closed
scrabsha opened this issue Jan 20, 2021 · 3 comments
Closed

Out-of-bound array access not reported when checking the crate #81224

scrabsha opened this issue Jan 20, 2021 · 3 comments
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug.

Comments

@scrabsha
Copy link
Contributor

scrabsha commented Jan 20, 2021

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.

fn main() {
    let a = [42];
    // Incorrect indexing
    println!("{}", 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.

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-unknown-linux-gnu
release: 1.49.0

rustc +nightly --version --verbose :

rustc 1.51.0-nightly (c5a96fb79 2021-01-19)
binary: rustc
commit-hash: c5a96fb7973649807a7943e7395456db158dcab6
commit-date: 2021-01-19
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1

rustc +beta --version --verbose:

rustc 1.50.0-beta.6 (ea20aa255 2021-01-14)
binary: rustc
commit-hash: ea20aa255b54708fb6a86f3146244eb20d079513
commit-date: 2021-01-14
host: x86_64-unknown-linux-gnu
release: 1.50.0-beta.6
@scrabsha scrabsha added the C-bug Category: This is a bug. label Jan 20, 2021
@jonas-schievink
Copy link
Contributor

I believe this is expected behavior, since these warnings are reported by the constant-propagation pass, which might not always run

@oli-obk
Copy link
Contributor

oli-obk commented Jan 21, 2021

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.

@Enselic
Copy link
Member

Enselic commented Dec 16, 2023

Triage: Closing as wont fix as discussed above.

@Enselic Enselic closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants