Skip to content

Commit

Permalink
Test -Zthir-unsafeck for unsafe function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSeulArtichaut committed May 11, 2021
1 parent 29780f4 commit a95b342
Show file tree
Hide file tree
Showing 46 changed files with 422 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/async-unsafe-fn-call-in-safe.rs:12:5
--> $DIR/async-unsafe-fn-call-in-safe.rs:14:5
|
LL | S::f();
| ^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/async-unsafe-fn-call-in-safe.rs:13:5
--> $DIR/async-unsafe-fn-call-in-safe.rs:15:5
|
LL | f();
| ^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/async-unsafe-fn-call-in-safe.rs:17:5
--> $DIR/async-unsafe-fn-call-in-safe.rs:19:5
|
LL | S::f();
| ^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/async-unsafe-fn-call-in-safe.rs:18:5
--> $DIR/async-unsafe-fn-call-in-safe.rs:20:5
|
LL | f();
| ^^^ call to unsafe function
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/async-await/async-unsafe-fn-call-in-safe.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// edition:2018
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck

struct S;

Expand Down
35 changes: 35 additions & 0 deletions src/test/ui/async-await/async-unsafe-fn-call-in-safe.thir.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/async-unsafe-fn-call-in-safe.rs:14:5
|
LL | S::f();
| ^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/async-unsafe-fn-call-in-safe.rs:15:5
|
LL | f();
| ^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/async-unsafe-fn-call-in-safe.rs:19:5
|
LL | S::f();
| ^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/async-unsafe-fn-call-in-safe.rs:20:5
|
LL | f();
| ^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0133`.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:12:23
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:15:23
|
LL | let result: i32 = foo(5, 5);
| ^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:21:23
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:24:23
|
LL | let result: i32 = foo(5, 5);
| ^^^^^^^^^ call to unsafe function
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/closures/closure_no_cap_coerce_many_unsafe_0.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck

// Ensure we get unsafe function after coercion
unsafe fn add(a: i32, b: i32) -> i32 {
a + b
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:15:23
|
LL | let result: i32 = foo(5, 5);
| ^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:24:23
|
LL | let result: i32 = foo(5, 5);
| ^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0133`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/coerce-unsafe-closure-to-unsafe-fn-ptr.rs:2:31
--> $DIR/coerce-unsafe-closure-to-unsafe-fn-ptr.rs:5:31
|
LL | let _: unsafe fn() = || { ::std::pin::Pin::new_unchecked(&0_u8); };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck

