-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#![feature(const_transmute)] | ||
#![allow(const_err)] // make sure we cannot allow away the errors tested here | ||
|
||
//! Test the "array of int" fast path in validity checking, and in particular whether it | ||
//! points at the right array element. | ||
use std::mem; | ||
|
||
#[repr(C)] | ||
union MaybeUninit<T: Copy> { | ||
uninit: (), | ||
init: T, | ||
} | ||
|
||
const UNINIT_INT_0: [u32; 3] = unsafe { | ||
//~^ ERROR it is undefined behavior to use this value | ||
//~| type validation failed: encountered uninitialized bytes at [0] | ||
[ | ||
MaybeUninit { uninit: () }.init, | ||
1, | ||
2, | ||
] | ||
}; | ||
const UNINIT_INT_1: [u32; 3] = unsafe { | ||
//~^ ERROR it is undefined behavior to use this value | ||
//~| type validation failed: encountered uninitialized bytes at [1] | ||
mem::transmute( | ||
[ | ||
0u8, | ||
0u8, | ||
0u8, | ||
0u8, | ||
1u8, | ||
MaybeUninit { uninit: () }.init, | ||
1u8, | ||
1u8, | ||
2u8, | ||
2u8, | ||
MaybeUninit { uninit: () }.init, | ||
2u8, | ||
] | ||
) | ||
}; | ||
const UNINIT_INT_2: [u32; 3] = unsafe { | ||
//~^ ERROR it is undefined behavior to use this value | ||
//~| type validation failed: encountered uninitialized bytes at [2] | ||
mem::transmute( | ||
[ | ||
0u8, | ||
0u8, | ||
0u8, | ||
0u8, | ||
1u8, | ||
1u8, | ||
1u8, | ||
1u8, | ||
2u8, | ||
2u8, | ||
2u8, | ||
MaybeUninit { uninit: () }.init, | ||
] | ||
) | ||
}; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/ub-int-array.rs:15:1 | ||
| | ||
LL | / const UNINIT_INT_0: [u32; 3] = unsafe { | ||
LL | | | ||
LL | | | ||
LL | | [ | ||
... | | ||
LL | | ] | ||
LL | | }; | ||
| |__^ type validation failed: encountered uninitialized bytes at [0] | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/ub-int-array.rs:24:1 | ||
| | ||
LL | / const UNINIT_INT_1: [u32; 3] = unsafe { | ||
LL | | | ||
LL | | | ||
LL | | mem::transmute( | ||
... | | ||
LL | | ) | ||
LL | | }; | ||
| |__^ type validation failed: encountered uninitialized bytes at [1] | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/ub-int-array.rs:44:1 | ||
| | ||
LL | / const UNINIT_INT_2: [u32; 3] = unsafe { | ||
LL | | | ||
LL | | | ||
LL | | mem::transmute( | ||
... | | ||
LL | | ) | ||
LL | | }; | ||
| |__^ type validation failed: encountered uninitialized bytes at [2] | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters