Skip to content

Commit 00f2277

Browse files
committed
Add even more tests for impl Fn() -> impl Trait
1 parent 7a4ba2f commit 00f2277

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/test/ui/impl-trait/impl-fn-hrtb-bounds.rs

+10
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,14 @@ fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
1010
|x| x
1111
}
1212

13+
fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
14+
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
15+
|x| x
16+
}
17+
18+
fn d() -> impl Fn() -> (impl Debug + '_) {
19+
//~^ ERROR missing lifetime specifier
20+
|| ()
21+
}
22+
1323
fn main() {}

src/test/ui/impl-trait/impl-fn-hrtb-bounds.stderr

+31-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,35 @@ note: lifetime declared here
2222
LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
2323
| ^^
2424

25-
error: aborting due to 2 previous errors
25+
error: higher kinded lifetime bounds on nested opaque types are not supported yet
26+
--> $DIR/impl-fn-hrtb-bounds.rs:13:52
27+
|
28+
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
29+
| ^^
30+
|
31+
note: lifetime declared here
32+
--> $DIR/impl-fn-hrtb-bounds.rs:13:20
33+
|
34+
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
35+
| ^^
36+
37+
error[E0106]: missing lifetime specifier
38+
--> $DIR/impl-fn-hrtb-bounds.rs:18:38
39+
|
40+
LL | fn d() -> impl Fn() -> (impl Debug + '_) {
41+
| ^^ expected named lifetime parameter
42+
|
43+
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
44+
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
45+
help: consider making the bound lifetime-generic with a new `'a` lifetime
46+
|
47+
LL | fn d() -> impl for<'a> Fn() -> (impl Debug + 'a) {
48+
| +++++++ ~~
49+
help: consider using the `'static` lifetime
50+
|
51+
LL | fn d() -> impl Fn() -> (impl Debug + 'static) {
52+
| ~~~~~~~
53+
54+
error: aborting due to 4 previous errors
2655

56+
For more information about this error, try `rustc --explain E0106`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
use std::fmt::Debug;
3+
4+
fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
5+
|x| x
6+
}
7+
8+
fn _b<'a>() -> impl Fn(&'a u8) -> (impl Debug + 'a) {
9+
a()
10+
}
11+
12+
fn main() {}

0 commit comments

Comments
 (0)