1 // Needed for `type Y = impl Trait<_>` and `type B = _;`
2 #![feature(associated_type_defaults)]
3 #![feature(type_alias_impl_trait)]
4 // This test checks that it is not possible to enable global type
5 // inference by using the `_` type placeholder.
8 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
10 fn test2() -> (_, _) { (5, 5) }
11 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
13 static TEST3: _ = "test";
14 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
16 static TEST4: _ = 145;
17 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
19 static TEST5: (_, _) = (1, 2);
20 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
23 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
25 fn test6_b<T>(_: _, _: T) { }
26 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
28 fn test6_c<T, K, L, A, B>(_: _, _: (T, K, L, A, B)) { }
29 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
31 fn test7(x: _) { let _x: usize = x; }
32 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
34 fn test8(_f: fn() -> _) { }
35 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
36 //~^^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
41 fn test9(&self) -> _ { () }
42 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
44 fn test10(&self, _x : _) { }
45 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
48 fn test11(x: &usize) -> &_ {
49 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
53 unsafe fn test12(x: *const usize) -> *const *const _ {
54 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
58 impl Clone for Test9 {
59 fn clone(&self) -> _ { Test9 }
60 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
62 fn clone_from(&mut self, other: _) { *self = Test9; }
63 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
68 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs
74 //~^ ERROR missing type for `static` item
76 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
77 static C: Option<_> = Some(42);
78 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
79 fn fn_test() -> _ { 5 }
80 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
82 fn fn_test2() -> (_, _) { (5, 5) }
83 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
85 static FN_TEST3: _ = "test";
86 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
88 static FN_TEST4: _ = 145;
89 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
91 static FN_TEST5: (_, _) = (1, 2);
92 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
95 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
97 fn fn_test7(x: _) { let _x: usize = x; }
98 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
100 fn fn_test8(_f: fn() -> _) { }
101 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
102 //~^^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
107 fn fn_test9(&self) -> _ { () }
108 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
110 fn fn_test10(&self, _x : _) { }
111 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
114 impl Clone for FnTest9 {
115 fn clone(&self) -> _ { FnTest9 }
116 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
118 fn clone_from(&mut self, other: _) { *self = FnTest9; }
119 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
124 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs
128 fn fn_test11(_: _) -> (_, _) { panic!() }
129 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
130 //~| ERROR type annotations needed
132 fn fn_test12(x: i32) -> (_, _) { (x, x) }
133 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
135 fn fn_test13(x: _) -> (i32, _) { (x, x) }
136 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
140 fn method_test1(&self, x: _);
141 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
142 fn method_test2(&self, x: _) -> _;
143 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
144 fn method_test3(&self) -> _;
145 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
146 fn assoc_fn_test1(x: _);
147 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
148 fn assoc_fn_test2(x: _) -> _;
149 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
150 fn assoc_fn_test3() -> _;
151 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
154 struct BadStruct<_>(_);
155 //~^ ERROR expected identifier, found reserved identifier `_`
156 //~| ERROR the placeholder `_` is not allowed within types on item signatures for structs
158 //~^ ERROR expected identifier, found reserved identifier `_`
159 impl BadTrait<_> for BadStruct<_> {}
160 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for implementations
162 fn impl_trait() -> impl BadTrait<_> {
163 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for opaque types
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 placeholder `_` is not allowed within types on item signatures for structs
172 struct BadStruct2<_, T>(_, T);
173 //~^ ERROR expected identifier, found reserved identifier `_`
174 //~| ERROR the placeholder `_` is not allowed within types on item signatures for structs
177 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for type aliases
181 impl Trait<usize> for Struct {}
182 type Y = impl Trait<_>;
183 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for opaque types
191 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types
193 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
195 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
196 // type E: _; // FIXME: make the parser propagate the existence of `B`
197 type F: std::ops::Fn(_);
198 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types
200 impl Qux for Struct {
202 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types
204 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types
206 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
207 //~| ERROR associated constant in `impl` without body
209 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
212 fn map<T>(_: fn() -> Option<&'static T>) -> Option<T> {
216 fn value() -> Option<&'static _> {
217 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
218 Option::<&'static u8>::None
221 const _: Option<_> = map(value);
222 //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants