about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2022-06-24 19:57:01 +0400
committerMaybe Waffle <waffle.lapkin@gmail.com>2022-07-12 21:00:13 +0400
commit577f3c6f52f641a8a8f2b2e39ee9784bbf76d25d (patch)
treea0b9504a66b7529d2b21e7e80f0744e5234fe2f8 /src
parent0c284843ba23482a2263e1e60b595ead154baae1 (diff)
downloadrust-577f3c6f52f641a8a8f2b2e39ee9784bbf76d25d.tar.gz
rust-577f3c6f52f641a8a8f2b2e39ee9784bbf76d25d.zip
add test for implicit stuff in signatures of closures with `for<>`
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/closures/binder/implicit-stuff.rs27
-rw-r--r--src/test/ui/closures/binder/implicit-stuff.stderr107
2 files changed, 134 insertions, 0 deletions
diff --git a/src/test/ui/closures/binder/implicit-stuff.rs b/src/test/ui/closures/binder/implicit-stuff.rs
new file mode 100644
index 00000000000..09e4c747afe
--- /dev/null
+++ b/src/test/ui/closures/binder/implicit-stuff.rs
@@ -0,0 +1,27 @@
+#![feature(closure_lifetime_binder)]
+
+fn main() {
+    // Implicit types
+    let _ = for<> || {};                                      //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
+    let _ = for<'a> || -> &'a _ { &() };                      //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
+    let _ = for<'a> |x| -> &'a () { x };                      //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
+    let _ = for<'a> |x: &'a _| -> &'a () { x };               //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
+    let _ = for<'a> |x: &'a Vec::<_>| -> &'a Vec::<()> { x }; //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
+    let _ = for<'a> |x: &'a Vec<()>| -> &'a Vec<_> { x };     //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
+    let _ = for<'a> |x: &'a _| -> &'a &'a () { x };           //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
+    let _ = for<'a> |x: &'a _, y, z: _| -> &'a _ {            //~ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
+        let _: &u8 = x;
+        let _: u32 = y;
+        let _: i32 = z;
+        x
+    };
+
+    // Lifetime elision
+    let _ = for<> |_: &()| -> () {};           //~ ERROR `&` without an explicit lifetime name cannot be used here
+    let _ = for<> |x: &()| -> &() { x };       //~ ERROR `&` without an explicit lifetime name cannot be used here
+                                               //~| ERROR `&` without an explicit lifetime name cannot be used here
+    let _ = for<> |x: &'_ ()| -> &'_ () { x }; //~ ERROR `'_` cannot be used here
+                                               //~| ERROR `'_` cannot be used here
+    let _ = for<'a> |x: &()| -> &'a () { x };  //~ ERROR `&` without an explicit lifetime name cannot be used here
+    let _ = for<'a> |x: &'a ()| -> &() { x };  //~ ERROR `&` without an explicit lifetime name cannot be used here
+}
diff --git a/src/test/ui/closures/binder/implicit-stuff.stderr b/src/test/ui/closures/binder/implicit-stuff.stderr
new file mode 100644
index 00000000000..779a08a44e5
--- /dev/null
+++ b/src/test/ui/closures/binder/implicit-stuff.stderr
@@ -0,0 +1,107 @@
+error[E0637]: `&` without an explicit lifetime name cannot be used here
+  --> $DIR/implicit-stuff.rs:20:23
+   |
+LL |     let _ = for<> |_: &()| -> () {};
+   |                       ^ explicit lifetime name needed here
+
+error[E0637]: `&` without an explicit lifetime name cannot be used here
+  --> $DIR/implicit-stuff.rs:21:23
+   |
+LL |     let _ = for<> |x: &()| -> &() { x };
+   |                       ^ explicit lifetime name needed here
+
+error[E0637]: `&` without an explicit lifetime name cannot be used here
+  --> $DIR/implicit-stuff.rs:21:31
+   |
+LL |     let _ = for<> |x: &()| -> &() { x };
+   |                               ^ explicit lifetime name needed here
+
+error[E0637]: `'_` cannot be used here
+  --> $DIR/implicit-stuff.rs:23:24
+   |
+LL |     let _ = for<> |x: &'_ ()| -> &'_ () { x };
+   |                        ^^ `'_` is a reserved lifetime name
+
+error[E0637]: `'_` cannot be used here
+  --> $DIR/implicit-stuff.rs:23:35
+   |
+LL |     let _ = for<> |x: &'_ ()| -> &'_ () { x };
+   |                                   ^^ `'_` is a reserved lifetime name
+
+error[E0637]: `&` without an explicit lifetime name cannot be used here
+  --> $DIR/implicit-stuff.rs:25:25
+   |
+LL |     let _ = for<'a> |x: &()| -> &'a () { x };
+   |                         ^ explicit lifetime name needed here
+
+error[E0637]: `&` without an explicit lifetime name cannot be used here
+  --> $DIR/implicit-stuff.rs:26:36
+   |
+LL |     let _ = for<'a> |x: &'a ()| -> &() { x };
+   |                                    ^ explicit lifetime name needed here
+
+error: implicit types in closure signatures are forbidden when `for<...>` is present
+  --> $DIR/implicit-stuff.rs:5:22
+   |
+LL |     let _ = for<> || {};
+   |             -----    ^
+   |             |
+   |             `for<...>` is here
+
+error: implicit types in closure signatures are forbidden when `for<...>` is present
+  --> $DIR/implicit-stuff.rs:6:31
+   |
+LL |     let _ = for<'a> || -> &'a _ { &() };
+   |             -------           ^
+   |             |
+   |             `for<...>` is here
+
+error: implicit types in closure signatures are forbidden when `for<...>` is present
+  --> $DIR/implicit-stuff.rs:7:22
+   |
+LL |     let _ = for<'a> |x| -> &'a () { x };
+   |             -------  ^
+   |             |
+   |             `for<...>` is here
+
+error: implicit types in closure signatures are forbidden when `for<...>` is present
+  --> $DIR/implicit-stuff.rs:8:29
+   |
+LL |     let _ = for<'a> |x: &'a _| -> &'a () { x };
+   |             -------         ^
+   |             |
+   |             `for<...>` is here
+
+error: implicit types in closure signatures are forbidden when `for<...>` is present
+  --> $DIR/implicit-stuff.rs:9:35
+   |
+LL |     let _ = for<'a> |x: &'a Vec::<_>| -> &'a Vec::<()> { x };
+   |             -------               ^
+   |             |
+   |             `for<...>` is here
+
+error: implicit types in closure signatures are forbidden when `for<...>` is present
+  --> $DIR/implicit-stuff.rs:10:49
+   |
+LL |     let _ = for<'a> |x: &'a Vec<()>| -> &'a Vec<_> { x };
+   |             ------- `for<...>` is here          ^
+
+error: implicit types in closure signatures are forbidden when `for<...>` is present
+  --> $DIR/implicit-stuff.rs:11:29
+   |
+LL |     let _ = for<'a> |x: &'a _| -> &'a &'a () { x };
+   |             -------         ^
+   |             |
+   |             `for<...>` is here
+
+error: implicit types in closure signatures are forbidden when `for<...>` is present
+  --> $DIR/implicit-stuff.rs:12:29
+   |
+LL |     let _ = for<'a> |x: &'a _, y, z: _| -> &'a _ {
+   |             -------         ^  ^     ^         ^
+   |             |
+   |             `for<...>` is here
+
+error: aborting due to 15 previous errors
+
+For more information about this error, try `rustc --explain E0637`.