about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAmanieu d'Antras <amanieu@gmail.com>2020-05-08 01:15:56 +0100
committerAmanieu d'Antras <amanieu@gmail.com>2020-05-18 14:41:34 +0100
commit2aa9aaada5f7ebd0236bf7ebdbbce6ec8b684239 (patch)
tree329f5470a4a2b8f5ce576dceeac0e395b2cd5474 /src
parentf10803c81cf6417c2ebe982519fa7c4502cab2cf (diff)
downloadrust-2aa9aaada5f7ebd0236bf7ebdbbce6ec8b684239.tar.gz
rust-2aa9aaada5f7ebd0236bf7ebdbbce6ec8b684239.zip
Add borrow-check test
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/asm/bad-reg.stderr2
-rw-r--r--src/test/ui/asm/type-check-4.rs23
-rw-r--r--src/test/ui/asm/type-check-4.stderr26
3 files changed, 50 insertions, 1 deletions
diff --git a/src/test/ui/asm/bad-reg.stderr b/src/test/ui/asm/bad-reg.stderr
index a1423f0e9c1..c6b7d310dfa 100644
--- a/src/test/ui/asm/bad-reg.stderr
+++ b/src/test/ui/asm/bad-reg.stderr
@@ -18,7 +18,7 @@ LL |         asm!("{:z}", in(reg) foo);
    |               |
    |               template modifier
    |
-   = note: the `reg` register class supports the following template modifiers: `l`, `h`, `x`, `e`, `r`
+   = note: the `reg` register class supports the following template modifiers: `l`, `x`, `e`, `r`
 
 error: invalid asm template modifier for this register class
   --> $DIR/bad-reg.rs:18:15
diff --git a/src/test/ui/asm/type-check-4.rs b/src/test/ui/asm/type-check-4.rs
new file mode 100644
index 00000000000..2be627c1165
--- /dev/null
+++ b/src/test/ui/asm/type-check-4.rs
@@ -0,0 +1,23 @@
+// only-x86_64
+
+#![feature(asm)]
+
+fn main() {
+    unsafe {
+        // Can't output to borrowed values.
+
+        let mut a = 0isize;
+        let p = &a;
+        asm!("{}", out(reg) a);
+        //~^ cannot assign to `a` because it is borrowed
+        println!("{}", p);
+
+        // Can't read from mutable borrowed values.
+
+        let mut a = 0isize;
+        let p = &mut a;
+        asm!("{}", in(reg) a);
+        //~^ cannot use `a` because it was mutably borrowed
+        println!("{}", p);
+    }
+}
diff --git a/src/test/ui/asm/type-check-4.stderr b/src/test/ui/asm/type-check-4.stderr
new file mode 100644
index 00000000000..8035bbefc1a
--- /dev/null
+++ b/src/test/ui/asm/type-check-4.stderr
@@ -0,0 +1,26 @@
+error[E0506]: cannot assign to `a` because it is borrowed
+  --> $DIR/type-check-4.rs:11:9
+   |
+LL |         let p = &a;
+   |                 -- borrow of `a` occurs here
+LL |         asm!("{}", out(reg) a);
+   |         ^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `a` occurs here
+LL |
+LL |         println!("{}", p);
+   |                        - borrow later used here
+
+error[E0503]: cannot use `a` because it was mutably borrowed
+  --> $DIR/type-check-4.rs:19:28
+   |
+LL |         let p = &mut a;
+   |                 ------ borrow of `a` occurs here
+LL |         asm!("{}", in(reg) a);
+   |                            ^ use of borrowed `a`
+LL |
+LL |         println!("{}", p);
+   |                        - borrow later used here
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0503, E0506.
+For more information about an error, try `rustc --explain E0503`.