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