Test that a couple more types of unsafe-ops get a wrapping unsafe block added

This commit is contained in:
Wim Looman 2023-05-27 14:37:18 +02:00
parent 975152ce30
commit aca61b2c07
No known key found for this signature in database
GPG Key ID: C6F5748C6DD1607B
3 changed files with 69 additions and 1 deletions

View File

@ -9,4 +9,15 @@ pub unsafe fn foo() { unsafe {
unsf(); //~ ERROR call to unsafe function is unsafe
}}
pub unsafe fn bar(x: *const i32) -> i32 { unsafe {
let y = *x; //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
y + *x //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
}}
static mut BAZ: i32 = 0;
pub unsafe fn baz() -> i32 { unsafe {
let y = BAZ; //~ ERROR use of mutable static is unsafe and requires unsafe block
y + BAZ //~ ERROR use of mutable static is unsafe and requires unsafe block
}}
fn main() {}

View File

@ -9,4 +9,15 @@ pub unsafe fn foo() {
unsf(); //~ ERROR call to unsafe function is unsafe
}
pub unsafe fn bar(x: *const i32) -> i32 {
let y = *x; //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
y + *x //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
}
static mut BAZ: i32 = 0;
pub unsafe fn baz() -> i32 {
let y = BAZ; //~ ERROR use of mutable static is unsafe and requires unsafe block
y + BAZ //~ ERROR use of mutable static is unsafe and requires unsafe block
}
fn main() {}

View File

@ -26,5 +26,51 @@ LL | unsf();
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: aborting due to 2 previous errors
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
--> $DIR/wrapping-unsafe-block-sugg.rs:13:13
|
LL | let y = *x;
| ^^ dereference of raw pointer
|
= note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
help: consider wrapping the function body in an unsafe block
|
LL ~ pub unsafe fn bar(x: *const i32) -> i32 { unsafe {
LL | let y = *x;
LL | y + *x
LL ~ }}
|
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
--> $DIR/wrapping-unsafe-block-sugg.rs:14:9
|
LL | y + *x
| ^^ dereference of raw pointer
|
= note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
error: use of mutable static is unsafe and requires unsafe block (error E0133)
--> $DIR/wrapping-unsafe-block-sugg.rs:19:13
|
LL | let y = BAZ;
| ^^^ use of mutable static
|
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
help: consider wrapping the function body in an unsafe block
|
LL ~ pub unsafe fn baz() -> i32 { unsafe {
LL | let y = BAZ;
LL | y + BAZ
LL ~ }}
|
error: use of mutable static is unsafe and requires unsafe block (error E0133)
--> $DIR/wrapping-unsafe-block-sugg.rs:20:9
|
LL | y + BAZ
| ^^^ use of mutable static
|
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
error: aborting due to 6 previous errors