]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-asm.rs
Rollup merge of #88090 - nbdd0121:inference, r=nikomatsakis
[rust.git] / src / test / ui / borrowck / borrowck-asm.rs
1 // ignore-s390x
2 // ignore-emscripten
3 // ignore-powerpc
4 // ignore-powerpc64
5 // ignore-powerpc64le
6 // ignore-riscv64
7 // ignore-sparc
8 // ignore-sparc64
9
10 #![feature(llvm_asm)]
11 #![allow(deprecated)] // llvm_asm!
12
13 #[cfg(any(target_arch = "x86",
14             target_arch = "x86_64",
15             target_arch = "arm",
16             target_arch = "aarch64",
17             target_arch = "mips",
18             target_arch = "mips64"))]
19 mod test_cases {
20     fn is_move() {
21         let y: &mut isize;
22         let x = &mut 0isize;
23         unsafe {
24             llvm_asm!("nop" : : "r"(x));
25         }
26         let z = x;  //~ ERROR use of moved value: `x`
27     }
28
29     fn in_is_read() {
30         let mut x = 3;
31         let y = &mut x;
32         unsafe {
33             llvm_asm!("nop" : : "r"(x)); //~ ERROR cannot use
34         }
35         let z = y;
36     }
37
38     fn out_is_assign() {
39         let x = 3;
40         unsafe {
41             llvm_asm!("nop" : "=r"(x));  //~ ERROR cannot assign twice
42         }
43         let mut a = &mut 3;
44         let b = &*a;
45         unsafe {
46             llvm_asm!("nop" : "=r"(a));  // OK, Shallow write to `a`
47         }
48         let c = b;
49         let d = *a;
50     }
51
52     fn rw_is_assign() {
53         let x = 3;
54         unsafe {
55             llvm_asm!("nop" : "+r"(x));  //~ ERROR cannot assign twice
56         }
57     }
58
59     fn indirect_is_not_init() {
60         let x: i32;
61         unsafe {
62             llvm_asm!("nop" : "=*r"(x)); //~ ERROR use of possibly-uninitialized variable
63         }
64     }
65
66     fn rw_is_read() {
67         let mut x = &mut 3;
68         let y = &*x;
69         unsafe {
70             llvm_asm!("nop" : "+r"(x));  //~ ERROR cannot assign to `x` because it is borrowed
71         }
72         let z = y;
73     }
74
75     fn two_moves() {
76         let x = &mut 2;
77         unsafe {
78             llvm_asm!("nop" : : "r"(x), "r"(x) );    //~ ERROR use of moved value
79         }
80     }
81 }
82
83 fn main() {}