summaryrefslogtreecommitdiffstats
path: root/tests/ui/unsafe
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/unsafe')
-rw-r--r--tests/ui/unsafe/foreign-unsafe-fn-called.mir.stderr11
-rw-r--r--tests/ui/unsafe/foreign-unsafe-fn-called.rs14
-rw-r--r--tests/ui/unsafe/foreign-unsafe-fn-called.thir.stderr11
-rw-r--r--tests/ui/unsafe/new-unsafe-pointers.rs7
-rw-r--r--tests/ui/unsafe/unsafe-fn-called-from-unsafe-blk.rs18
-rw-r--r--tests/ui/unsafe/unsafe-fn-called-from-unsafe-fn.rs17
-rw-r--r--tests/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr28
-rw-r--r--tests/ui/unsafe/unsafe-fn-deref-ptr.rs3
-rw-r--r--tests/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr28
-rw-r--r--tests/ui/unsafe/unsafe-pointer-assignability.rs11
10 files changed, 144 insertions, 4 deletions
diff --git a/tests/ui/unsafe/foreign-unsafe-fn-called.mir.stderr b/tests/ui/unsafe/foreign-unsafe-fn-called.mir.stderr
new file mode 100644
index 000000000..d3cf5d84f
--- /dev/null
+++ b/tests/ui/unsafe/foreign-unsafe-fn-called.mir.stderr
@@ -0,0 +1,11 @@
+error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
+ --> $DIR/foreign-unsafe-fn-called.rs:11:5
+ |
+LL | test::free();
+ | ^^^^^^^^^^^^ call to unsafe function
+ |
+ = note: consult the function's documentation for information on how to avoid undefined behavior
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/unsafe/foreign-unsafe-fn-called.rs b/tests/ui/unsafe/foreign-unsafe-fn-called.rs
new file mode 100644
index 000000000..67302ea1b
--- /dev/null
+++ b/tests/ui/unsafe/foreign-unsafe-fn-called.rs
@@ -0,0 +1,14 @@
+// revisions: mir thir
+// [thir]compile-flags: -Z thir-unsafeck
+
+mod test {
+ extern "C" {
+ pub fn free();
+ }
+}
+
+fn main() {
+ test::free();
+ //[mir]~^ ERROR call to unsafe function is unsafe
+ //[thir]~^^ ERROR call to unsafe function `test::free` is unsafe
+}
diff --git a/tests/ui/unsafe/foreign-unsafe-fn-called.thir.stderr b/tests/ui/unsafe/foreign-unsafe-fn-called.thir.stderr
new file mode 100644
index 000000000..00ba0f7a6
--- /dev/null
+++ b/tests/ui/unsafe/foreign-unsafe-fn-called.thir.stderr
@@ -0,0 +1,11 @@
+error[E0133]: call to unsafe function `test::free` is unsafe and requires unsafe function or block
+ --> $DIR/foreign-unsafe-fn-called.rs:11:5
+ |
+LL | test::free();
+ | ^^^^^^^^^^^^ call to unsafe function
+ |
+ = note: consult the function's documentation for information on how to avoid undefined behavior
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/unsafe/new-unsafe-pointers.rs b/tests/ui/unsafe/new-unsafe-pointers.rs
new file mode 100644
index 000000000..d99eb4cbd
--- /dev/null
+++ b/tests/ui/unsafe/new-unsafe-pointers.rs
@@ -0,0 +1,7 @@
+// run-pass
+// pretty-expanded FIXME #23616
+
+fn main() {
+ let _a: *const isize = 3 as *const isize;
+ let _a: *mut isize = 3 as *mut isize;
+}
diff --git a/tests/ui/unsafe/unsafe-fn-called-from-unsafe-blk.rs b/tests/ui/unsafe/unsafe-fn-called-from-unsafe-blk.rs
new file mode 100644
index 000000000..3713a7065
--- /dev/null
+++ b/tests/ui/unsafe/unsafe-fn-called-from-unsafe-blk.rs
@@ -0,0 +1,18 @@
+// run-pass
+
+#![allow(dead_code)]
+//
+// See also: ui/unsafe/unsafe-fn-called-from-safe.rs
+
+// pretty-expanded FIXME #23616
+
+unsafe fn f() { return; }
+
+fn g() {
+ unsafe {
+ f();
+ }
+}
+
+pub fn main() {
+}
diff --git a/tests/ui/unsafe/unsafe-fn-called-from-unsafe-fn.rs b/tests/ui/unsafe/unsafe-fn-called-from-unsafe-fn.rs
new file mode 100644
index 000000000..5e9531076
--- /dev/null
+++ b/tests/ui/unsafe/unsafe-fn-called-from-unsafe-fn.rs
@@ -0,0 +1,17 @@
+// run-pass
+
+#![allow(dead_code)]
+//
+// See also: ui/unsafe/unsafe-fn-called-from-safe.rs
+
+// pretty-expanded FIXME #23616
+
+unsafe fn f() { return; }
+
+unsafe fn g() {
+ f();
+}
+
+pub fn main() {
+ return;
+}
diff --git a/tests/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr b/tests/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr
index a26149924..7f1e7c890 100644
--- a/tests/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr
+++ b/tests/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr
@@ -1,11 +1,35 @@
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
- --> $DIR/unsafe-fn-deref-ptr.rs:5:12
+ --> $DIR/unsafe-fn-deref-ptr.rs:5:13
+ |
+LL | let _ = *p;
+ | ^^ 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[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
+ --> $DIR/unsafe-fn-deref-ptr.rs:6:17
+ |
+LL | let _: u8 = *p;
+ | ^^ 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[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
+ --> $DIR/unsafe-fn-deref-ptr.rs:7:9
+ |
+LL | _ = *p;
+ | ^^ 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[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
+ --> $DIR/unsafe-fn-deref-ptr.rs:8:12
|
LL | return *p;
| ^^ 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: aborting due to previous error
+error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/unsafe/unsafe-fn-deref-ptr.rs b/tests/ui/unsafe/unsafe-fn-deref-ptr.rs
index dc989535b..4b7c6bf69 100644
--- a/tests/ui/unsafe/unsafe-fn-deref-ptr.rs
+++ b/tests/ui/unsafe/unsafe-fn-deref-ptr.rs
@@ -2,6 +2,9 @@
// [thir]compile-flags: -Z thir-unsafeck
fn f(p: *const u8) -> u8 {
+ let _ = *p; //~ ERROR dereference of raw pointer is unsafe
+ let _: u8 = *p; //~ ERROR dereference of raw pointer is unsafe
+ _ = *p; //~ ERROR dereference of raw pointer is unsafe
return *p; //~ ERROR dereference of raw pointer is unsafe
}
diff --git a/tests/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr b/tests/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr
index a26149924..7f1e7c890 100644
--- a/tests/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr
+++ b/tests/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr
@@ -1,11 +1,35 @@
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
- --> $DIR/unsafe-fn-deref-ptr.rs:5:12
+ --> $DIR/unsafe-fn-deref-ptr.rs:5:13
+ |
+LL | let _ = *p;
+ | ^^ 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[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
+ --> $DIR/unsafe-fn-deref-ptr.rs:6:17
+ |
+LL | let _: u8 = *p;
+ | ^^ 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[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
+ --> $DIR/unsafe-fn-deref-ptr.rs:7:9
+ |
+LL | _ = *p;
+ | ^^ 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[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
+ --> $DIR/unsafe-fn-deref-ptr.rs:8:12
|
LL | return *p;
| ^^ 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: aborting due to previous error
+error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/unsafe/unsafe-pointer-assignability.rs b/tests/ui/unsafe/unsafe-pointer-assignability.rs
new file mode 100644
index 000000000..db822bb6a
--- /dev/null
+++ b/tests/ui/unsafe/unsafe-pointer-assignability.rs
@@ -0,0 +1,11 @@
+// run-pass
+
+fn f(x: *const isize) {
+ unsafe {
+ assert_eq!(*x, 3);
+ }
+}
+
+pub fn main() {
+ f(&3);
+}