Skip to content

Commit a95b342

Browse files
Test -Zthir-unsafeck for unsafe function calls
1 parent 29780f4 commit a95b342

File tree

46 files changed

+422
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+422
-45
lines changed

src/test/ui/async-await/async-unsafe-fn-call-in-safe.stderr renamed to src/test/ui/async-await/async-unsafe-fn-call-in-safe.mir.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2-
--> $DIR/async-unsafe-fn-call-in-safe.rs:12:5
2+
--> $DIR/async-unsafe-fn-call-in-safe.rs:14:5
33
|
44
LL | S::f();
55
| ^^^^^^ call to unsafe function
66
|
77
= note: consult the function's documentation for information on how to avoid undefined behavior
88

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

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

2525
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
26-
--> $DIR/async-unsafe-fn-call-in-safe.rs:18:5
26+
--> $DIR/async-unsafe-fn-call-in-safe.rs:20:5
2727
|
2828
LL | f();
2929
| ^^^ call to unsafe function

src/test/ui/async-await/async-unsafe-fn-call-in-safe.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// edition:2018
2+
// revisions: mir thir
3+
// [thir]compile-flags: -Z thir-unsafeck
24

35
struct S;
46

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2+
--> $DIR/async-unsafe-fn-call-in-safe.rs:14:5
3+
|
4+
LL | S::f();
5+
| ^^^^^^ call to unsafe function
6+
|
7+
= note: consult the function's documentation for information on how to avoid undefined behavior
8+
9+
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
10+
--> $DIR/async-unsafe-fn-call-in-safe.rs:15:5
11+
|
12+
LL | f();
13+
| ^^^ call to unsafe function
14+
|
15+
= note: consult the function's documentation for information on how to avoid undefined behavior
16+
17+
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
18+
--> $DIR/async-unsafe-fn-call-in-safe.rs:19:5
19+
|
20+
LL | S::f();
21+
| ^^^^^^ call to unsafe function
22+
|
23+
= note: consult the function's documentation for information on how to avoid undefined behavior
24+
25+
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
26+
--> $DIR/async-unsafe-fn-call-in-safe.rs:20:5
27+
|
28+
LL | f();
29+
| ^^^ call to unsafe function
30+
|
31+
= note: consult the function's documentation for information on how to avoid undefined behavior
32+
33+
error: aborting due to 4 previous errors
34+
35+
For more information about this error, try `rustc --explain E0133`.

src/test/ui/closures/closure_no_cap_coerce_many_unsafe_0.stderr renamed to src/test/ui/closures/closure_no_cap_coerce_many_unsafe_0.mir.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2-
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:12:23
2+
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:15:23
33
|
44
LL | let result: i32 = foo(5, 5);
55
| ^^^^^^^^^ call to unsafe function
66
|
77
= note: consult the function's documentation for information on how to avoid undefined behavior
88

99
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
10-
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:21:23
10+
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:24:23
1111
|
1212
LL | let result: i32 = foo(5, 5);
1313
| ^^^^^^^^^ call to unsafe function

