summaryrefslogtreecommitdiff
path: root/tests/ui/unsafe
diff options
context:
space:
mode:
authorWim Looman <git@nemo157.com>2023-05-27 14:37:18 +0200
committerWim Looman <git@nemo157.com>2023-06-13 15:47:02 +0200
commitaca61b2c07f2f7b644ca000385473af9de2d5f77 (patch)
tree8e1da0299c6fc1e42f14f5da8e1a25026b380307 /tests/ui/unsafe
parent975152ce30b8c0aa3cb7a3dca0a17c6c20e9db5b (diff)
Test that a couple more types of unsafe-ops get a wrapping unsafe block added
Diffstat (limited to 'tests/ui/unsafe')
-rw-r--r--tests/ui/unsafe/wrapping-unsafe-block-sugg.fixed11
-rw-r--r--tests/ui/unsafe/wrapping-unsafe-block-sugg.rs11
-rw-r--r--tests/ui/unsafe/wrapping-unsafe-block-sugg.stderr48
3 files changed, 69 insertions, 1 deletions
diff --git a/tests/ui/unsafe/wrapping-unsafe-block-sugg.fixed b/tests/ui/unsafe/wrapping-unsafe-block-sugg.fixed
index 81b7d68bc4a..c36aabb7c92 100644
--- a/tests/ui/unsafe/wrapping-unsafe-block-sugg.fixed
+++ b/tests/ui/unsafe/wrapping-unsafe-block-sugg.fixed
@@ -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() {}
diff --git a/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs b/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs
index ef6936d91d1..95e22d1bc4d 100644
--- a/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs
+++ b/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs
@@ -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() {}
diff --git a/tests/ui/unsafe/wrapping-unsafe-block-sugg.stderr b/tests/ui/unsafe/wrapping-unsafe-block-sugg.stderr
index 7283ee08bdf..b05d87069ab 100644
--- a/tests/ui/unsafe/wrapping-unsafe-block-sugg.stderr
+++ b/tests/ui/unsafe/wrapping-unsafe-block-sugg.stderr
@@ -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