fn main() {
let _: unsafe fn() = || { ::std::pin::Pin::new_unchecked(&0_u8); };
//~^ ERROR E0133
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/coerce-unsafe-closure-to-unsafe-fn-ptr.rs:5:31
|
LL | let _: unsafe fn() = || { ::std::pin::Pin::new_unchecked(&0_u8); };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error: aborting due to previous error

For more information about this error, try `rustc --explain E0133`.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/const-extern-fn-requires-unsafe.rs:8:5
--> $DIR/const-extern-fn-requires-unsafe.rs:11:5
|
LL | foo();
| ^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/const-extern-fn-requires-unsafe.rs:6:17
--> $DIR/const-extern-fn-requires-unsafe.rs:9:17
|
LL | let a: [u8; foo()];
| ^^^^^ call to unsafe function
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck

#![feature(const_extern_fn)]

const unsafe extern "C" fn foo() -> usize { 5 }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/const-extern-fn-requires-unsafe.rs:11:5
|
LL | foo();
| ^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/const-extern-fn-requires-unsafe.rs:9:17
|
LL | let a: [u8; foo()];
| ^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0133`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/E0133.rs:4:5
--> $DIR/E0133.rs:7:5
|
LL | f();
| ^^^ call to unsafe function
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/error-codes/E0133.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck

unsafe fn f() { return; }

fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/unsafe-fn-called-from-safe.rs:4:5
--> $DIR/E0133.rs:7:5
|
LL | f();
| ^^^ call to unsafe function
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: `transmute` is not allowed in constant functions
--> $DIR/feature-gate-const_fn_transmute.rs:8:43
--> $DIR/feature-gate-const_fn_transmute.rs:11:43
|
LL | const fn transmute_fn() -> u32 { unsafe { mem::transmute(Foo(3)) } }
| ^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -9,7 +9,7 @@ LL | const fn transmute_fn() -> u32 { unsafe { mem::transmute(Foo(3)) } }
= note: `transmute` is only allowed in constants and statics for now

error[E0658]: `transmute` is not allowed in constant functions
--> $DIR/feature-gate-const_fn_transmute.rs:11:53
--> $DIR/feature-gate-const_fn_transmute.rs:14:53
|
LL | const fn transmute_fn_intrinsic() -> u32 { unsafe { std::intrinsics::transmute(Foo(3)) } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -19,7 +19,7 @@ LL | const fn transmute_fn_intrinsic() -> u32 { unsafe { std::intrinsics::transm
= note: `transmute` is only allowed in constants and statics for now

error[E0658]: `transmute` is not allowed in constant functions
--> $DIR/feature-gate-const_fn_transmute.rs:14:58
--> $DIR/feature-gate-const_fn_transmute.rs:17:58
|
LL | const fn transmute_fn_core_intrinsic() -> u32 { unsafe { core::intrinsics::transmute(Foo(3)) } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -29,7 +29,7 @@ LL | const fn transmute_fn_core_intrinsic() -> u32 { unsafe { core::intrinsics::
= note: `transmute` is only allowed in constants and statics for now

error[E0658]: `transmute` is not allowed in constant functions
--> $DIR/feature-gate-const_fn_transmute.rs:17:48
--> $DIR/feature-gate-const_fn_transmute.rs:20:48
|
LL | const unsafe fn unsafe_transmute_fn() -> u32 { mem::transmute(Foo(3)) }
| ^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -39,7 +39,7 @@ LL | const unsafe fn unsafe_transmute_fn() -> u32 { mem::transmute(Foo(3)) }
= note: `transmute` is only allowed in constants and statics for now

error[E0658]: `transmute` is not allowed in constant functions
--> $DIR/feature-gate-const_fn_transmute.rs:20:58
--> $DIR/feature-gate-const_fn_transmute.rs:23:58
|
LL | const unsafe fn unsafe_transmute_fn_intrinsic() -> u32 { std::intrinsics::transmute(Foo(3)) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -49,7 +49,7 @@ LL | const unsafe fn unsafe_transmute_fn_intrinsic() -> u32 { std::intrinsics::t
= note: `transmute` is only allowed in constants and statics for now

error[E0658]: `transmute` is not allowed in constant functions
--> $DIR/feature-gate-const_fn_transmute.rs:23:63
--> $DIR/feature-gate-const_fn_transmute.rs:26:63
|
LL | const unsafe fn unsafe_transmute_fn_core_intrinsic() -> u32 { core::intrinsics::transmute(Foo(3)) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -59,7 +59,7 @@ LL | const unsafe fn unsafe_transmute_fn_core_intrinsic() -> u32 { core::intrins
= note: `transmute` is only allowed in constants and statics for now

error[E0658]: `transmute` is not allowed in constant functions
--> $DIR/feature-gate-const_fn_transmute.rs:26:39
--> $DIR/feature-gate-const_fn_transmute.rs:29:39
|
LL | const fn safe_transmute_fn() -> u32 { mem::transmute(Foo(3)) }
| ^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -69,7 +69,7 @@ LL | const fn safe_transmute_fn() -> u32 { mem::transmute(Foo(3)) }
= note: `transmute` is only allowed in constants and statics for now

error[E0658]: `transmute` is not allowed in constant functions
--> $DIR/feature-gate-const_fn_transmute.rs:30:49
--> $DIR/feature-gate-const_fn_transmute.rs:33:49
|
LL | const fn safe_transmute_fn_intrinsic() -> u32 { std::intrinsics::transmute(Foo(3)) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -79,7 +79,7 @@ LL | const fn safe_transmute_fn_intrinsic() -> u32 { std::intrinsics::transmute(
= note: `transmute` is only allowed in constants and statics for now

error[E0658]: `transmute` is not allowed in constant functions
--> $DIR/feature-gate-const_fn_transmute.rs:34:54
--> $DIR/feature-gate-const_fn_transmute.rs:37:54
|
LL | const fn safe_transmute_fn_core_intrinsic() -> u32 { core::intrinsics::transmute(Foo(3)) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -89,23 +89,23 @@ LL | const fn safe_transmute_fn_core_intrinsic() -> u32 { core::intrinsics::tran
= note: `transmute` is only allowed in constants and statics for now

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/feature-gate-const_fn_transmute.rs:26:39
--> $DIR/feature-gate-const_fn_transmute.rs:29:39
|
LL | const fn safe_transmute_fn() -> u32 { mem::transmute(Foo(3)) }
| ^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/feature-gate-const_fn_transmute.rs:30:49
--> $DIR/feature-gate-const_fn_transmute.rs:33:49
|
LL | const fn safe_transmute_fn_intrinsic() -> u32 { std::intrinsics::transmute(Foo(3)) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/feature-gate-const_fn_transmute.rs:34:54
--> $DIR/feature-gate-const_fn_transmute.rs:37:54
|
LL | const fn safe_transmute_fn_core_intrinsic() -> u32 { core::intrinsics::transmute(Foo(3)) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/feature-gates/feature-gate-const_fn_transmute.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck

use std::mem;

#[repr(transparent)]
Expand Down
Loading

0 comments on commit a95b342

Please sign in to comment.