Skip to content

Commit 37dd79f

Browse files
nikomatsakischrisvittal
authored andcommitted
extend where-allowed.rs with many more cases
also merge disallowed and disallowed-2 into that set
1 parent ebc4408 commit 37dd79f

File tree

3 files changed

+179
-93
lines changed

3 files changed

+179
-93
lines changed

src/test/compile-fail/impl-trait/disallowed-2.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/test/compile-fail/impl-trait/disallowed.rs

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/test/compile-fail/impl-trait/where-allowed.rs

Lines changed: 179 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,218 @@
1414
use std::fmt::Debug;
1515

1616
// Allowed
17-
fn simple_universal(_: impl Debug) { panic!() }
17+
fn in_parameters(_: impl Debug) { panic!() }
1818

1919
// Allowed
20-
fn simple_existential() -> impl Debug { panic!() }
20+
fn in_return() -> impl Debug { panic!() }
2121

2222
// Allowed
23-
fn collection_universal(_: Vec<impl Debug>) { panic!() }
23+
fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() }
2424

2525
// Allowed
26-
fn collection_existential() -> Vec<impl Debug> { panic!() }
26+
fn in_adt_in_return() -> Vec<impl Debug> { panic!() }
2727

2828
// Disallowed
29-
fn fn_type_universal(_: fn(impl Debug)) { panic!() }
29+
fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
3030
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
3131

3232
// Disallowed
33-
fn fn_type_existential() -> fn(impl Debug) { panic!() }
33+
fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
3434
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
3535

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
3870

3971
// 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!() }
4173
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
4274

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+
4380
// Allowed
44-
fn nested_universal(_: impl Iterator<Item = impl Iterator>) { panic!() }
81+
fn in_impl_Trait_in_parameters(_: impl Iterator<Item = impl Iterator>) { panic!() }
4582

4683
// Allowed
47-
fn nested_existential() -> impl IntoIterator<Item = impl IntoIterator> {
84+
fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> {
4885
vec![vec![0; 10], vec![12; 7], vec![8; 3]]
4986
}
5087

5188
// 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> }
5394
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
5495

5596
// Disallowed
56-
struct ImplMember { x: impl Debug }
97+
struct InTupleStructField(impl Debug);
5798
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
5899

59100
// 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);
63111
}
64112

65113
// 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() { || {} };
68229
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
69230
}
70231

71-
fn main() {}

0 commit comments

Comments
 (0)