]> git.proxmox.com Git - rustc.git/blob - src/test/ui/typeck/typeck_type_placeholder_item.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / typeck / typeck_type_placeholder_item.rs
1 // Needed for `type Y = impl Trait<_>` and `type B = _;`
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
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 for return types
12
13 fn test2() -> (_, _) { (5, 5) }
14 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for return types
15
16 static TEST3: _ = "test";
17 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for static variables
18
19 static TEST4: _ = 145;
20 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for static variables
21
22 static TEST5: (_, _) = (1, 2);
23 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for static variables
24
25 fn test6(_: _) { }
26 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
27
28 fn test6_b<T>(_: _, _: T) { }
29 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
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 for functions
33
34 fn test7(x: _) { let _x: usize = x; }
35 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
36
37 fn test8(_f: fn() -> _) { }
38 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
39 //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
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 for return types
46
47 fn test10(&self, _x : _) { }
48 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
49 }
50
51 fn test11(x: &usize) -> &_ {
52 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for return types
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 for return types
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 for return types
64
65 fn clone_from(&mut self, other: _) { *self = Test9; }
66 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
67 }
68
69 struct Test10 {
70 a: _,
71 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for structs
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 for static variables
80 static C: Option<_> = Some(42);
81 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for static variables
82 fn fn_test() -> _ { 5 }
83 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for return types
84
85 fn fn_test2() -> (_, _) { (5, 5) }
86 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for return types
87
88 static FN_TEST3: _ = "test";
89 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for static variables
90
91 static FN_TEST4: _ = 145;
92 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for static variables
93
94 static FN_TEST5: (_, _) = (1, 2);
95 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for static variables
96
97 fn fn_test6(_: _) { }
98 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
99
100 fn fn_test7(x: _) { let _x: usize = x; }
101 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
102
103 fn fn_test8(_f: fn() -> _) { }
104 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
105 //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
106
107 struct FnTest9;
108
109 impl FnTest9 {
110 fn fn_test9(&self) -> _ { () }
111 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for return types
112
113 fn fn_test10(&self, _x : _) { }
114 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
115 }
116
117 impl Clone for FnTest9 {
118 fn clone(&self) -> _ { FnTest9 }
119 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for return types
120
121 fn clone_from(&mut self, other: _) { *self = FnTest9; }
122 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
123 }
124
125 struct FnTest10 {
126 a: _,
127 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for structs
128 b: (_, _),
129 }
130
131 fn fn_test11(_: _) -> (_, _) { panic!() }
132 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for return types
133 //~| ERROR type annotations needed
134
135 fn fn_test12(x: i32) -> (_, _) { (x, x) }
136 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for return types
137
138 fn fn_test13(x: _) -> (i32, _) { (x, x) }
139 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for return types
140 }
141
142 trait T {
143 fn method_test1(&self, x: _);
144 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
145 fn method_test2(&self, x: _) -> _;
146 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
147 fn method_test3(&self) -> _;
148 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
149 fn assoc_fn_test1(x: _);
150 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
151 fn assoc_fn_test2(x: _) -> _;
152 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
153 fn assoc_fn_test3() -> _;
154 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for functions
155 }
156
157 struct BadStruct<_>(_);
158 //~^ ERROR expected identifier, found reserved identifier `_`
159 //~| ERROR the type placeholder `_` is not allowed within types on item signatures for structs
160 trait BadTrait<_> {}
161 //~^ ERROR expected identifier, found reserved identifier `_`
162 impl BadTrait<_> for BadStruct<_> {}
163 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for implementations
164
165 fn impl_trait() -> impl BadTrait<_> {
166 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for opaque types
167 unimplemented!()
168 }
169
170 struct BadStruct1<_, _>(_);
171 //~^ ERROR expected identifier, found reserved identifier `_`
172 //~| ERROR expected identifier, found reserved identifier `_`
173 //~| ERROR the name `_` is already used
174 //~| ERROR the type placeholder `_` is not allowed within types on item signatures for structs
175 struct BadStruct2<_, T>(_, T);
176 //~^ ERROR expected identifier, found reserved identifier `_`
177 //~| ERROR the type placeholder `_` is not allowed within types on item signatures for structs
178
179 type X = Box<_>;
180 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for type aliases
181
182 struct Struct;
183 trait Trait<T> {}
184 impl Trait<usize> for Struct {}
185 type Y = impl Trait<_>;
186 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for opaque types
187 fn foo() -> Y {
188 Struct
189 }
190
191 trait Qux {
192 type A;
193 type B = _;
194 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for associated types
195 const C: _;
196 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for constants
197 const D: _ = 42;
198 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for constants
199 // type E: _; // FIXME: make the parser propagate the existence of `B`
200 type F: std::ops::Fn(_);
201 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for associated types
202 }
203 impl Qux for Struct {
204 type A = _;
205 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for associated types
206 type B = _;
207 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for associated types
208 const C: _;
209 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for constants
210 //~| ERROR associated constant in `impl` without body
211 const D: _ = 42;
212 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for constants
213 }
214
215 fn map<T>(_: fn() -> Option<&'static T>) -> Option<T> {
216 None
217 }
218
219 fn value() -> Option<&'static _> {
220 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for return types
221 Option::<&'static u8>::None
222 }
223
224 const _: Option<_> = map(value);
225 //~^ ERROR the type placeholder `_` is not allowed within types on item signatures for constants