src/test/ui/closures/closure_no_cap_coerce_many_unsafe_0.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// revisions: mir thir
2+
// [thir]compile-flags: -Z thir-unsafeck
3+
14
// Ensure we get unsafe function after coercion
25
unsafe fn add(a: i32, b: i32) -> i32 {
36
a + b
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2+
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:15:23
3+
|
4+
LL | let result: i32 = foo(5, 5);
5+
| ^^^^^^^^^ call to unsafe function
6+
|
7+
= note: consult the function's documentation for information on how to avoid undefined behavior
8+
9+
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
10+
--> $DIR/closure_no_cap_coerce_many_unsafe_0.rs:24:23
11+
|
12+
LL | let result: i32 = foo(5, 5);
13+
| ^^^^^^^^^ call to unsafe function
14+
|
15+
= note: consult the function's documentation for information on how to avoid undefined behavior
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0133`.

src/test/ui/closures/coerce-unsafe-closure-to-unsafe-fn-ptr.stderr renamed to src/test/ui/closures/coerce-unsafe-closure-to-unsafe-fn-ptr.mir.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2-
--> $DIR/coerce-unsafe-closure-to-unsafe-fn-ptr.rs:2:31
2+
--> $DIR/coerce-unsafe-closure-to-unsafe-fn-ptr.rs:5:31
33
|
44
LL | let _: unsafe fn() = || { ::std::pin::Pin::new_unchecked(&0_u8); };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function

src/test/ui/closures/coerce-unsafe-closure-to-unsafe-fn-ptr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// revisions: mir thir
2+
// [thir]compile-flags: -Z thir-unsafeck
3+
14
fn main() {
25
let _: unsafe fn() = || { ::std::pin::Pin::new_unchecked(&0_u8); };
36
//~^ ERROR E0133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2+
--> $DIR/coerce-unsafe-closure-to-unsafe-fn-ptr.rs:5:31
3+
|
4+
LL | let _: unsafe fn() = || { ::std::pin::Pin::new_unchecked(&0_u8); };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
6+
|
7+
= note: consult the function's documentation for information on how to avoid undefined behavior
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0133`.

src/test/ui/consts/const-extern-fn/const-extern-fn-requires-unsafe.stderr renamed to src/test/ui/consts/const-extern-fn/const-extern-fn-requires-unsafe.mir.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2-
--> $DIR/const-extern-fn-requires-unsafe.rs:8:5
2+
--> $DIR/const-extern-fn-requires-unsafe.rs:11:5
33
|
44
LL | foo();
55
| ^^^^^ call to unsafe function
66
|
77
= note: consult the function's documentation for information on how to avoid undefined behavior
88

99
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
10-
--> $DIR/const-extern-fn-requires-unsafe.rs:6:17
10+
--> $DIR/const-extern-fn-requires-unsafe.rs:9:17
1111
|
1212
LL | let a: [u8; foo()];
1313
| ^^^^^ call to unsafe function

src/test/ui/consts/const-extern-fn/const-extern-fn-requires-unsafe.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// revisions: mir thir
2+
// [thir]compile-flags: -Z thir-unsafeck
3+
14
#![feature(const_extern_fn)]
25

36
const unsafe extern "C" fn foo() -> usize { 5 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2+
--> $DIR/const-extern-fn-requires-unsafe.rs:11:5
3+
|
4+
LL | foo();
5+
| ^^^^^ call to unsafe function
6+
|
7+
= note: consult the function's documentation for information on how to avoid undefined behavior
8+
9+
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
10+
--> $DIR/const-extern-fn-requires-unsafe.rs:9:17
11+
|
12+
LL | let a: [u8; foo()];
13+
| ^^^^^ call to unsafe function
14+
|
15+
= note: consult the function's documentation for information on how to avoid undefined behavior
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0133`.

src/test/ui/error-codes/E0133.stderr renamed to src/test/ui/error-codes/E0133.mir.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2-
--> $DIR/E0133.rs:4:5
2+
--> $DIR/E0133.rs:7:5
33
|
44
LL | f();
55
| ^^^ call to unsafe function

src/test/ui/error-codes/E0133.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// revisions: mir thir
2+
// [thir]compile-flags: -Z thir-unsafeck
3+
14
unsafe fn f() { return; }
25

36
fn main() {

src/test/ui/unsafe/unsafe-fn-called-from-safe.stderr renamed to src/test/ui/error-codes/E0133.thir.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2-
--> $DIR/unsafe-fn-called-from-safe.rs:4:5
2+
--> $DIR/E0133.rs:7:5
33
|
44
LL | f();
55
| ^^^ call to unsafe function

src/test/ui/feature-gates/feature-gate-const_fn_transmute.stderr renamed to src/test/ui/feature-gates/feature-gate-const_fn_transmute.mir.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: `transmute` is not allowed in constant functions
2-
--> $DIR/feature-gate-const_fn_transmute.rs:8:43
2+
--> $DIR/feature-gate-const_fn_transmute.rs:11:43
33
|
44
LL | const fn transmute_fn() -> u32 { unsafe { mem::transmute(Foo(3)) } }
55
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -9,7 +9,7 @@ LL | const fn transmute_fn() -> u32 { unsafe { mem::transmute(Foo(3)) } }
99
= note: `transmute` is only allowed in constants and statics for now
1010

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

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

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

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

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

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

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

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

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

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

107107
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
108-
--> $DIR/feature-gate-const_fn_transmute.rs:34:54
108+
--> $DIR/feature-gate-const_fn_transmute.rs:37:54
109109
|
110110
LL | const fn safe_transmute_fn_core_intrinsic() -> u32 { core::intrinsics::transmute(Foo(3)) }
111111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function

src/test/ui/feature-gates/feature-gate-const_fn_transmute.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// revisions: mir thir
2+
// [thir]compile-flags: -Z thir-unsafeck
3+
14
use std::mem;
25

36
#[repr(transparent)]

0 commit comments

Comments
 (0)