Add more tests for impl Fn() -> impl Trait
This commit is contained in:
parent
8b494f427c
commit
7a4ba2ffde
7 changed files with 106 additions and 0 deletions
7
src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.rs
Normal file
7
src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
fn a() -> impl Fn(&u8) -> impl Debug {
|
||||
|x| x //~ ERROR lifetime may not live long enough
|
||||
}
|
||||
|
||||
fn main() {}
|
11
src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.stderr
Normal file
11
src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
error: lifetime may not live long enough
|
||||
--> $DIR/impl-fn-hrtb-bounds-2.rs:4:9
|
||||
|
|
||||
LL | |x| x
|
||||
| -- ^ returning this value requires that `'1` must outlive `'2`
|
||||
| ||
|
||||
| |return type of closure is &'2 u8
|
||||
| has type `&'1 u8`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
13
src/test/ui/impl-trait/impl-fn-hrtb-bounds.rs
Normal file
13
src/test/ui/impl-trait/impl-fn-hrtb-bounds.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
|
||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
||||
|x| x
|
||||
}
|
||||
|
||||
fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
|
||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
||||
|x| x
|
||||
}
|
||||
|
||||
fn main() {}
|
26
src/test/ui/impl-trait/impl-fn-hrtb-bounds.stderr
Normal file
26
src/test/ui/impl-trait/impl-fn-hrtb-bounds.stderr
Normal file
|
@ -0,0 +1,26 @@
|
|||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
||||
--> $DIR/impl-fn-hrtb-bounds.rs:3:41
|
||||
|
|
||||
LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
|
||||
| ^^
|
||||
|
|
||||
note: lifetime declared here
|
||||
--> $DIR/impl-fn-hrtb-bounds.rs:3:19
|
||||
|
|
||||
LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
|
||||
| ^
|
||||
|
||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
||||
--> $DIR/impl-fn-hrtb-bounds.rs:8:52
|
||||
|
|
||||
LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
|
||||
| ^^
|
||||
|
|
||||
note: lifetime declared here
|
||||
--> $DIR/impl-fn-hrtb-bounds.rs:8:20
|
||||
|
|
||||
LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
|
||||
| ^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
14
src/test/ui/impl-trait/impl-fn-parsing-ambiguities.rs
Normal file
14
src/test/ui/impl-trait/impl-fn-parsing-ambiguities.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
fn a() -> impl Fn(&u8) -> impl Debug + '_ {
|
||||
//~^ ERROR ambiguous `+` in a type
|
||||
//~^^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
||||
|x| x
|
||||
}
|
||||
|
||||
fn b() -> impl Fn() -> impl Debug + Send {
|
||||
//~^ ERROR ambiguous `+` in a type
|
||||
|| ()
|
||||
}
|
||||
|
||||
fn main() {}
|
26
src/test/ui/impl-trait/impl-fn-parsing-ambiguities.stderr
Normal file
26
src/test/ui/impl-trait/impl-fn-parsing-ambiguities.stderr
Normal file
|
@ -0,0 +1,26 @@
|
|||
error: ambiguous `+` in a type
|
||||
--> $DIR/impl-fn-parsing-ambiguities.rs:3:27
|
||||
|
|
||||
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
|
||||
| ^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + '_)`
|
||||
|
||||
error: ambiguous `+` in a type
|
||||
--> $DIR/impl-fn-parsing-ambiguities.rs:9:24
|
||||
|
|
||||
LL | fn b() -> impl Fn() -> impl Debug + Send {
|
||||
| ^^^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + Send)`
|
||||
|
||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
||||
--> $DIR/impl-fn-parsing-ambiguities.rs:3:40
|
||||
|
|
||||
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
|
||||
| ^^
|
||||
|
|
||||
note: lifetime declared here
|
||||
--> $DIR/impl-fn-parsing-ambiguities.rs:3:19
|
||||
|
|
||||
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
|
||||
| ^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
|
@ -9,8 +9,17 @@ fn ff_debug() -> impl Fn() -> impl Fn() -> impl Debug {
|
|||
|| f_debug()
|
||||
}
|
||||
|
||||
fn multi() -> impl Fn() -> (impl Debug + Send) {
|
||||
|| ()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Check that `ff_debug` is `() -> (() -> Debug)` and not `(() -> ()) -> Debug`
|
||||
let debug = ff_debug()()();
|
||||
assert_eq!(format!("{:?}", debug), "()");
|
||||
|
||||
let x = multi()();
|
||||
assert_eq!(format!("{:?}", x), "()");
|
||||
fn assert_send(_: &impl Send) {}
|
||||
assert_send(&x);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue