Skip to content

Commit effa3f8

Browse files
committed
transmute-non-immediate-to-immediate
1 parent e9c74b1 commit effa3f8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
//@ run-pass
2-
// Issue #7988
3-
// Transmuting non-immediate type to immediate type
1+
//! This test verifies the correct behavior of `std::mem::transmute` when converting
2+
//! a value from a single-element array type (`[isize; 1]`) to a scalar integer type (`isize`).
3+
//! This is a regression test ensuring that such transmutations, where source and destination
4+
//! types have the same size and alignment but differ in their "immediacy" or structure,
5+
//! are handled correctly.
6+
//!
7+
//! Regression test: <https://github.com/rust-lang/rust/issues/7988>
48
9+
//@ run-pass
510

611
pub fn main() {
712
unsafe {
8-
::std::mem::transmute::<[isize; 1],isize>([1])
9-
};
13+
// Transmute a single-element array `[1]` (which might be treated as a "non-immediate" type)
14+
// to a scalar `isize` (an "immediate" type).
15+
// This is safe because `[isize; 1]` and `isize` have the same size and alignment.
16+
::std::mem::transmute::<[isize; 1], isize>([1]);
17+
}
1018
}

0 commit comments

Comments
 (0)