1 //! A simple test for testing many permutations of allowedness of
6 fn in_parameters(_: impl Debug) { panic!() }
9 fn in_return() -> impl Debug { panic!() }
12 fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() }
15 fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
16 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
19 fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
20 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
23 fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() }
24 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
27 fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
28 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
31 fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
32 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
35 fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
36 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
39 fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
40 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
43 fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() }
44 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
47 fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
48 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
49 //~^^ ERROR nested `impl Trait` is not allowed
52 fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
53 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
56 fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
57 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
58 //~| ERROR nested `impl Trait` is not allowed
61 fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() }
62 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
65 fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
66 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
69 fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() }
70 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
74 fn in_impl_Trait_in_parameters(_: impl Iterator<Item = impl Iterator>) { panic!() }
77 fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> {
78 vec![vec![0; 10], vec![12; 7], vec![8; 3]]
82 struct InBraceStructField { x: impl Debug }
83 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
86 struct InAdtInBraceStructField { x: Vec<impl Debug> }
87 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
90 struct InTupleStructField(impl Debug);
91 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
95 InBraceVariant { x: impl Debug },
96 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
97 InTupleVariant(impl Debug),
98 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
102 trait InTraitDefnParameters {
103 fn in_parameters(_: impl Debug);
107 trait InTraitDefnReturn {
108 fn in_return() -> impl Debug;
109 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
112 // Allowed and disallowed in trait impls
115 fn in_trait_impl_parameter(_: impl Debug);
116 fn in_trait_impl_return() -> Self::Out;
118 impl DummyTrait for () {
119 type Out = impl Debug;
120 //~^ ERROR `impl Trait` in type aliases is unstable
122 fn in_trait_impl_parameter(_: impl Debug) { }
125 fn in_trait_impl_return() -> impl Debug { () }
126 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
132 fn in_inherent_impl_parameters(_: impl Debug) { }
133 fn in_inherent_impl_return() -> impl Debug { () }
138 fn in_foreign_parameters(_: impl Debug);
139 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
141 fn in_foreign_return() -> impl Debug;
142 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
146 extern "C" fn in_extern_fn_parameters(_: impl Debug) {
150 extern "C" fn in_extern_fn_return() -> impl Debug {
154 type InTypeAlias<R> = impl Debug;
155 //~^ ERROR `impl Trait` in type aliases is unstable
157 type InReturnInTypeAlias<R> = fn() -> impl Debug;
158 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
159 //~| ERROR `impl Trait` in type aliases is unstable
161 // Disallowed in impl headers
162 impl PartialEq<impl Debug> for () {
163 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
166 // Disallowed in impl headers
167 impl PartialEq<()> for impl Debug {
168 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
171 // Disallowed in inherent impls
173 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
176 // Disallowed in inherent impls
177 struct InInherentImplAdt<T> { t: T }
178 impl InInherentImplAdt<impl Debug> {
179 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
182 // Disallowed in where clauses
183 fn in_fn_where_clause()
184 where impl Debug: Debug
185 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
189 // Disallowed in where clauses
190 fn in_adt_in_fn_where_clause()
191 where Vec<impl Debug>: Debug
192 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
197 fn in_trait_parameter_in_fn_where_clause<T>()
198 where T: PartialEq<impl Debug>
199 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
204 fn in_Fn_parameter_in_fn_where_clause<T>()
205 where T: Fn(impl Debug)
206 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
211 fn in_Fn_return_in_fn_where_clause<T>()
212 where T: Fn() -> impl Debug
213 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
218 struct InStructGenericParamDefault<T = impl Debug>(T);
219 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
222 enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) }
223 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
226 trait InTraitGenericParamDefault<T = impl Debug> {}
227 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
230 type InTypeAliasGenericParamDefault<T = impl Debug> = T;
231 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
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
237 //~| ERROR `impl Trait` only allowed in function and inherent method return types
238 //~| ERROR no nominal type found
241 fn in_method_generic_param_default<T = impl Debug>(_: T) {}
242 //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
243 //~| WARNING this was previously accepted by the compiler but is being phased out
244 //~| ERROR `impl Trait` only allowed in function and inherent method return types
247 let _in_local_variable: impl Fn() = || {};
248 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
249 let _in_return_in_local_variable = || -> impl Fn() { || {} };
250 //~^ ERROR `impl Trait` only allowed in function and inherent method return types