]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-asm.rs
Rollup merge of #57132 - daxpedda:master, r=steveklabnik
[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-sparc
7 // ignore-sparc64
8
9 // revisions: ast mir
10 //[mir]compile-flags: -Z borrowck=mir
11
12 #![feature(asm)]
13
14 #[cfg(any(target_arch = "x86",
15             target_arch = "x86_64",
16             target_arch = "arm",
17             target_arch = "aarch64",
18             target_arch = "mips",
19             target_arch = "mips64"))]
20 mod test_cases {
21     fn is_move() {
22         let y: &mut isize;
23         let x = &mut 0isize;
24         unsafe {
25             asm!("nop" : : "r"(x));
26         }
27         let z = x;  //[ast]~ ERROR use of moved value: `x`
28                     //[mir]~^ ERROR use of moved value: `x`
29     }
30
31     fn in_is_read() {
32         let mut x = 3;
33         let y = &mut x;
34         unsafe {
35             asm!("nop" : : "r"(x)); //[ast]~ ERROR cannot use
36                                     //[mir]~^ ERROR cannot use
37         }
38         let z = y;
39     }
40
41     fn out_is_assign() {
42         let x = 3;
43         unsafe {
44             asm!("nop" : "=r"(x));  //[ast]~ ERROR cannot assign twice
45                                     //[mir]~^ ERROR cannot assign twice
46         }
47         let mut a = &mut 3;
48         let b = &*a;
49         unsafe {
50             asm!("nop" : "=r"(a));  //[ast]~ ERROR cannot assign to `a` because it is borrowed
51                                     // No MIR error, this is a shallow write.
52         }
53         let c = b;
54         let d = *a;
55     }
56
57     fn rw_is_assign() {
58         let x = 3;
59         unsafe {
60             asm!("nop" : "+r"(x));  //[ast]~ ERROR cannot assign twice
61                                     //[mir]~^ ERROR cannot assign twice
62         }
63     }
64
65     fn indirect_is_not_init() {
66         let x: i32;
67         unsafe {
68             asm!("nop" : "=*r"(x)); //[ast]~ ERROR use of possibly uninitialized variable
69                                     //[mir]~^ ERROR use of possibly uninitialized variable
70         }
71     }
72
73     fn rw_is_read() {
74         let mut x = &mut 3;
75         let y = &*x;
76         unsafe {
77             asm!("nop" : "+r"(x));  //[ast]~ ERROR cannot assign to `x` because it is borrowed
78                                     //[mir]~^ ERROR cannot assign to `x` because it is borrowed
79         }
80         let z = y;
81     }
82
83     fn two_moves() {
84         let x = &mut 2;
85         unsafe {
86             asm!("nop" : : "r"(x), "r"(x) );    //[ast]~ ERROR use of moved value
87                                                 //[mir]~^ ERROR use of moved value
88         }
89     }
90 }
91
92 fn main() {}