]> git.lizzy.rs Git - rust.git/blob - src/test/ui/asm/type-check-1.rs
Merge commit '4a053f206fd6799a25823c307f7d7f9d897be118' into sync-rustfmt-subtree
[rust.git] / src / test / ui / asm / type-check-1.rs
1 // needs-asm-support
2 // ignore-nvptx64
3 // ignore-spirv
4 // ignore-wasm32
5
6 #![feature(asm_const)]
7
8 use std::arch::{asm, global_asm};
9
10 fn main() {
11     unsafe {
12         // Outputs must be place expressions
13
14         asm!("{}", in(reg) 1 + 2);
15         asm!("{}", out(reg) 1 + 2);
16         //~^ ERROR invalid asm output
17         asm!("{}", inout(reg) 1 + 2);
18         //~^ ERROR invalid asm output
19
20         // Operands must be sized
21
22         let v: [u64; 3] = [0, 1, 2];
23         asm!("{}", in(reg) v[..]);
24         //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
25         asm!("{}", out(reg) v[..]);
26         //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
27         asm!("{}", inout(reg) v[..]);
28         //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
29
30         // Constants must be... constant
31
32         let x = 0;
33         const fn const_foo(x: i32) -> i32 {
34             x
35         }
36         const fn const_bar<T>(x: T) -> T {
37             x
38         }
39         asm!("{}", const x);
40         //~^ ERROR attempt to use a non-constant value in a constant
41         asm!("{}", const const_foo(0));
42         asm!("{}", const const_foo(x));
43         //~^ ERROR attempt to use a non-constant value in a constant
44         asm!("{}", const const_bar(0));
45         asm!("{}", const const_bar(x));
46         //~^ ERROR attempt to use a non-constant value in a constant
47
48         // Const operands must be integers and must be constants.
49
50         asm!("{}", const 0);
51         asm!("{}", const 0i32);
52         asm!("{}", const 0i128);
53         asm!("{}", const 0f32);
54         //~^ ERROR mismatched types
55         asm!("{}", const 0 as *mut u8);
56         //~^ ERROR mismatched types
57         asm!("{}", const &0);
58         //~^ ERROR mismatched types
59     }
60 }
61
62 // Const operands must be integers and must be constants.
63
64 global_asm!("{}", const 0);
65 global_asm!("{}", const 0i32);
66 global_asm!("{}", const 0i128);
67 global_asm!("{}", const 0f32);
68 //~^ ERROR mismatched types
69 global_asm!("{}", const 0 as *mut u8);
70 //~^ ERROR mismatched types