]> git.lizzy.rs Git - rust.git/blob - src/test/ui/test-attrs/test-on-not-fn.rs
:arrow_up: rust-analyzer
[rust.git] / src / test / ui / test-attrs / test-on-not-fn.rs
1 // compile-flags: --test
2
3 #[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
4 mod test {}
5
6 #[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
7 mod loooooooooooooong_teeeeeeeeeest {
8     /*
9     this is a comment
10     this comment goes on for a very long time
11     this is to pad out the span for this module for a long time
12     Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
13     labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
14     laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
15     voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
16     non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
17     */
18 }
19
20 #[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
21 extern "C" {}
22
23 #[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
24 trait Foo {}
25
26 #[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
27 impl Foo for i32 {}
28
29 #[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
30 const FOO: i32 = -1_i32;
31
32 #[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
33 static BAR: u64 = 10_000_u64;
34
35 #[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
36 enum MyUnit {
37     Unit,
38 }
39
40 #[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
41 struct NewI32(i32);
42
43 #[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
44 union Spooky {
45     x: i32,
46     y: u32,
47 }
48
49 #[repr(C, align(64))]
50 #[test] //~ ERROR: the `#[test]` attribute may only be used on a non-associated function
51 #[derive(Copy, Clone, Debug)]
52 struct MoreAttrs {
53     a: i32,
54     b: u64,
55 }
56
57 macro_rules! foo {
58     () => {};
59 }
60
61 #[test] //~ WARN: the `#[test]` attribute may only be used on a non-associated function
62 foo!();
63
64 // make sure it doesn't erroneously trigger on a real test
65 #[test]
66 fn real_test() {
67     assert_eq!(42_i32, 42_i32);
68 }
69
70 // make sure it works with cfg test
71 #[cfg(test)]
72 mod real_tests {
73     #[cfg(test)]
74     fn foo() {}
75
76     #[test]
77     fn bar() {
78         foo();
79     }
80 }