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