mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
assert_{inhabited,zero_valid,uninit_valid}
intrinsics are safe
Those intrinsics either panic or do nothing. They are safe.
This commit is contained in:
parent
75b7e52e92
commit
6b19a48e70
@ -69,6 +69,9 @@ pub fn intrinsic_operation_unsafety(intrinsic: Symbol) -> hir::Unsafety {
|
|||||||
// to note that it's safe to call, since
|
// to note that it's safe to call, since
|
||||||
// safe extern fns are otherwise unprecedented.
|
// safe extern fns are otherwise unprecedented.
|
||||||
sym::abort
|
sym::abort
|
||||||
|
| sym::assert_inhabited
|
||||||
|
| sym::assert_zero_valid
|
||||||
|
| sym::assert_uninit_valid
|
||||||
| sym::size_of
|
| sym::size_of
|
||||||
| sym::min_align_of
|
| sym::min_align_of
|
||||||
| sym::needs_drop
|
| sym::needs_drop
|
||||||
|
@ -13,10 +13,10 @@ fn main() {
|
|||||||
const _BAD1: () = unsafe {
|
const _BAD1: () = unsafe {
|
||||||
MaybeUninit::<!>::uninit().assume_init();
|
MaybeUninit::<!>::uninit().assume_init();
|
||||||
};
|
};
|
||||||
const _BAD2: () = unsafe {
|
const _BAD2: () = {
|
||||||
intrinsics::assert_uninit_valid::<bool>();
|
intrinsics::assert_uninit_valid::<bool>();
|
||||||
};
|
};
|
||||||
const _BAD3: () = unsafe {
|
const _BAD3: () = {
|
||||||
intrinsics::assert_zero_valid::<&'static i32>();
|
intrinsics::assert_zero_valid::<&'static i32>();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ LL | MaybeUninit::<!>::uninit().assume_init();
|
|||||||
error: any use of this value will cause an error
|
error: any use of this value will cause an error
|
||||||
--> $DIR/assert-type-intrinsics.rs:17:9
|
--> $DIR/assert-type-intrinsics.rs:17:9
|
||||||
|
|
|
|
||||||
LL | const _BAD2: () = unsafe {
|
LL | const _BAD2: () = {
|
||||||
| ---------------
|
| ---------------
|
||||||
LL | intrinsics::assert_uninit_valid::<bool>();
|
LL | intrinsics::assert_uninit_valid::<bool>();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `bool` uninitialized, which is invalid
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `bool` uninitialized, which is invalid
|
||||||
@ -24,7 +24,7 @@ LL | intrinsics::assert_uninit_valid::<bool>();
|
|||||||
error: any use of this value will cause an error
|
error: any use of this value will cause an error
|
||||||
--> $DIR/assert-type-intrinsics.rs:20:9
|
--> $DIR/assert-type-intrinsics.rs:20:9
|
||||||
|
|
|
|
||||||
LL | const _BAD3: () = unsafe {
|
LL | const _BAD3: () = {
|
||||||
| ---------------
|
| ---------------
|
||||||
LL | intrinsics::assert_zero_valid::<&'static i32>();
|
LL | intrinsics::assert_zero_valid::<&'static i32>();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
|
||||||
@ -51,7 +51,7 @@ Future breakage diagnostic:
|
|||||||
error: any use of this value will cause an error
|
error: any use of this value will cause an error
|
||||||
--> $DIR/assert-type-intrinsics.rs:17:9
|
--> $DIR/assert-type-intrinsics.rs:17:9
|
||||||
|
|
|
|
||||||
LL | const _BAD2: () = unsafe {
|
LL | const _BAD2: () = {
|
||||||
| ---------------
|
| ---------------
|
||||||
LL | intrinsics::assert_uninit_valid::<bool>();
|
LL | intrinsics::assert_uninit_valid::<bool>();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `bool` uninitialized, which is invalid
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `bool` uninitialized, which is invalid
|
||||||
@ -64,7 +64,7 @@ Future breakage diagnostic:
|
|||||||
error: any use of this value will cause an error
|
error: any use of this value will cause an error
|
||||||
--> $DIR/assert-type-intrinsics.rs:20:9
|
--> $DIR/assert-type-intrinsics.rs:20:9
|
||||||
|
|
|
|
||||||
LL | const _BAD3: () = unsafe {
|
LL | const _BAD3: () = {
|
||||||
| ---------------
|
| ---------------
|
||||||
LL | intrinsics::assert_zero_valid::<&'static i32>();
|
LL | intrinsics::assert_zero_valid::<&'static i32>();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
|
||||||
|
Loading…
Reference in New Issue
Block a user