summaryrefslogtreecommitdiffstats
path: root/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /tests/ui/unsafe/wrapping-unsafe-block-sugg.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/unsafe/wrapping-unsafe-block-sugg.rs')
-rw-r--r--tests/ui/unsafe/wrapping-unsafe-block-sugg.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs b/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs
new file mode 100644
index 000000000..9c6be4589
--- /dev/null
+++ b/tests/ui/unsafe/wrapping-unsafe-block-sugg.rs
@@ -0,0 +1,66 @@
+// run-rustfix
+// aux-build:external_unsafe_macro.rs
+
+#![deny(unsafe_op_in_unsafe_fn)] //~ NOTE
+
+extern crate external_unsafe_macro;
+
+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
+}
+
+macro_rules! unsafe_macro { () => (unsf()) }
+//~^ ERROR call to unsafe function is unsafe
+//~| NOTE
+//~| NOTE
+//~| ERROR call to unsafe function is unsafe
+//~| NOTE
+//~| NOTE
+
+pub unsafe fn unsafe_in_macro() {
+ //~^ NOTE an unsafe function restricts its caller, but its body is safe by default
+ unsafe_macro!();
+ //~^ NOTE
+ //~| NOTE
+ unsafe_macro!();
+ //~^ NOTE
+ //~| NOTE
+}
+
+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!();
+}
+
+fn main() {}