Add borrow-check test
This commit is contained in:
parent
f10803c81c
commit
2aa9aaada5
3 changed files with 50 additions and 1 deletions
|
@ -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
|
||||
|
|
23
src/test/ui/asm/type-check-4.rs
Normal file
23
src/test/ui/asm/type-check-4.rs
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
26
src/test/ui/asm/type-check-4.stderr
Normal file
26
src/test/ui/asm/type-check-4.stderr
Normal file
|
@ -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`.
|
Loading…
Add table
Reference in a new issue