]> git.lizzy.rs Git - rust.git/blob - src/test/ui/typeck/typeck_type_placeholder_item.rs
d1fb51e0fe2443e83b4f9d504e70ebdc8139de40
[rust.git] / src / test / ui / typeck / typeck_type_placeholder_item.rs
1 // This test checks that it is not possible to enable global type
2 // inference by using the `_` type placeholder.
3
4 fn test() -> _ { 5 }
5 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
6
7 fn test2() -> (_, _) { (5, 5) }
8 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
9
10 static TEST3: _ = "test";
11 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
12
13 static TEST4: _ = 145;
14 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
15
16 static TEST5: (_, _) = (1, 2);
17 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
18
19 fn test6(_: _) { }
20 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
21
22 fn test6_b<T>(_: _, _: T) { }
23 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
24
25 fn test6_c<T, K, L, A, B>(_: _, _: (T, K, L, A, B)) { }
26 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
27
28 fn test7(x: _) { let _x: usize = x; }
29 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
30
31 fn test8(_f: fn() -> _) { }
32 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
33
34 struct Test9;
35
36 impl Test9 {
37     fn test9(&self) -> _ { () }
38     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
39
40     fn test10(&self, _x : _) { }
41     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
42 }
43
44 impl Clone for Test9 {
45     fn clone(&self) -> _ { Test9 }
46     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
47
48     fn clone_from(&mut self, other: _) { *self = Test9; }
49     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
50 }
51
52 struct Test10 {
53     a: _,
54     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
55     b: (_, _),
56 }
57
58 pub fn main() {
59     fn fn_test() -> _ { 5 }
60     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
61
62     fn fn_test2() -> (_, _) { (5, 5) }
63     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
64
65     static FN_TEST3: _ = "test";
66     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
67
68     static FN_TEST4: _ = 145;
69     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
70
71     static FN_TEST5: (_, _) = (1, 2);
72     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
73
74     fn fn_test6(_: _) { }
75     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
76
77     fn fn_test7(x: _) { let _x: usize = x; }
78     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
79
80     fn fn_test8(_f: fn() -> _) { }
81     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
82
83     struct FnTest9;
84
85     impl FnTest9 {
86         fn fn_test9(&self) -> _ { () }
87         //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
88
89         fn fn_test10(&self, _x : _) { }
90         //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
91     }
92
93     impl Clone for FnTest9 {
94         fn clone(&self) -> _ { FnTest9 }
95         //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
96
97         fn clone_from(&mut self, other: _) { *self = FnTest9; }
98         //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
99     }
100
101     struct FnTest10 {
102         a: _,
103         //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
104         b: (_, _),
105     }
106
107     fn fn_test11(_: _) -> (_, _) { panic!() }
108     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
109     //~| ERROR type annotations needed
110
111     fn fn_test12(x: i32) -> (_, _) { (x, x) }
112     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
113
114     fn fn_test13(x: _) -> (i32, _) { (x, x) }
115     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
116 }
117
118 trait T {
119     fn method_test1(&self, x: _);
120     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
121     fn method_test2(&self, x: _) -> _;
122     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
123     fn method_test3(&self) -> _;
124     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
125     fn assoc_fn_test1(x: _);
126     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
127     fn assoc_fn_test2(x: _) -> _;
128     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
129     fn assoc_fn_test3() -> _;
130     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
131 }