about summary refs log tree commit diff
path: root/tests/ui/coercion/ptr-mutability-errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/coercion/ptr-mutability-errors.rs')
-rw-r--r--tests/ui/coercion/ptr-mutability-errors.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/ui/coercion/ptr-mutability-errors.rs b/tests/ui/coercion/ptr-mutability-errors.rs
new file mode 100644
index 00000000000..2549bd6f134
--- /dev/null
+++ b/tests/ui/coercion/ptr-mutability-errors.rs
@@ -0,0 +1,25 @@
+// Test coercions between pointers which don't do anything fancy like unsizing.
+// These are testing that we don't lose mutability when converting to raw pointers.
+
+//@ dont-require-annotations: NOTE
+
+pub fn main() {
+    // *const -> *mut
+    let x: *const isize = &42;
+    let x: *mut isize = x; //~  ERROR mismatched types
+                           //~| NOTE expected raw pointer `*mut isize`
+                           //~| NOTE found raw pointer `*const isize`
+                           //~| NOTE types differ in mutability
+
+    // & -> *mut
+    let x: *mut isize = &42; //~  ERROR mismatched types
+                             //~| NOTE expected raw pointer `*mut isize`
+                             //~| NOTE found reference `&isize`
+                             //~| NOTE types differ in mutability
+
+    let x: *const isize = &42;
+    let x: *mut isize = x; //~  ERROR mismatched types
+                           //~| NOTE expected raw pointer `*mut isize`
+                           //~| NOTE found raw pointer `*const isize`
+                           //~| NOTE types differ in mutability
+}