Skip to content

Commit 577f3c6

Browse files
committed
add test for implicit stuff in signatures of closures with for<>
1 parent 0c28484 commit 577f3c6

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![feature(closure_lifetime_binder)]
2+
3+
fn main() {
4+
// Implicit types
5+
let _ = for<> || {}; //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
6+
let _ = for<'a> || -> &'a _ { &() }; //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
7+
let _ = for<'a> |x| -> &'a () { x }; //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
8+
let _ = for<'a> |x: &'a _| -> &'a () { x }; //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
9+
let _ = for<'a> |x: &'a Vec::<_>| -> &'a Vec::<()> { x }; //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
10+
let _ = for<'a> |x: &'a Vec<()>| -> &'a Vec<_> { x }; //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
11+
let _ = for<'a> |x: &'a _| -> &'a &'a () { x }; //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
12+
let _ = for<'a> |x: &'a _, y, z: _| -> &'a _ { //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
13+
let _: &u8 = x;
14+
let _: u32 = y;
15+
let _: i32 = z;
16+
x
17+
};
18+
19+
// Lifetime elision
20+
let _ = for<> |_: &()| -> () {}; //~ ERROR `&` without an explicit lifetime name cannot be used here
21+
let _ = for<> |x: &()| -> &() { x }; //~ ERROR `&` without an explicit lifetime name cannot be used here
22+
//~| ERROR `&` without an explicit lifetime name cannot be used here
23+
let _ = for<> |x: &'_ ()| -> &'_ () { x }; //~ ERROR `'_` cannot be used here
24+
//~| ERROR `'_` cannot be used here
25+
let _ = for<'a> |x: &()| -> &'a () { x }; //~ ERROR `&` without an explicit lifetime name cannot be used here
26+
let _ = for<'a> |x: &'a ()| -> &() { x }; //~ ERROR `&` without an explicit lifetime name cannot be used here
27+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
error[E0637]: `&` without an explicit lifetime name cannot be used here
2+
--> $DIR/implicit-stuff.rs:20:23
3+
|
4+
LL | let _ = for<> |_: &()| -> () {};
5+
| ^ explicit lifetime name needed here
6+
7+
error[E0637]: `&` without an explicit lifetime name cannot be used here
8+
--> $DIR/implicit-stuff.rs:21:23
9+
|
10+
LL | let _ = for<> |x: &()| -> &() { x };
11+
| ^ explicit lifetime name needed here
12+
13+
error[E0637]: `&` without an explicit lifetime name cannot be used here
14+
--> $DIR/implicit-stuff.rs:21:31
15+
|
16+
LL | let _ = for<> |x: &()| -> &() { x };
17+
| ^ explicit lifetime name needed here
18+
19+
error[E0637]: `'_` cannot be used here
20+
--> $DIR/implicit-stuff.rs:23:24
21+
|
22+
LL | let _ = for<> |x: &'_ ()| -> &'_ () { x };
23+
| ^^ `'_` is a reserved lifetime name
24+
25+
error[E0637]: `'_` cannot be used here
26+
--> $DIR/implicit-stuff.rs:23:35
27+
|
28+
LL | let _ = for<> |x: &'_ ()| -> &'_ () { x };
29+
| ^^ `'_` is a reserved lifetime name
30+
31+
error[E0637]: `&` without an explicit lifetime name cannot be used here
32+
--> $DIR/implicit-stuff.rs:25:25
33+
|
34+
LL | let _ = for<'a> |x: &()| -> &'a () { x };
35+
| ^ explicit lifetime name needed here
36+
37+
error[E0637]: `&` without an explicit lifetime name cannot be used here
38+
--> $DIR/implicit-stuff.rs:26:36
39+
|
40+
LL | let _ = for<'a> |x: &'a ()| -> &() { x };
41+
| ^ explicit lifetime name needed here
42+
43+
error: implicit types in closure signatures are forbidden when `for<...>` is present
44+
--> $DIR/implicit-stuff.rs:5:22
45+
|
46+
LL | let _ = for<> || {};
47+
| ----- ^
48+
| |
49+
| `for<...>` is here
50+
51+
error: implicit types in closure signatures are forbidden when `for<...>` is present
52+
--> $DIR/implicit-stuff.rs:6:31
53+
|
54+
LL | let _ = for<'a> || -> &'a _ { &() };
55+
| ------- ^
56+
| |
57+
| `for<...>` is here
58+
59+
error: implicit types in closure signatures are forbidden when `for<...>` is present
60+
--> $DIR/implicit-stuff.rs:7:22
61+
|
62+
LL | let _ = for<'a> |x| -> &'a () { x };
63+
| ------- ^
64+
| |
65+
| `for<...>` is here
66+
67+
error: implicit types in closure signatures are forbidden when `for<...>` is present
68+
--> $DIR/implicit-stuff.rs:8:29
69+
|
70+
LL | let _ = for<'a> |x: &'a _| -> &'a () { x };
71+
| ------- ^
72+
| |
73+
| `for<...>` is here
74+
75+
error: implicit types in closure signatures are forbidden when `for<...>` is present
76+
--> $DIR/implicit-stuff.rs:9:35
77+
|
78+
LL | let _ = for<'a> |x: &'a Vec::<_>| -> &'a Vec::<()> { x };
79+
| ------- ^
80+
| |
81+
| `for<...>` is here
82+
83+
error: implicit types in closure signatures are forbidden when `for<...>` is present
84+
--> $DIR/implicit-stuff.rs:10:49
85+
|
86+
LL | let _ = for<'a> |x: &'a Vec<()>| -> &'a Vec<_> { x };
87+
| ------- `for<...>` is here ^
88+
89+
error: implicit types in closure signatures are forbidden when `for<...>` is present
90+
--> $DIR/implicit-stuff.rs:11:29
91+
|
92+
LL | let _ = for<'a> |x: &'a _| -> &'a &'a () { x };
93+
| ------- ^
94+
| |
95+
| `for<...>` is here
96+
97+
error: implicit types in closure signatures are forbidden when `for<...>` is present
98+
--> $DIR/implicit-stuff.rs:12:29
99+
|
100+
LL | let _ = for<'a> |x: &'a _, y, z: _| -> &'a _ {
101+
| ------- ^ ^ ^ ^
102+
| |
103+
| `for<...>` is here
104+
105+
error: aborting due to 15 previous errors
106+
107+
For more information about this error, try `rustc --explain E0637`.

0 commit comments

Comments
 (0)