summaryrefslogtreecommitdiff
path: root/tests/ui/unsafe
diff options
context:
space:
mode:
authorWim Looman <git@nemo157.com>2023-05-27 22:20:14 +0200
committerWim Looman <git@nemo157.com>2023-06-13 15:48:57 +0200
commit8f3e876e522f9ecc8f855485bb4857163c0f86e4 (patch)
tree35cabbf833c365a1aacd372192ed1db970904469 /tests/ui/unsafe
parent62a712a8bbb29a5d2f4e82b74d1ee5aa0490a5a3 (diff)
Add note about unsafe functions body not being unsafe
Diffstat (limited to 'tests/ui/unsafe')
-rw-r--r--tests/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.mir.stderr10
-rw-r--r--tests/ui/unsafe/wrapping-unsafe-block-sugg.fixed17
-rw-r--r--tests/ui/unsafe/wrapping-unsafe-block-sugg.rs17
-rw-r--r--tests/ui/unsafe/wrapping-unsafe-block-sugg.stderr27
4 files changed, 63 insertions, 8 deletions
diff --git a/tests/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.mir.stderr b/tests/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.mir.stderr
index 6f005fe8958..0c0826c1cfb 100644
--- a/tests/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.mir.stderr
+++ b/tests/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.mir.stderr
@@ -5,6 +5,11 @@ LL | unsf();
| ^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
+note: an unsafe function restricts its caller, but its body is safe by default
+ --> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:11:1
+ |
+LL | unsafe fn deny_level() {
+ | ^^^^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:4:9
|
@@ -46,6 +51,11 @@ LL | unsf();
| ^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
+note: an unsafe function restricts its caller, but its body is safe by default
+ --> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:27:1
+ |
+LL | unsafe fn warning_level() {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:26:8
|
diff --git a/tests/ui/unsafe/wrapping-unsafe-block-sugg.fixed b/tests/ui/unsafe/wrapping-unsafe-block-sugg.fixed
index c36aabb7c92..8fdc21ee109 100644
--- a/tests/ui/unsafe/wrapping-unsafe-block-sugg.fixed
+++ b/tests/ui/unsafe/wrapping-unsafe-block-sugg.fixed
@@ -1,23 +1,38 @@
// run-rustfix
-#![deny(unsafe_op_in_unsafe_fn)]
+#![deny(unsafe_op_in_unsafe_fn)] //~ NOTE
unsafe fn unsf() {}
pub unsafe fn foo() { unsafe {
+ //~^ NOTE an unsafe function restricts its caller, but its body is safe by default
unsf(); //~ ERROR call to unsafe function is unsafe
+ //~^ NOTE
+ //~| NOTE
unsf(); //~ ERROR call to unsafe function is unsafe
+ //~^ NOTE
+ //~| NOTE
}}
pub unsafe fn bar(x: *const i32) -> i32 { unsafe {
+ //~^ NOTE an unsafe function restricts its caller, but its body is safe by default
let y = *x; //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
+ //~^ NOTE
+ //~| NOTE
y + *x //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
+ //~^ NOTE
+ //~| NOTE
}}
static mut BAZ: i32 = 0;
pub unsafe fn baz() -> i32 { unsafe {
+ //~^ NOTE an unsafe function restricts its caller, but its body is safe by default
let y = BAZ; //~ ERROR use of mutable static is unsafe and requires unsafe block
+ //~^ NOTE
+ //~| NOTE
y + BAZ //~ ERROR use of mutable static is unsafe and requires unsafe block
+ //~^ NOTE
+ //~| NOTE
}}
fn main() {}
diff --git a/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs b/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs
index 95e22d1bc4d..0c6feee4ff2 100644
--- a/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs
+++ b/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs
@@ -1,23 +1,38 @@
// run-rustfix
-#![deny(unsafe_op_in_unsafe_fn)]
+#![deny(unsafe_op_in_unsafe_fn)] //~ NOTE
unsafe fn unsf() {}
pub unsafe fn foo() {
+ //~^ NOTE an unsafe function restricts its caller, but its body is safe by default
unsf(); //~ ERROR call to unsafe function is unsafe
+ //~^ NOTE
+ //~| NOTE
unsf(); //~ ERROR call to unsafe function is unsafe
+ //~^ NOTE
+ //~| NOTE
}
pub unsafe fn bar(x: *const i32) -> i32 {
+ //~^ NOTE an unsafe function restricts its caller, but its body is safe by default
let y = *x; //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
+ //~^ NOTE
+ //~| NOTE
y + *x //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
+ //~^ NOTE
+ //~| NOTE
}
static mut BAZ: i32 = 0;
pub unsafe fn baz() -> i32 {
+ //~^ NOTE an unsafe function restricts its caller, but its body is safe by default
let y = BAZ; //~ ERROR use of mutable static is unsafe and requires unsafe block
+ //~^ NOTE
+ //~| NOTE
y + BAZ //~ ERROR use of mutable static is unsafe and requires unsafe block
+ //~^ NOTE
+ //~| NOTE
}
fn main() {}
diff --git a/tests/ui/unsafe/wrapping-unsafe-block-sugg.stderr b/tests/ui/unsafe/wrapping-unsafe-block-sugg.stderr
index b22c5b74b56..76f86b09d68 100644
--- a/tests/ui/unsafe/wrapping-unsafe-block-sugg.stderr
+++ b/tests/ui/unsafe/wrapping-unsafe-block-sugg.stderr
@@ -1,10 +1,15 @@
error: call to unsafe function is unsafe and requires unsafe block (error E0133)
- --> $DIR/wrapping-unsafe-block-sugg.rs:8:5
+ --> $DIR/wrapping-unsafe-block-sugg.rs:9:5
|
LL | unsf();
| ^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
+note: an unsafe function restricts its caller, but its body is safe by default
+ --> $DIR/wrapping-unsafe-block-sugg.rs:7:1
+ |
+LL | pub unsafe fn foo() {
+ | ^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/wrapping-unsafe-block-sugg.rs:3:9
|
@@ -12,7 +17,7 @@ LL | #![deny(unsafe_op_in_unsafe_fn)]
| ^^^^^^^^^^^^^^^^^^^^^^
error: call to unsafe function is unsafe and requires unsafe block (error E0133)
- --> $DIR/wrapping-unsafe-block-sugg.rs:9:5
+ --> $DIR/wrapping-unsafe-block-sugg.rs:12:5
|
LL | unsf();
| ^^^^^^ call to unsafe function
@@ -20,15 +25,20 @@ LL | unsf();
= note: consult the function's documentation for information on how to avoid undefined behavior
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
- --> $DIR/wrapping-unsafe-block-sugg.rs:13:13
+ --> $DIR/wrapping-unsafe-block-sugg.rs:19: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
+note: an unsafe function restricts its caller, but its body is safe by default
+ --> $DIR/wrapping-unsafe-block-sugg.rs:17:1
+ |
+LL | pub unsafe fn bar(x: *const i32) -> i32 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
- --> $DIR/wrapping-unsafe-block-sugg.rs:14:9
+ --> $DIR/wrapping-unsafe-block-sugg.rs:22:9
|
LL | y + *x
| ^^ dereference of raw pointer
@@ -36,15 +46,20 @@ LL | y + *x
= 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
+ --> $DIR/wrapping-unsafe-block-sugg.rs:30: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
+note: an unsafe function restricts its caller, but its body is safe by default
+ --> $DIR/wrapping-unsafe-block-sugg.rs:28:1
+ |
+LL | pub unsafe fn baz() -> i32 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: use of mutable static is unsafe and requires unsafe block (error E0133)
- --> $DIR/wrapping-unsafe-block-sugg.rs:20:9
+ --> $DIR/wrapping-unsafe-block-sugg.rs:33:9
|
LL | y + BAZ
| ^^^ use of mutable static