Skip to content

Commit 7a4ba2f

Browse files
committed
Add more tests for impl Fn() -> impl Trait
1 parent 8b494f4 commit 7a4ba2f

7 files changed

+106
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use std::fmt::Debug;
2+
3+
fn a() -> impl Fn(&u8) -> impl Debug {
4+
|x| x //~ ERROR lifetime may not live long enough
5+
}
6+
7+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/impl-fn-hrtb-bounds-2.rs:4:9
3+
|
4+
LL | |x| x
5+
| -- ^ returning this value requires that `'1` must outlive `'2`
6+
| ||
7+
| |return type of closure is &'2 u8
8+
| has type `&'1 u8`
9+
10+
error: aborting due to previous error
11+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::fmt::Debug;
2+
3+
fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
4+
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
5+
|x| x
6+
}
7+
8+
fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
9+
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
10+
|x| x
11+
}
12+
13+
fn main() {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
2+
--> $DIR/impl-fn-hrtb-bounds.rs:3:41
3+
|
4+
LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
5+
| ^^
6+
|
7+
note: lifetime declared here
8+
--> $DIR/impl-fn-hrtb-bounds.rs:3:19
9+
|
10+
LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
11+
| ^
12+
13+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
14+
--> $DIR/impl-fn-hrtb-bounds.rs:8:52
15+
|
16+
LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
17+
| ^^
18+
|
19+
note: lifetime declared here
20+
--> $DIR/impl-fn-hrtb-bounds.rs:8:20
21+
|
22+
LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
23+
| ^^
24+
25+
error: aborting due to 2 previous errors
26+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::fmt::Debug;
2+
3+
fn a() -> impl Fn(&u8) -> impl Debug + '_ {
4+
//~^ ERROR ambiguous `+` in a type
5+
//~^^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
6+
|x| x
7+
}
8+
9+
fn b() -> impl Fn() -> impl Debug + Send {
10+
//~^ ERROR ambiguous `+` in a type
11+
|| ()
12+
}
13+
14+
fn main() {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: ambiguous `+` in a type
2+
--> $DIR/impl-fn-parsing-ambiguities.rs:3:27
3+
|
4+
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
5+
| ^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + '_)`
6+
7+
error: ambiguous `+` in a type
8+
--> $DIR/impl-fn-parsing-ambiguities.rs:9:24
9+
|
10+
LL | fn b() -> impl Fn() -> impl Debug + Send {
11+
| ^^^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + Send)`
12+
13+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
14+
--> $DIR/impl-fn-parsing-ambiguities.rs:3:40
15+
|
16+
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
17+
| ^^
18+
|
19+
note: lifetime declared here
20+
--> $DIR/impl-fn-parsing-ambiguities.rs:3:19
21+
|
22+
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
23+
| ^
24+
25+
error: aborting due to 3 previous errors
26+

src/test/ui/impl-trait/impl_fn_associativity.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ fn ff_debug() -> impl Fn() -> impl Fn() -> impl Debug {
99
|| f_debug()
1010
}
1111

12+
fn multi() -> impl Fn() -> (impl Debug + Send) {
13+
|| ()
14+
}
15+
1216
fn main() {
1317
// Check that `ff_debug` is `() -> (() -> Debug)` and not `(() -> ()) -> Debug`
1418
let debug = ff_debug()()();
1519
assert_eq!(format!("{:?}", debug), "()");
20+
21+
let x = multi()();
22+
assert_eq!(format!("{:?}", x), "()");
23+
fn assert_send(_: &impl Send) {}
24+
assert_send(&x);
1625
}

0 commit comments

Comments
 (0)