diff options
Diffstat (limited to 'tests/ui/transmute/transmute-array-to-scalar.rs')
| -rw-r--r-- | tests/ui/transmute/transmute-array-to-scalar.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/ui/transmute/transmute-array-to-scalar.rs b/tests/ui/transmute/transmute-array-to-scalar.rs new file mode 100644 index 00000000000..cd6dbb040c8 --- /dev/null +++ b/tests/ui/transmute/transmute-array-to-scalar.rs @@ -0,0 +1,14 @@ +//! Verify transmuting from a single-element array to a scalar is allowed. +//! +//! Regression test: <https://github.com/rust-lang/rust/issues/7988> + +//@ run-pass + +pub fn main() { + unsafe { + // Transmute a single-element array `[1]` (which might be treated as a "non-immediate" type) + // to a scalar `isize` (an "immediate" type). + // This is safe because `[isize; 1]` and `isize` have the same size and alignment. + ::std::mem::transmute::<[isize; 1], isize>([1]); + } +} |
