]>
Commit | Line | Data |
---|---|---|
abe05a73 XL |
1 | //! A simple test for testing many permutations of allowedness of |
2 | //! impl Trait | |
abe05a73 XL |
3 | use std::fmt::Debug; |
4 | ||
5 | // Allowed | |
6 | fn in_parameters(_: impl Debug) { panic!() } | |
7 | ||
8 | // Allowed | |
9 | fn in_return() -> impl Debug { panic!() } | |
10 | ||
11 | // Allowed | |
12 | fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() } | |
13 | ||
abe05a73 XL |
14 | // Disallowed |
15 | fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() } | |
136023e0 | 16 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
17 | |
18 | // Disallowed | |
19 | fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() } | |
136023e0 | 20 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
21 | |
22 | // Disallowed | |
23 | fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() } | |
136023e0 | 24 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
25 | |
26 | // Disallowed | |
27 | fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() } | |
136023e0 | 28 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
29 | |
30 | // Disallowed | |
31 | fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() } | |
136023e0 | 32 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
33 | |
34 | // Disallowed | |
35 | fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() } | |
136023e0 | 36 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
37 | |
38 | // Disallowed | |
39 | fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() } | |
136023e0 | 40 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
41 | |
42 | // Disallowed | |
43 | fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() } | |
136023e0 | 44 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
45 | |
46 | // Disallowed | |
47 | fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() } | |
136023e0 | 48 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
0531ce1d | 49 | //~^^ ERROR nested `impl Trait` is not allowed |
abe05a73 XL |
50 | |
51 | // Disallowed | |
52 | fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() } | |
136023e0 | 53 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
54 | |
55 | // Disallowed | |
56 | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } | |
136023e0 | 57 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
e74abb32 | 58 | //~| ERROR nested `impl Trait` is not allowed |
abe05a73 XL |
59 | |
60 | // Disallowed | |
61 | fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() } | |
136023e0 | 62 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
63 | |
64 | // Disallowed | |
65 | fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() } | |
136023e0 | 66 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
67 | |
68 | // Disallowed | |
69 | fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() } | |
136023e0 | 70 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
71 | |
72 | ||
73 | // Allowed | |
74 | fn in_impl_Trait_in_parameters(_: impl Iterator<Item = impl Iterator>) { panic!() } | |
75 | ||
76 | // Allowed | |
77 | fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> { | |
78 | vec![vec![0; 10], vec![12; 7], vec![8; 3]] | |
79 | } | |
80 | ||
81 | // Disallowed | |
82 | struct InBraceStructField { x: impl Debug } | |
136023e0 | 83 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
84 | |
85 | // Disallowed | |
86 | struct InAdtInBraceStructField { x: Vec<impl Debug> } | |
136023e0 | 87 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
88 | |
89 | // Disallowed | |
90 | struct InTupleStructField(impl Debug); | |
136023e0 | 91 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
92 | |
93 | // Disallowed | |
94 | enum InEnum { | |
95 | InBraceVariant { x: impl Debug }, | |
136023e0 | 96 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 | 97 | InTupleVariant(impl Debug), |
136023e0 | 98 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
99 | } |
100 | ||
101 | // Allowed | |
102 | trait InTraitDefnParameters { | |
103 | fn in_parameters(_: impl Debug); | |
104 | } | |
105 | ||
106 | // Disallowed | |
107 | trait InTraitDefnReturn { | |
108 | fn in_return() -> impl Debug; | |
136023e0 | 109 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
110 | } |
111 | ||
112 | // Allowed and disallowed in trait impls | |
113 | trait DummyTrait { | |
114 | type Out; | |
b7449926 | 115 | fn in_trait_impl_parameter(_: impl Debug); |
abe05a73 XL |
116 | fn in_trait_impl_return() -> Self::Out; |
117 | } | |
118 | impl DummyTrait for () { | |
119 | type Out = impl Debug; | |
416331ca | 120 | //~^ ERROR `impl Trait` in type aliases is unstable |
abe05a73 XL |
121 | |
122 | fn in_trait_impl_parameter(_: impl Debug) { } | |
123 | // Allowed | |
124 | ||
125 | fn in_trait_impl_return() -> impl Debug { () } | |
136023e0 | 126 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
127 | } |
128 | ||
129 | // Allowed | |
130 | struct DummyType; | |
131 | impl DummyType { | |
132 | fn in_inherent_impl_parameters(_: impl Debug) { } | |
133 | fn in_inherent_impl_return() -> impl Debug { () } | |
134 | } | |
135 | ||
136 | // Disallowed | |
137 | extern "C" { | |
138 | fn in_foreign_parameters(_: impl Debug); | |
136023e0 | 139 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
140 | |
141 | fn in_foreign_return() -> impl Debug; | |
136023e0 | 142 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
143 | } |
144 | ||
145 | // Allowed | |
146 | extern "C" fn in_extern_fn_parameters(_: impl Debug) { | |
147 | } | |
148 | ||
149 | // Allowed | |
150 | extern "C" fn in_extern_fn_return() -> impl Debug { | |
151 | 22 | |
152 | } | |
153 | ||
154 | type InTypeAlias<R> = impl Debug; | |
416331ca | 155 | //~^ ERROR `impl Trait` in type aliases is unstable |
abe05a73 XL |
156 | |
157 | type InReturnInTypeAlias<R> = fn() -> impl Debug; | |
136023e0 | 158 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
60c5eb7d | 159 | //~| ERROR `impl Trait` in type aliases is unstable |
abe05a73 XL |
160 | |
161 | // Disallowed in impl headers | |
162 | impl PartialEq<impl Debug> for () { | |
136023e0 | 163 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
164 | } |
165 | ||
166 | // Disallowed in impl headers | |
167 | impl PartialEq<()> for impl Debug { | |
136023e0 | 168 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
169 | } |
170 | ||
171 | // Disallowed in inherent impls | |
172 | impl impl Debug { | |
136023e0 | 173 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
174 | } |
175 | ||
176 | // Disallowed in inherent impls | |
177 | struct InInherentImplAdt<T> { t: T } | |
178 | impl InInherentImplAdt<impl Debug> { | |
136023e0 | 179 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
180 | } |
181 | ||
182 | // Disallowed in where clauses | |
183 | fn in_fn_where_clause() | |
184 | where impl Debug: Debug | |
136023e0 | 185 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
186 | { |
187 | } | |
188 | ||
189 | // Disallowed in where clauses | |
190 | fn in_adt_in_fn_where_clause() | |
191 | where Vec<impl Debug>: Debug | |
136023e0 | 192 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
193 | { |
194 | } | |
195 | ||
196 | // Disallowed | |
197 | fn in_trait_parameter_in_fn_where_clause<T>() | |
198 | where T: PartialEq<impl Debug> | |
136023e0 | 199 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
200 | { |
201 | } | |
202 | ||
203 | // Disallowed | |
204 | fn in_Fn_parameter_in_fn_where_clause<T>() | |
205 | where T: Fn(impl Debug) | |
136023e0 | 206 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
207 | { |
208 | } | |
209 | ||
210 | // Disallowed | |
211 | fn in_Fn_return_in_fn_where_clause<T>() | |
212 | where T: Fn() -> impl Debug | |
136023e0 | 213 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 XL |
214 | { |
215 | } | |
216 | ||
cdc7bbd5 XL |
217 | // Disallowed |
218 | struct InStructGenericParamDefault<T = impl Debug>(T); | |
136023e0 | 219 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
cdc7bbd5 XL |
220 | |
221 | // Disallowed | |
222 | enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) } | |
136023e0 | 223 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
cdc7bbd5 XL |
224 | |
225 | // Disallowed | |
226 | trait InTraitGenericParamDefault<T = impl Debug> {} | |
136023e0 | 227 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
cdc7bbd5 XL |
228 | |
229 | // Disallowed | |
230 | type InTypeAliasGenericParamDefault<T = impl Debug> = T; | |
136023e0 | 231 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
cdc7bbd5 XL |
232 | |
233 | // Disallowed | |
234 | impl <T = impl Debug> T {} | |
235 | //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions | |
236 | //~| WARNING this was previously accepted by the compiler but is being phased out | |
136023e0 | 237 | //~| ERROR `impl Trait` not allowed outside of function and method return types |
cdc7bbd5 XL |
238 | |
239 | // Disallowed | |
240 | fn in_method_generic_param_default<T = impl Debug>(_: T) {} | |
241 | //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions | |
242 | //~| WARNING this was previously accepted by the compiler but is being phased out | |
136023e0 | 243 | //~| ERROR `impl Trait` not allowed outside of function and method return types |
cdc7bbd5 | 244 | |
abe05a73 XL |
245 | fn main() { |
246 | let _in_local_variable: impl Fn() = || {}; | |
136023e0 | 247 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 | 248 | let _in_return_in_local_variable = || -> impl Fn() { || {} }; |
136023e0 | 249 | //~^ ERROR `impl Trait` not allowed outside of function and method return types |
abe05a73 | 250 | } |