Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2aa9aaa

Browse files
committed
Add borrow-check test
1 parent f10803c commit 2aa9aaa

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/test/ui/asm/bad-reg.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | asm!("{:z}", in(reg) foo);
1818
| |
1919
| template modifier
2020
|
21-
= note: the `reg` register class supports the following template modifiers: `l`, `h`, `x`, `e`, `r`
21+
= note: the `reg` register class supports the following template modifiers: `l`, `x`, `e`, `r`
2222

2323
error: invalid asm template modifier for this register class
2424
--> $DIR/bad-reg.rs:18:15

src/test/ui/asm/type-check-4.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// only-x86_64
2+
3+
#![feature(asm)]
4+
5+
fn main() {
6+
unsafe {
7+
// Can't output to borrowed values.
8+
9+
let mut a = 0isize;
10+
let p = &a;
11+
asm!("{}", out(reg) a);
12+
//~^ cannot assign to `a` because it is borrowed
13+
println!("{}", p);
14+
15+
// Can't read from mutable borrowed values.
16+
17+
let mut a = 0isize;
18+
let p = &mut a;
19+
asm!("{}", in(reg) a);
20+
//~^ cannot use `a` because it was mutably borrowed
21+
println!("{}", p);
22+
}
23+
}

src/test/ui/asm/type-check-4.stderr

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0506]: cannot assign to `a` because it is borrowed
2+
--> $DIR/type-check-4.rs:11:9
3+
|
4+
LL | let p = &a;
5+
| -- borrow of `a` occurs here
6+
LL | asm!("{}", out(reg) a);
7+
| ^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `a` occurs here
8+
LL |
9+
LL | println!("{}", p);
10+
| - borrow later used here
11+
12+
error[E0503]: cannot use `a` because it was mutably borrowed
13+
--> $DIR/type-check-4.rs:19:28
14+
|
15+
LL | let p = &mut a;
16+
| ------ borrow of `a` occurs here
17+
LL | asm!("{}", in(reg) a);
18+
| ^ use of borrowed `a`
19+
LL |
20+
LL | println!("{}", p);
21+
| - borrow later used here
22+
23+
error: aborting due to 2 previous errors
24+
25+
Some errors have detailed explanations: E0503, E0506.
26+
For more information about an error, try `rustc --explain E0503`.

0 commit comments

Comments
 (0)