Skip to content
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

assert_{inhabited,zero_valid,uninit_valid} intrinsics are safe #100487

Merged
merged 1 commit into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_typeck/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ pub fn intrinsic_operation_unsafety(intrinsic: Symbol) -> hir::Unsafety {
// to note that it's safe to call, since
// safe extern fns are otherwise unprecedented.
sym::abort
| sym::assert_inhabited
| sym::assert_zero_valid
| sym::assert_uninit_valid
| sym::size_of
| sym::min_align_of
| sym::needs_drop
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/consts/assert-type-intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ fn main() {
const _BAD1: () = unsafe {
MaybeUninit::<!>::uninit().assume_init();
};
const _BAD2: () = unsafe {
const _BAD2: () = {
intrinsics::assert_uninit_valid::<bool>();
};
const _BAD3: () = unsafe {
const _BAD3: () = {
intrinsics::assert_zero_valid::<&'static i32>();
};
}
8 changes: 4 additions & 4 deletions src/test/ui/consts/assert-type-intrinsics.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LL | MaybeUninit::<!>::uninit().assume_init();
error: any use of this value will cause an error
--> $DIR/assert-type-intrinsics.rs:17:9
|
LL | const _BAD2: () = unsafe {
LL | const _BAD2: () = {
| ---------------
LL | intrinsics::assert_uninit_valid::<bool>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `bool` uninitialized, which is invalid
Expand All @@ -24,7 +24,7 @@ LL | intrinsics::assert_uninit_valid::<bool>();
error: any use of this value will cause an error
--> $DIR/assert-type-intrinsics.rs:20:9
|
LL | const _BAD3: () = unsafe {
LL | const _BAD3: () = {
| ---------------
LL | intrinsics::assert_zero_valid::<&'static i32>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
Expand All @@ -51,7 +51,7 @@ Future breakage diagnostic:
error: any use of this value will cause an error
--> $DIR/assert-type-intrinsics.rs:17:9
|
LL | const _BAD2: () = unsafe {
LL | const _BAD2: () = {
| ---------------
LL | intrinsics::assert_uninit_valid::<bool>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `bool` uninitialized, which is invalid
Expand All @@ -64,7 +64,7 @@ Future breakage diagnostic:
error: any use of this value will cause an error
--> $DIR/assert-type-intrinsics.rs:20:9
|
LL | const _BAD3: () = unsafe {
LL | const _BAD3: () = {
| ---------------
LL | intrinsics::assert_zero_valid::<&'static i32>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
Expand Down