|
14 | 14 | use std::fmt::Debug;
|
15 | 15 |
|
16 | 16 | // Allowed
|
17 |
| -fn simple_universal(_: impl Debug) { panic!() } |
| 17 | +fn in_parameters(_: impl Debug) { panic!() } |
18 | 18 |
|
19 | 19 | // Allowed
|
20 |
| -fn simple_existential() -> impl Debug { panic!() } |
| 20 | +fn in_return() -> impl Debug { panic!() } |
21 | 21 |
|
22 | 22 | // Allowed
|
23 |
| -fn collection_universal(_: Vec<impl Debug>) { panic!() } |
| 23 | +fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() } |
24 | 24 |
|
25 | 25 | // Allowed
|
26 |
| -fn collection_existential() -> Vec<impl Debug> { panic!() } |
| 26 | +fn in_adt_in_return() -> Vec<impl Debug> { panic!() } |
27 | 27 |
|
28 | 28 | // Disallowed
|
29 |
| -fn fn_type_universal(_: fn(impl Debug)) { panic!() } |
| 29 | +fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() } |
30 | 30 | //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
|
31 | 31 |
|
32 | 32 | // Disallowed
|
33 |
| -fn fn_type_existential() -> fn(impl Debug) { panic!() } |
| 33 | +fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() } |
34 | 34 | //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
|
35 | 35 |
|
36 |
| -// Allowed |
37 |
| -fn dyn_universal(_: &dyn Iterator<Item = impl Debug>) { panic!() } |
| 36 | +// Disallowed |
| 37 | +fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() } |
| 38 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 39 | + |
| 40 | +// Disallowed |
| 41 | +fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() } |
| 42 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 43 | + |
| 44 | +// Disallowed |
| 45 | +fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() } |
| 46 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 47 | + |
| 48 | +// Disallowed |
| 49 | +fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() } |
| 50 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 51 | +// FIXME -- no error currently |
| 52 | + |
| 53 | +// Disallowed |
| 54 | +fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() } |
| 55 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 56 | + |
| 57 | +// Disallowed |
| 58 | +fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() } |
| 59 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 60 | +// FIXME -- no error currently |
| 61 | + |
| 62 | +// Disallowed |
| 63 | +fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() } |
| 64 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 65 | + |
| 66 | +// Disallowed |
| 67 | +fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() } |
| 68 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 69 | +// FIXME -- no error currently |
38 | 70 |
|
39 | 71 | // Disallowed
|
40 |
| -fn dyn_fn_trait(_: &dyn Fn(impl Debug)) { panic!() } |
| 72 | +fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } |
41 | 73 | //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
|
42 | 74 |
|
| 75 | +// Disallowed |
| 76 | +fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() } |
| 77 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 78 | +// FIXME -- no error currently |
| 79 | + |
43 | 80 | // Allowed
|
44 |
| -fn nested_universal(_: impl Iterator<Item = impl Iterator>) { panic!() } |
| 81 | +fn in_impl_Trait_in_parameters(_: impl Iterator<Item = impl Iterator>) { panic!() } |
45 | 82 |
|
46 | 83 | // Allowed
|
47 |
| -fn nested_existential() -> impl IntoIterator<Item = impl IntoIterator> { |
| 84 | +fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> { |
48 | 85 | vec![vec![0; 10], vec![12; 7], vec![8; 3]]
|
49 | 86 | }
|
50 | 87 |
|
51 | 88 | // Disallowed
|
52 |
| -fn universal_fn_trait(_: impl Fn(impl Debug)) { panic!() } |
| 89 | +struct InBraceStructField { x: impl Debug } |
| 90 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 91 | + |
| 92 | +// Disallowed |
| 93 | +struct InAdtInBraceStructField { x: Vec<impl Debug> } |
53 | 94 | //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
|
54 | 95 |
|
55 | 96 | // Disallowed
|
56 |
| -struct ImplMember { x: impl Debug } |
| 97 | +struct InTupleStructField(impl Debug); |
57 | 98 | //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
|
58 | 99 |
|
59 | 100 | // Disallowed
|
60 |
| -trait Universal { |
61 |
| - // FIXME, should error? |
62 |
| - fn universal(impl Debug); |
| 101 | +enum InEnum { |
| 102 | + InBraceVariant { x: impl Debug }, |
| 103 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 104 | + InTupleVariant(impl Debug), |
| 105 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 106 | +} |
| 107 | + |
| 108 | +// Allowed |
| 109 | +trait InTraitDefnParameters { |
| 110 | + fn in_parameters(_: impl Debug); |
63 | 111 | }
|
64 | 112 |
|
65 | 113 | // Disallowed
|
66 |
| -trait Existential { |
67 |
| - fn existential() -> impl Debug; |
| 114 | +trait InTraitDefnReturn { |
| 115 | + fn in_return() -> impl Debug; |
| 116 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 117 | +} |
| 118 | + |
| 119 | +// Allowed and disallowed in trait impls |
| 120 | +trait DummyTrait { |
| 121 | + type Out; |
| 122 | + fn in_trait_impl_parameter(impl Debug); |
| 123 | + fn in_trait_impl_return() -> Self::Out; |
| 124 | +} |
| 125 | +impl DummyTrait for () { |
| 126 | + type Out = impl Debug; |
| 127 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 128 | + |
| 129 | + fn in_trait_impl_parameter(_: impl Debug) { } |
| 130 | + // Allowed |
| 131 | + |
| 132 | + fn in_trait_impl_return() -> impl Debug { () } |
| 133 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 134 | +} |
| 135 | + |
| 136 | +// Allowed |
| 137 | +struct DummyType; |
| 138 | +impl DummyType { |
| 139 | + fn in_inherent_impl_parameters(_: impl Debug) { } |
| 140 | + fn in_inherent_impl_return() -> impl Debug { () } |
| 141 | +} |
| 142 | + |
| 143 | +// Disallowed |
| 144 | +extern "C" { |
| 145 | + fn in_foreign_parameters(_: impl Debug); |
| 146 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 147 | + // FIXME currently allowed |
| 148 | + |
| 149 | + fn in_foreign_return() -> impl Debug; |
| 150 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 151 | + // FIXME currently allowed |
| 152 | +} |
| 153 | + |
| 154 | +// Allowed |
| 155 | +extern "C" fn in_extern_fn_parameters(_: impl Debug) { |
| 156 | +} |
| 157 | + |
| 158 | +// Allowed |
| 159 | +extern "C" fn in_extern_fn_return() -> impl Debug { |
| 160 | + 22 |
| 161 | +} |
| 162 | + |
| 163 | +type InTypeAlias<R> = impl Debug; |
| 164 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 165 | + |
| 166 | +type InReturnInTypeAlias<R> = fn() -> impl Debug; |
| 167 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 168 | + |
| 169 | +// Disallowed in impl headers |
| 170 | +impl PartialEq<impl Debug> for () { |
| 171 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 172 | +} |
| 173 | + |
| 174 | +// Disallowed in impl headers |
| 175 | +impl PartialEq<()> for impl Debug { |
| 176 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 177 | +} |
| 178 | + |
| 179 | +// Disallowed in inherent impls |
| 180 | +impl impl Debug { |
| 181 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 182 | +} |
| 183 | + |
| 184 | +// Disallowed in inherent impls |
| 185 | +struct InInherentImplAdt<T> { t: T } |
| 186 | +impl InInherentImplAdt<impl Debug> { |
| 187 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 188 | +} |
| 189 | + |
| 190 | +// Disallowed in where clauses |
| 191 | +fn in_fn_where_clause() |
| 192 | + where impl Debug: Debug |
| 193 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 194 | +{ |
| 195 | +} |
| 196 | + |
| 197 | +// Disallowed in where clauses |
| 198 | +fn in_adt_in_fn_where_clause() |
| 199 | + where Vec<impl Debug>: Debug |
| 200 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 201 | +{ |
| 202 | +} |
| 203 | + |
| 204 | +// Disallowed |
| 205 | +fn in_trait_parameter_in_fn_where_clause<T>() |
| 206 | + where T: PartialEq<impl Debug> |
| 207 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 208 | +{ |
| 209 | +} |
| 210 | + |
| 211 | +// Disallowed |
| 212 | +fn in_Fn_parameter_in_fn_where_clause<T>() |
| 213 | + where T: Fn(impl Debug) |
| 214 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 215 | +{ |
| 216 | +} |
| 217 | + |
| 218 | +// Disallowed |
| 219 | +fn in_Fn_return_in_fn_where_clause<T>() |
| 220 | + where T: Fn() -> impl Debug |
| 221 | +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 222 | +{ |
| 223 | +} |
| 224 | + |
| 225 | +fn main() { |
| 226 | + let _in_local_variable: impl Fn() = || {}; |
| 227 | + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types |
| 228 | + let _in_return_in_local_variable = || -> impl Fn() { || {} }; |
68 | 229 | //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
|
69 | 230 | }
|
70 | 231 |
|
71 |
| -fn main() {} |
|
0 commit comments