about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2022-06-23 19:00:03 +0400
committerMaybe Waffle <waffle.lapkin@gmail.com>2022-10-25 13:25:51 +0000
commit7a4ba2ffdee0e63fe62f7543589faec9ad29fb9c (patch)
tree329ad7db0545ea7ff4572033ab6a83384f75d8e6
parent8b494f427cb06896996fb02ac8c3ff745fde4d15 (diff)
downloadrust-7a4ba2ffdee0e63fe62f7543589faec9ad29fb9c.tar.gz
rust-7a4ba2ffdee0e63fe62f7543589faec9ad29fb9c.zip
Add more tests for `impl Fn() -> impl Trait`
-rw-r--r--src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.rs7
-rw-r--r--src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.stderr11
-rw-r--r--src/test/ui/impl-trait/impl-fn-hrtb-bounds.rs13
-rw-r--r--src/test/ui/impl-trait/impl-fn-hrtb-bounds.stderr26
-rw-r--r--src/test/ui/impl-trait/impl-fn-parsing-ambiguities.rs14
-rw-r--r--src/test/ui/impl-trait/impl-fn-parsing-ambiguities.stderr26
-rw-r--r--src/test/ui/impl-trait/impl_fn_associativity.rs9
7 files changed, 106 insertions, 0 deletions
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 00000000000..688ae1da5e3
--- /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 00000000000..57f618d11f9
--- /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 00000000000..f7d9430a226
--- /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 00000000000..6fe4534d928
--- /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 00000000000..053912aa816
--- /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 00000000000..e54864443ae
--- /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 f5f1909cf58..6accaed98c9 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);
 }