1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! A simple test for testing many permutations of allowedness of
16 fn in_parameters(_: impl Debug) { panic!() }
19 fn in_return() -> impl Debug { panic!() }
22 fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() }
25 fn in_adt_in_return() -> Vec<impl Debug> { panic!() }
28 fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
29 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
32 fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
33 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
36 fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() }
37 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
40 fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
41 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
44 fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
45 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
48 fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
49 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
52 fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
53 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
56 fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() }
57 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
60 fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
61 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
62 //~^^ ERROR nested `impl Trait` is not allowed
65 fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
66 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
69 fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
70 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
71 //~^^ ERROR nested `impl Trait` is not allowed
74 fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() }
75 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
78 fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
79 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
82 fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() }
83 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
87 fn in_impl_Trait_in_parameters(_: impl Iterator<Item = impl Iterator>) { panic!() }
90 fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> {
91 vec![vec![0; 10], vec![12; 7], vec![8; 3]]
95 struct InBraceStructField { x: impl Debug }
96 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
99 struct InAdtInBraceStructField { x: Vec<impl Debug> }
100 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
103 struct InTupleStructField(impl Debug);
104 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
108 InBraceVariant { x: impl Debug },
109 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
110 InTupleVariant(impl Debug),
111 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
115 trait InTraitDefnParameters {
116 fn in_parameters(_: impl Debug);
120 trait InTraitDefnReturn {
121 fn in_return() -> impl Debug;
122 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
125 // Allowed and disallowed in trait impls
128 fn in_trait_impl_parameter(_: impl Debug);
129 fn in_trait_impl_return() -> Self::Out;
131 impl DummyTrait for () {
132 type Out = impl Debug;
133 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
135 fn in_trait_impl_parameter(_: impl Debug) { }
138 fn in_trait_impl_return() -> impl Debug { () }
139 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
145 fn in_inherent_impl_parameters(_: impl Debug) { }
146 fn in_inherent_impl_return() -> impl Debug { () }
151 fn in_foreign_parameters(_: impl Debug);
152 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
154 fn in_foreign_return() -> impl Debug;
155 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
159 extern "C" fn in_extern_fn_parameters(_: impl Debug) {
163 extern "C" fn in_extern_fn_return() -> impl Debug {
167 type InTypeAlias<R> = impl Debug;
168 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
170 type InReturnInTypeAlias<R> = fn() -> impl Debug;
171 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
173 // Disallowed in impl headers
174 impl PartialEq<impl Debug> for () {
175 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
178 // Disallowed in impl headers
179 impl PartialEq<()> for impl Debug {
180 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
183 // Disallowed in inherent impls
185 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
188 // Disallowed in inherent impls
189 struct InInherentImplAdt<T> { t: T }
190 impl InInherentImplAdt<impl Debug> {
191 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
194 // Disallowed in where clauses
195 fn in_fn_where_clause()
196 where impl Debug: Debug
197 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
201 // Disallowed in where clauses
202 fn in_adt_in_fn_where_clause()
203 where Vec<impl Debug>: Debug
204 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
209 fn in_trait_parameter_in_fn_where_clause<T>()
210 where T: PartialEq<impl Debug>
211 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
216 fn in_Fn_parameter_in_fn_where_clause<T>()
217 where T: Fn(impl Debug)
218 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
223 fn in_Fn_return_in_fn_where_clause<T>()
224 where T: Fn() -> impl Debug
225 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
230 let _in_local_variable: impl Fn() = || {};
231 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
232 let _in_return_in_local_variable = || -> impl Fn() { || {} };
233 //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types