2021-05-24 05:55:01 -05:00
|
|
|
// revisions: mir thir
|
|
|
|
// [thir]compile-flags: -Zthir-unsafeck
|
|
|
|
|
2020-05-21 16:53:12 -05:00
|
|
|
#![deny(unsafe_op_in_unsafe_fn)]
|
2020-05-03 16:11:58 -05:00
|
|
|
#![deny(unused_unsafe)]
|
|
|
|
|
|
|
|
unsafe fn unsf() {}
|
2020-05-14 13:37:23 -05:00
|
|
|
const PTR: *const () = std::ptr::null();
|
|
|
|
static mut VOID: () = ();
|
|
|
|
|
2020-05-21 16:53:12 -05:00
|
|
|
unsafe fn deny_level() {
|
2020-05-03 16:11:58 -05:00
|
|
|
unsf();
|
2022-04-26 05:43:00 -05:00
|
|
|
//[mir]~^ ERROR call to unsafe function is unsafe and requires unsafe block
|
|
|
|
//[thir]~^^ ERROR call to unsafe function `unsf` is unsafe and requires unsafe block
|
2020-05-14 13:37:23 -05:00
|
|
|
*PTR;
|
2020-05-21 16:53:12 -05:00
|
|
|
//~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
|
2020-05-14 13:37:23 -05:00
|
|
|
VOID = ();
|
2020-05-21 16:53:12 -05:00
|
|
|
//~^ ERROR use of mutable static is unsafe and requires unsafe block
|
2021-01-17 04:07:43 -06:00
|
|
|
|
|
|
|
unsafe {}
|
|
|
|
//~^ ERROR unnecessary `unsafe` block
|
2020-05-03 16:11:58 -05:00
|
|
|
}
|
|
|
|
|
2020-05-21 16:53:12 -05:00
|
|
|
// Check that `unsafe_op_in_unsafe_fn` works starting from the `warn` level.
|
|
|
|
#[warn(unsafe_op_in_unsafe_fn)]
|
|
|
|
#[deny(warnings)]
|
|
|
|
unsafe fn warning_level() {
|
|
|
|
unsf();
|
2022-04-26 05:43:00 -05:00
|
|
|
//[mir]~^ ERROR call to unsafe function is unsafe and requires unsafe block
|
|
|
|
//[thir]~^^ ERROR call to unsafe function `unsf` is unsafe and requires unsafe block
|
2020-05-21 16:53:12 -05:00
|
|
|
*PTR;
|
|
|
|
//~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
|
|
|
|
VOID = ();
|
|
|
|
//~^ ERROR use of mutable static is unsafe and requires unsafe block
|
2021-01-17 04:07:43 -06:00
|
|
|
unsafe {}
|
|
|
|
//~^ ERROR unnecessary `unsafe` block
|
2020-05-21 16:53:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn explicit_block() {
|
2020-05-14 13:37:23 -05:00
|
|
|
// no error
|
|
|
|
unsafe {
|
|
|
|
unsf();
|
|
|
|
*PTR;
|
|
|
|
VOID = ();
|
|
|
|
}
|
2020-05-03 16:11:58 -05:00
|
|
|
}
|
|
|
|
|
2020-05-21 16:53:12 -05:00
|
|
|
unsafe fn two_explicit_blocks() {
|
2020-05-03 16:11:58 -05:00
|
|
|
unsafe { unsafe { unsf() } }
|
|
|
|
//~^ ERROR unnecessary `unsafe` block
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(unsafe_op_in_unsafe_fn)]
|
2020-05-21 16:53:12 -05:00
|
|
|
unsafe fn allow_level() {
|
2020-05-14 13:37:23 -05:00
|
|
|
// lint allowed -> no error
|
|
|
|
unsf();
|
|
|
|
*PTR;
|
|
|
|
VOID = ();
|
2020-05-13 16:43:21 -05:00
|
|
|
|
|
|
|
unsafe { unsf() }
|
2020-05-03 16:11:58 -05:00
|
|
|
}
|
|
|
|
|
2020-05-21 16:53:12 -05:00
|
|
|
unsafe fn nested_allow_level() {
|
|
|
|
#[allow(unsafe_op_in_unsafe_fn)]
|
|
|
|
{
|
|
|
|
// lint allowed -> no error
|
|
|
|
unsf();
|
|
|
|
*PTR;
|
|
|
|
VOID = ();
|
|
|
|
|
|
|
|
unsafe { unsf() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 16:43:21 -05:00
|
|
|
fn main() {
|
2020-05-21 16:53:12 -05:00
|
|
|
unsf();
|
2022-04-26 05:43:00 -05:00
|
|
|
//[mir]~^ ERROR call to unsafe function is unsafe and requires unsafe block
|
|
|
|
//[thir]~^^ ERROR call to unsafe function `unsf` is unsafe and requires unsafe block
|
2020-05-21 16:53:12 -05:00
|
|
|
#[allow(unsafe_op_in_unsafe_fn)]
|
|
|
|
{
|
|
|
|
unsf();
|
2022-04-26 05:43:00 -05:00
|
|
|
//[mir]~^ ERROR call to unsafe function is unsafe and requires unsafe function or block
|
|
|
|
//[thir]~^^ ERROR call to unsafe function `unsf` is unsafe and requires unsafe function or block
|
2020-05-21 16:53:12 -05:00
|
|
|
}
|
2020-05-13 16:43:21 -05:00
|
|
|
}
|