Add tests

This commit is contained in:
LeSeulArtichaut 2020-05-03 23:11:58 +02:00
parent a977df35d1
commit 594c499db9
4 changed files with 82 additions and 0 deletions

View file

@ -0,0 +1,11 @@
#![deny(unused_unsafe)]
unsafe fn unsf() {}
unsafe fn foo() {
unsafe { //~ ERROR unnecessary `unsafe` block
unsf()
}
}
fn main() {}

View file

@ -0,0 +1,16 @@
error: unnecessary `unsafe` block
--> $DIR/feature-gate-unsafe_block_in_unsafe_fn.rs:6:5
|
LL | unsafe fn foo() {
| --------------- because it's nested under this `unsafe` fn
LL | unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
note: the lint level is defined here
--> $DIR/feature-gate-unsafe_block_in_unsafe_fn.rs:1:9
|
LL | #![deny(unused_unsafe)]
| ^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -0,0 +1,26 @@
#![feature(unsafe_block_in_unsafe_fn)]
#![warn(unsafe_op_in_unsafe_fn)]
#![deny(unused_unsafe)]
unsafe fn unsf() {}
unsafe fn foo() {
unsf();
//~^ WARNING call to unsafe function is unsafe and requires unsafe block
}
unsafe fn bar() {
unsafe { unsf() } // no error
}
unsafe fn baz() {
unsafe { unsafe { unsf() } }
//~^ ERROR unnecessary `unsafe` block
}
#[allow(unsafe_op_in_unsafe_fn)]
unsafe fn qux() {
unsf(); // no error
}
fn main() {}

View file

@ -0,0 +1,29 @@
warning: call to unsafe function is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:8:5
|
LL | unsf();
| ^^^^^^ call to unsafe function
|
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:2:9
|
LL | #![warn(unsafe_op_in_unsafe_fn)]
| ^^^^^^^^^^^^^^^^^^^^^^
= note: consult the function's documentation for information on how to avoid undefined behavior
error: unnecessary `unsafe` block
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:17:14
|
LL | unsafe { unsafe { unsf() } }
| ------ ^^^^^^ unnecessary `unsafe` block
| |
| because it's nested under this `unsafe` block
|
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:3:9
|
LL | #![deny(unused_unsafe)]
| ^^^^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted