]> git.lizzy.rs Git - rust.git/blob - src/test/ui/typeck/typeck_type_placeholder_item.rs
Do not ICE on assoc type with bad placeholder
[rust.git] / src / test / ui / typeck / typeck_type_placeholder_item.rs
1 // Needed for `type Y = impl Trait<_>` and `type B = _;`
2 #![feature(type_alias_impl_trait, associated_type_defaults)]
3 // This test checks that it is not possible to enable global type
4 // inference by using the `_` type placeholder.
5
6 fn test() -> _ { 5 }
7 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
8
9 fn test2() -> (_, _) { (5, 5) }
10 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
11
12 static TEST3: _ = "test";
13 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
14
15 static TEST4: _ = 145;
16 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
17
18 static TEST5: (_, _) = (1, 2);
19 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
20
21 fn test6(_: _) { }
22 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
23
24 fn test6_b<T>(_: _, _: T) { }
25 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
26
27 fn test6_c<T, K, L, A, B>(_: _, _: (T, K, L, A, B)) { }
28 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
29
30 fn test7(x: _) { let _x: usize = x; }
31 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
32
33 fn test8(_f: fn() -> _) { }
34 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
35 //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
36
37 struct Test9;
38
39 impl Test9 {
40     fn test9(&self) -> _ { () }
41     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
42
43     fn test10(&self, _x : _) { }
44     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
45 }
46
47 fn test11(x: &usize) -> &_ {
48 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
49     &x
50 }
51
52 unsafe fn test12(x: *const usize) -> *const *const _ {
53 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
54     &x
55 }
56
57 impl Clone for Test9 {
58     fn clone(&self) -> _ { Test9 }
59     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
60
61     fn clone_from(&mut self, other: _) { *self = Test9; }
62     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
63 }
64
65 struct Test10 {
66     a: _,
67     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
68     b: (_, _),
69 }
70
71 pub fn main() {
72     static A = 42;
73     //~^ ERROR missing type for `static` item
74     static B: _ = 42;
75     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
76     static C: Option<_> = Some(42);
77     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
78
79     fn fn_test() -> _ { 5 }
80     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
81
82     fn fn_test2() -> (_, _) { (5, 5) }
83     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
84
85     static FN_TEST3: _ = "test";
86     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
87
88     static FN_TEST4: _ = 145;
89     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
90
91     static FN_TEST5: (_, _) = (1, 2);
92     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
93
94     fn fn_test6(_: _) { }
95     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
96
97     fn fn_test7(x: _) { let _x: usize = x; }
98     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
99
100     fn fn_test8(_f: fn() -> _) { }
101     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
102     //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
103
104     struct FnTest9;
105
106     impl FnTest9 {
107         fn fn_test9(&self) -> _ { () }
108         //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
109
110         fn fn_test10(&self, _x : _) { }
111         //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
112     }
113
114     impl Clone for FnTest9 {
115         fn clone(&self) -> _ { FnTest9 }
116         //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
117
118         fn clone_from(&mut self, other: _) { *self = FnTest9; }
119         //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
120     }
121
122     struct FnTest10 {
123         a: _,
124         //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
125         b: (_, _),
126     }
127
128     fn fn_test11(_: _) -> (_, _) { panic!() }
129     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
130     //~| ERROR type annotations needed
131
132     fn fn_test12(x: i32) -> (_, _) { (x, x) }
133     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
134
135     fn fn_test13(x: _) -> (i32, _) { (x, x) }
136     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
137 }
138
139 trait T {
140     fn method_test1(&self, x: _);
141     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
142     fn method_test2(&self, x: _) -> _;
143     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
144     fn method_test3(&self) -> _;
145     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
146     fn assoc_fn_test1(x: _);
147     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
148     fn assoc_fn_test2(x: _) -> _;
149     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
150     fn assoc_fn_test3() -> _;
151     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
152 }
153
154 struct BadStruct<_>(_);
155 //~^ ERROR expected identifier, found reserved identifier `_`
156 //~| ERROR the type placeholder `_` is not allowed within types on item signatures
157 trait BadTrait<_> {}
158 //~^ ERROR expected identifier, found reserved identifier `_`
159 impl BadTrait<_> for BadStruct<_> {}
160 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
161
162 fn impl_trait() -> impl BadTrait<_> {
163 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
164     unimplemented!()
165 }
166
167 struct BadStruct1<_, _>(_);
168 //~^ ERROR expected identifier, found reserved identifier `_`
169 //~| ERROR expected identifier, found reserved identifier `_`
170 //~| ERROR the name `_` is already used
171 //~| ERROR the type placeholder `_` is not allowed within types on item signatures
172 struct BadStruct2<_, T>(_, T);
173 //~^ ERROR expected identifier, found reserved identifier `_`
174 //~| ERROR the type placeholder `_` is not allowed within types on item signatures
175
176 type X = Box<_>;
177 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
178
179 struct Struct;
180 trait Trait<T> {}
181 impl Trait<usize> for Struct {}
182 type Y = impl Trait<_>;
183 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
184 fn foo() -> Y {
185     Struct
186 }
187
188 trait Qux {
189     type A;
190     type B = _;
191     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
192     const C: _;
193     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
194     const D: _ = 42;
195     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
196     // type E: _; // FIXME: make the parser propagate the existence of `B`
197     type F: std::ops::Fn(_);
198     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
199 }
200 impl Qux for Struct {
201     type A = _;
202     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
203     type B = _;
204     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
205     const C: _;
206     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
207     //~| ERROR associated constant in `impl` without body
208     const D: _ = 42;
209     //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
210 }