Skip to content

debug_asserts within libstd are not hit unless using -Zbuild-std #120539

Closed
@glandium

Description

@glandium

STR:

$ cargo new testcase ; cd testcase
$ cat <<EOF > src/main.rs
fn main() {
    let a = [0; 2];
    let b = unsafe { a.get_unchecked(3) };
    println!("{}", b);
}
EOF
$ cargo +nightly run -q
32764
$ cargo +nightly run -q -Zbuild-std --target=x86_64-unknown-linux-gnu
thread 'main' panicked at /home/glandium/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/index.rs:228:9:
slice::get_unchecked requires that the index is within the slice
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.

It would seem the intent is for the latter to always happen, but it doesn't.

$ rustc +nightly --version
rustc 1.77.0-nightly (cb4d9a190 2024-01-30)

Metadata

Metadata

Assignees

Labels

C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions