Skip to content

Commit 594c499

Browse files
Add tests
1 parent a977df3 commit 594c499

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![deny(unused_unsafe)]
2+
3+
unsafe fn unsf() {}
4+
5+
unsafe fn foo() {
6+
unsafe { //~ ERROR unnecessary `unsafe` block
7+
unsf()
8+
}
9+
}
10+
11+
fn main() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: unnecessary `unsafe` block
2+
--> $DIR/feature-gate-unsafe_block_in_unsafe_fn.rs:6:5
3+
|
4+
LL | unsafe fn foo() {
5+
| --------------- because it's nested under this `unsafe` fn
6+
LL | unsafe {
7+
| ^^^^^^ unnecessary `unsafe` block
8+
|
9+
note: the lint level is defined here
10+
--> $DIR/feature-gate-unsafe_block_in_unsafe_fn.rs:1:9
11+
|
12+
LL | #![deny(unused_unsafe)]
13+
| ^^^^^^^^^^^^^
14+
15+
error: aborting due to previous error
16+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![feature(unsafe_block_in_unsafe_fn)]
2+
#![warn(unsafe_op_in_unsafe_fn)]
3+
#![deny(unused_unsafe)]
4+
5+
unsafe fn unsf() {}
6+
7+
unsafe fn foo() {
8+
unsf();
9+
//~^ WARNING call to unsafe function is unsafe and requires unsafe block
10+
}
11+
12+
unsafe fn bar() {
13+
unsafe { unsf() } // no error
14+
}
15+
16+
unsafe fn baz() {
17+
unsafe { unsafe { unsf() } }
18+
//~^ ERROR unnecessary `unsafe` block
19+
}
20+
21+
#[allow(unsafe_op_in_unsafe_fn)]
22+
unsafe fn qux() {
23+
unsf(); // no error
24+
}
25+
26+
fn main() {}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
warning: call to unsafe function is unsafe and requires unsafe block (error E0133)
2+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:8:5
3+
|
4+
LL | unsf();
5+
| ^^^^^^ call to unsafe function
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:2:9
9+
|
10+
LL | #![warn(unsafe_op_in_unsafe_fn)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^
12+
= note: consult the function's documentation for information on how to avoid undefined behavior
13+
14+
error: unnecessary `unsafe` block
15+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:17:14
16+
|
17+
LL | unsafe { unsafe { unsf() } }
18+
| ------ ^^^^^^ unnecessary `unsafe` block
19+
| |
20+
| because it's nested under this `unsafe` block
21+
|
22+
note: the lint level is defined here
23+
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:3:9
24+
|
25+
LL | #![deny(unused_unsafe)]
26+
| ^^^^^^^^^^^^^
27+
28+
error: aborting due to previous error; 1 warning emitted
29+

0 commit comments

Comments
 (0)