Add tests
This commit is contained in:
parent
a977df35d1
commit
594c499db9
4 changed files with 82 additions and 0 deletions
|
|
@ -0,0 +1,11 @@
|
|||
#![deny(unused_unsafe)]
|
||||
|
||||
unsafe fn unsf() {}
|
||||
|
||||
unsafe fn foo() {
|
||||
unsafe { //~ ERROR unnecessary `unsafe` block
|
||||
unsf()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -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
|
||||
|
||||
26
src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.rs
Normal file
26
src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.rs
Normal 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() {}
|
||||
29
src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.stderr
Normal file
29
src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.stderr
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue