test that both size_of_val and align_of_val panic

This commit is contained in:
Ralf Jung 2023-12-11 13:38:14 +01:00
parent df227f78c6
commit a47416beb5
5 changed files with 16 additions and 6 deletions

View File

@ -1,6 +1,7 @@
// run-fail
// check-run-results
// normalize-stderr-test "panicking\.rs:\d+:\d+:" -> "panicking.rs:"
// exec-env:RUST_BACKTRACE=0
// normalize-stderr-test: "(core/src/panicking\.rs):[0-9]+:[0-9]+" -> "$1:$$LINE:$$COL"
#![feature(extern_types)]
extern "C" {

View File

@ -1,4 +1,4 @@
thread 'main' panicked at library/core/src/panicking.rs:
thread 'main' panicked at library/core/src/panicking.rs:$LINE:$COL:
attempted to compute the size or alignment of extern type `Opaque`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.

View File

@ -1,4 +1,4 @@
thread 'main' panicked at library/core/src/panicking.rs:
thread 'main' panicked at library/core/src/panicking.rs:$LINE:$COL:
attempted to compute the size or alignment of extern type `A`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.

View File

@ -1,6 +1,8 @@
// run-fail
// check-run-results
// normalize-stderr-test "panicking\.rs:\d+:\d+:" -> "panicking.rs:"
// exec-env:RUST_BACKTRACE=0
// normalize-stderr-test: "(core/src/panicking\.rs):[0-9]+:[0-9]+" -> "$1:$$LINE:$$COL"
// revisions: size align
#![feature(extern_types)]
use std::mem::{align_of_val, size_of_val};
@ -13,6 +15,9 @@ fn main() {
let x: &A = unsafe { &*(1usize as *const A) };
// These don't have a dynamic size, so this should panic.
assert_eq!(size_of_val(x), 0);
assert_eq!(align_of_val(x), 1);
if cfg!(size) {
assert_eq!(size_of_val(x), 0);
} else {
assert_eq!(align_of_val(x), 1);
}
}

View File

@ -0,0 +1,4 @@
thread 'main' panicked at library/core/src/panicking.rs:$LINE:$COL:
attempted to compute the size or alignment of extern type `A`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.