From 7a4ba2ffdee0e63fe62f7543589faec9ad29fb9c Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 23 Jun 2022 19:00:03 +0400 Subject: [PATCH] Add more tests for `impl Fn() -> impl Trait` --- .../ui/impl-trait/impl-fn-hrtb-bounds-2.rs | 7 +++++ .../impl-trait/impl-fn-hrtb-bounds-2.stderr | 11 ++++++++ src/test/ui/impl-trait/impl-fn-hrtb-bounds.rs | 13 ++++++++++ .../ui/impl-trait/impl-fn-hrtb-bounds.stderr | 26 +++++++++++++++++++ .../impl-trait/impl-fn-parsing-ambiguities.rs | 14 ++++++++++ .../impl-fn-parsing-ambiguities.stderr | 26 +++++++++++++++++++ .../ui/impl-trait/impl_fn_associativity.rs | 9 +++++++ 7 files changed, 106 insertions(+) create mode 100644 src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.rs create mode 100644 src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.stderr create mode 100644 src/test/ui/impl-trait/impl-fn-hrtb-bounds.rs create mode 100644 src/test/ui/impl-trait/impl-fn-hrtb-bounds.stderr create mode 100644 src/test/ui/impl-trait/impl-fn-parsing-ambiguities.rs create mode 100644 src/test/ui/impl-trait/impl-fn-parsing-ambiguities.stderr diff --git a/src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.rs b/src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.rs new file mode 100644 index 000000000000..688ae1da5e30 --- /dev/null +++ b/src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.rs @@ -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() {} diff --git a/src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.stderr b/src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.stderr new file mode 100644 index 000000000000..57f618d11f90 --- /dev/null +++ b/src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.stderr @@ -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 + diff --git a/src/test/ui/impl-trait/impl-fn-hrtb-bounds.rs b/src/test/ui/impl-trait/impl-fn-hrtb-bounds.rs new file mode 100644 index 000000000000..f7d9430a2263 --- /dev/null +++ b/src/test/ui/impl-trait/impl-fn-hrtb-bounds.rs @@ -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() {} diff --git a/src/test/ui/impl-trait/impl-fn-hrtb-bounds.stderr b/src/test/ui/impl-trait/impl-fn-hrtb-bounds.stderr new file mode 100644 index 000000000000..6fe4534d9281 --- /dev/null +++ b/src/test/ui/impl-trait/impl-fn-hrtb-bounds.stderr @@ -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 + diff --git a/src/test/ui/impl-trait/impl-fn-parsing-ambiguities.rs b/src/test/ui/impl-trait/impl-fn-parsing-ambiguities.rs new file mode 100644 index 000000000000..053912aa8166 --- /dev/null +++ b/src/test/ui/impl-trait/impl-fn-parsing-ambiguities.rs @@ -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() {} diff --git a/src/test/ui/impl-trait/impl-fn-parsing-ambiguities.stderr b/src/test/ui/impl-trait/impl-fn-parsing-ambiguities.stderr new file mode 100644 index 000000000000..e54864443ae0 --- /dev/null +++ b/src/test/ui/impl-trait/impl-fn-parsing-ambiguities.stderr @@ -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 + diff --git a/src/test/ui/impl-trait/impl_fn_associativity.rs b/src/test/ui/impl-trait/impl_fn_associativity.rs index f5f1909cf58b..6accaed98c9a 100644 --- a/src/test/ui/impl-trait/impl_fn_associativity.rs +++ b/src/test/ui/impl-trait/impl_fn_associativity.rs @@ -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); }