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