-
Notifications
You must be signed in to change notification settings - Fork 13.4k
reword Miri validity errors: undefined -> uninitialized #71164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() {} |
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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should dump the memory of constants at some point and have diagnostics point into them (but in general it's useless for validation to point to the entire constant's span, just pointing to the name should suffice) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's not great -- but also pre-existing. |
||
| | ||
= 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`. |
Uh oh!
There was an error while loading. Please reload this page.