Skip to content

cargo check does not catch "index out of bounds" error #113831

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

Closed
endvvell opened this issue Jul 18, 2023 · 2 comments
Closed

cargo check does not catch "index out of bounds" error #113831

endvvell opened this issue Jul 18, 2023 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@endvvell
Copy link

Running cargo check does not detect "index out of bounds" error in the following code:

fn main() {
    let a: [i32; 5] = [1, 2, 3, 4, 5];
    let element = a[9999];
    println!("{}", element);
}

I expected to see this happen:

Same output that the cargo build returns:

error: this operation will panic at runtime
 --> src/main.rs:3:19
  |
3 |     let element = a[9999];
  |                   ^^^^^^^ index out of bounds: the length is 5 but the index is 9999
  |

Instead, this happened:

Finished dev [unoptimized + debuginfo] target(s) in 0.00s

Running cargo check --release also returns a positive result:

Finished release [optimized] target(s) in 0.00s

Meta

rustc --version --verbose:

rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: x86_64-unknown-linux-gnu
release: 1.71.0
LLVM version: 16.0.5

cargo --version --verbose:

cargo 1.71.0 (cfd3bbd8f 2023-06-08)
release: 1.71.0
commit-hash: cfd3bbd8fe4fd92074dfad04b7eb9a923646839f
commit-date: 2023-06-08
host: x86_64-unknown-linux-gnu
libgit2: 1.6.4 (sys:0.17.1 vendored)
libcurl: 8.0.1-DEV (sys:0.4.61+curl-8.0.1 vendored ssl:OpenSSL/1.1.1t)
ssl: OpenSSL 1.1.1t  7 Feb 2023
os: Ubuntu 20.04 (focal) [64-bit]
@endvvell endvvell added the C-bug Category: This is a bug. label Jul 18, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 18, 2023
@clubby789
Copy link
Contributor

This is expected behaviour, cc #81224. Checking for unconditional panics requires running some of the MIR opt pipeline, which would slow down cargo check

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 20, 2023
@saethlin
Copy link
Member

Closing this as a duplicate of the linked issue.

@saethlin saethlin closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants