2022-07-27 17:03:16 -05:00
|
|
|
//@ run-rustfix
|
2023-06-11 04:59:15 -05:00
|
|
|
//@ aux-build:external_unsafe_macro.rs
|
2022-07-27 17:03:16 -05:00
|
|
|
|
2023-05-27 15:20:14 -05:00
|
|
|
#![deny(unsafe_op_in_unsafe_fn)] //~ NOTE
|
2023-10-26 10:39:25 -05:00
|
|
|
#![crate_name = "wrapping_unsafe_block_sugg"]
|
2022-07-27 17:03:16 -05:00
|
|
|
|
2023-06-11 04:59:15 -05:00
|
|
|
extern crate external_unsafe_macro;
|
|
|
|
|
2022-07-27 17:03:16 -05:00
|
|
|
unsafe fn unsf() {}
|
|
|
|
|
|
|
|
pub unsafe fn foo() { unsafe {
|
2023-05-27 15:20:14 -05:00
|
|
|
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
2023-12-07 05:56:48 -06:00
|
|
|
unsf(); //~ ERROR call to unsafe function `unsf` is unsafe
|
2024-01-13 17:06:34 -06:00
|
|
|
//~^ NOTE call to unsafe function
|
|
|
|
//~| NOTE for more information, see issue #71668
|
|
|
|
//~| NOTE consult the function's documentation
|
2023-12-07 05:56:48 -06:00
|
|
|
unsf(); //~ ERROR call to unsafe function `unsf` is unsafe
|
2024-01-13 17:06:34 -06:00
|
|
|
//~^ NOTE call to unsafe function
|
|
|
|
//~| NOTE for more information, see issue #71668
|
|
|
|
//~| NOTE consult the function's documentation
|
2022-07-27 17:03:16 -05:00
|
|
|
}}
|
|
|
|
|
2023-05-27 07:37:18 -05:00
|
|
|
pub unsafe fn bar(x: *const i32) -> i32 { unsafe {
|
2023-05-27 15:20:14 -05:00
|
|
|
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
2023-05-27 07:37:18 -05:00
|
|
|
let y = *x; //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
|
2024-01-13 17:06:34 -06:00
|
|
|
//~^ NOTE dereference of raw pointer
|
|
|
|
//~| NOTE for more information, see issue #71668
|
|
|
|
//~| NOTE raw pointers may be null
|
2023-05-27 07:37:18 -05:00
|
|
|
y + *x //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
|
2024-01-13 17:06:34 -06:00
|
|
|
//~^ NOTE dereference of raw pointer
|
|
|
|
//~| NOTE for more information, see issue #71668
|
|
|
|
//~| NOTE raw pointers may be null
|
2023-05-27 07:37:18 -05:00
|
|
|
}}
|
|
|
|
|
|
|
|
static mut BAZ: i32 = 0;
|
|
|
|
pub unsafe fn baz() -> i32 { unsafe {
|
2023-05-27 15:20:14 -05:00
|
|
|
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
2023-05-27 07:37:18 -05:00
|
|
|
let y = BAZ; //~ ERROR use of mutable static is unsafe and requires unsafe block
|
2024-01-13 17:06:34 -06:00
|
|
|
//~^ NOTE use of mutable static
|
|
|
|
//~| NOTE for more information, see issue #71668
|
|
|
|
//~| NOTE mutable statics can be mutated by multiple threads
|
2023-05-27 07:37:18 -05:00
|
|
|
y + BAZ //~ ERROR use of mutable static is unsafe and requires unsafe block
|
2024-01-13 17:06:34 -06:00
|
|
|
//~^ NOTE use of mutable static
|
|
|
|
//~| NOTE for more information, see issue #71668
|
|
|
|
//~| NOTE mutable statics can be mutated by multiple threads
|
2023-05-27 07:37:18 -05:00
|
|
|
}}
|
|
|
|
|
2023-06-11 04:59:15 -05:00
|
|
|
macro_rules! unsafe_macro { () => (unsf()) }
|
2023-12-07 05:56:48 -06:00
|
|
|
//~^ ERROR call to unsafe function `unsf` is unsafe
|
2024-01-13 17:06:34 -06:00
|
|
|
//~| NOTE call to unsafe function
|
|
|
|
//~| NOTE for more information, see issue #71668
|
|
|
|
//~| NOTE consult the function's documentation
|
2023-12-07 05:56:48 -06:00
|
|
|
//~| ERROR call to unsafe function `unsf` is unsafe
|
2024-01-13 17:06:34 -06:00
|
|
|
//~| NOTE call to unsafe function
|
|
|
|
//~| NOTE for more information, see issue #71668
|
|
|
|
//~| NOTE consult the function's documentation
|
2023-06-11 04:59:15 -05:00
|
|
|
|
|
|
|
pub unsafe fn unsafe_in_macro() { unsafe {
|
|
|
|
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
|
|
|
unsafe_macro!();
|
2024-01-13 17:06:34 -06:00
|
|
|
//~^ NOTE in this expansion
|
|
|
|
//~| NOTE in this expansion
|
|
|
|
//~| NOTE in this expansion
|
2023-06-11 04:59:15 -05:00
|
|
|
unsafe_macro!();
|
2024-01-13 17:06:34 -06:00
|
|
|
//~^ NOTE in this expansion
|
|
|
|
//~| NOTE in this expansion
|
|
|
|
//~| NOTE in this expansion
|
2023-06-11 04:59:15 -05:00
|
|
|
}}
|
|
|
|
|
|
|
|
pub unsafe fn unsafe_in_external_macro() {
|
|
|
|
// FIXME: https://github.com/rust-lang/rust/issues/112504
|
|
|
|
// FIXME: ~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
|
|
|
external_unsafe_macro::unsafe_macro!();
|
|
|
|
external_unsafe_macro::unsafe_macro!();
|
|
|
|
}
|
|
|
|
|
2022-07-27 17:03:16 -05:00
|
|
|
fn main() {}
|