1 //! A simple test for testing many permutations of allowedness of
3 #![feature(impl_trait_in_fn_trait_return)]
7 fn in_parameters(_: impl Debug) { panic!() }
10 fn in_return() -> impl Debug { panic!() }
13 fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() }
16 fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
17 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
20 fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
21 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
24 fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() }
25 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
28 fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
29 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
32 fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
33 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
36 fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
37 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
40 fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
41 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
44 fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() }
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!() }
64 fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
65 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
68 fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() }
69 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
73 fn in_impl_Trait_in_parameters(_: impl Iterator<Item = impl Iterator>) { panic!() }
76 fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> {
77 vec![vec![0; 10], vec![12; 7], vec![8; 3]]
81 struct InBraceStructField { x: impl Debug }
82 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
85 struct InAdtInBraceStructField { x: Vec<impl Debug> }
86 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
89 struct InTupleStructField(impl Debug);
90 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
94 InBraceVariant { x: impl Debug },
95 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
96 InTupleVariant(impl Debug),
97 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
101 trait InTraitDefnParameters {
102 fn in_parameters(_: impl Debug);
106 trait InTraitDefnReturn {
107 fn in_return() -> impl Debug;
108 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
111 // Allowed and disallowed in trait impls
114 fn in_trait_impl_parameter(_: impl Debug);
115 fn in_trait_impl_return() -> Self::Out;
117 impl DummyTrait for () {
118 type Out = impl Debug;
119 //~^ ERROR `impl Trait` in type aliases is unstable
121 fn in_trait_impl_parameter(_: impl Debug) { }
124 fn in_trait_impl_return() -> impl Debug { () }
125 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
131 fn in_inherent_impl_parameters(_: impl Debug) { }
132 fn in_inherent_impl_return() -> impl Debug { () }
137 fn in_foreign_parameters(_: impl Debug);
138 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
140 fn in_foreign_return() -> impl Debug;
141 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
145 extern "C" fn in_extern_fn_parameters(_: impl Debug) {
149 extern "C" fn in_extern_fn_return() -> impl Debug {
153 type InTypeAlias<R> = impl Debug;
154 //~^ ERROR `impl Trait` in type aliases is unstable
156 type InReturnInTypeAlias<R> = fn() -> impl Debug;
157 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
158 //~| ERROR `impl Trait` in type aliases is unstable
160 // Disallowed in impl headers
161 impl PartialEq<impl Debug> for () {
162 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
165 // Disallowed in impl headers
166 impl PartialEq<()> for impl Debug {
167 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
170 // Disallowed in inherent impls
172 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
175 // Disallowed in inherent impls
176 struct InInherentImplAdt<T> { t: T }
177 impl InInherentImplAdt<impl Debug> {
178 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
181 // Disallowed in where clauses
182 fn in_fn_where_clause()
183 where impl Debug: Debug
184 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
188 // Disallowed in where clauses
189 fn in_adt_in_fn_where_clause()
190 where Vec<impl Debug>: Debug
191 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
196 fn in_trait_parameter_in_fn_where_clause<T>()
197 where T: PartialEq<impl Debug>
198 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
203 fn in_Fn_parameter_in_fn_where_clause<T>()
204 where T: Fn(impl Debug)
205 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
210 fn in_Fn_return_in_fn_where_clause<T>()
211 where T: Fn() -> impl Debug
212 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
217 struct InStructGenericParamDefault<T = impl Debug>(T);
218 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
221 enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) }
222 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
225 trait InTraitGenericParamDefault<T = impl Debug> {}
226 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
229 type InTypeAliasGenericParamDefault<T = impl Debug> = T;
230 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
233 impl <T = impl Debug> T {}
234 //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
235 //~| WARNING this was previously accepted by the compiler but is being phased out
236 //~| ERROR `impl Trait` only allowed in function and inherent method return types
237 //~| ERROR no nominal type found
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
243 //~| ERROR `impl Trait` only allowed in function and inherent method return types
246 let _in_local_variable: impl Fn() = || {};
247 //~^ ERROR `impl Trait` only allowed in function and inherent method return types
248 let _in_return_in_local_variable = || -> impl Fn() { || {} };
249 //~^ ERROR `impl Trait` only allowed in function and inherent method return types