Skip to content

Commit

Permalink
test that both size_of_val and align_of_val panic
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 12, 2023
1 parent df227f7 commit a47416b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tests/ui/extern/extern-types-field-offset.rs
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/extern/extern-types-field-offset.run.stderr
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 8 additions & 3 deletions tests/ui/extern/extern-types-size_of_val.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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);
}
}
4 changes: 4 additions & 0 deletions tests/ui/extern/extern-types-size_of_val.size.run.stderr
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit a47416b

Please sign in to comment.