summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/binder
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/closures/binder
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/closures/binder')
-rw-r--r--tests/ui/closures/binder/async-closure-with-binder.rs8
-rw-r--r--tests/ui/closures/binder/async-closure-with-binder.stderr16
-rw-r--r--tests/ui/closures/binder/disallow-const.rs6
-rw-r--r--tests/ui/closures/binder/disallow-const.stderr8
-rw-r--r--tests/ui/closures/binder/disallow-ty.rs6
-rw-r--r--tests/ui/closures/binder/disallow-ty.stderr8
-rw-r--r--tests/ui/closures/binder/implicit-return.rs6
-rw-r--r--tests/ui/closures/binder/implicit-return.stderr10
-rw-r--r--tests/ui/closures/binder/implicit-stuff.rs27
-rw-r--r--tests/ui/closures/binder/implicit-stuff.stderr107
-rw-r--r--tests/ui/closures/binder/late-bound-in-body.rs9
-rw-r--r--tests/ui/closures/binder/nested-closures-regions.rs9
-rw-r--r--tests/ui/closures/binder/nested-closures-regions.stderr38
-rw-r--r--tests/ui/closures/binder/nested-closures.rs7
-rw-r--r--tests/ui/closures/binder/suggestion-for-introducing-lifetime-into-binder.rs7
-rw-r--r--tests/ui/closures/binder/suggestion-for-introducing-lifetime-into-binder.stderr33
16 files changed, 305 insertions, 0 deletions
diff --git a/tests/ui/closures/binder/async-closure-with-binder.rs b/tests/ui/closures/binder/async-closure-with-binder.rs
new file mode 100644
index 000000000..4fa599d37
--- /dev/null
+++ b/tests/ui/closures/binder/async-closure-with-binder.rs
@@ -0,0 +1,8 @@
+// edition:2021
+#![feature(closure_lifetime_binder)]
+#![feature(async_closure)]
+fn main() {
+ for<'a> async || ();
+ //~^ ERROR `for<...>` binders on `async` closures are not currently supported
+ //~^^ ERROR implicit types in closure signatures are forbidden when `for<...>` is present
+}
diff --git a/tests/ui/closures/binder/async-closure-with-binder.stderr b/tests/ui/closures/binder/async-closure-with-binder.stderr
new file mode 100644
index 000000000..1d4628b1a
--- /dev/null
+++ b/tests/ui/closures/binder/async-closure-with-binder.stderr
@@ -0,0 +1,16 @@
+error: `for<...>` binders on `async` closures are not currently supported
+ --> $DIR/async-closure-with-binder.rs:5:5
+ |
+LL | for<'a> async || ();
+ | ^^^^^^^
+
+error: implicit types in closure signatures are forbidden when `for<...>` is present
+ --> $DIR/async-closure-with-binder.rs:5:5
+ |
+LL | for<'a> async || ();
+ | -------^^^^^^^^^
+ | |
+ | `for<...>` is here
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/closures/binder/disallow-const.rs b/tests/ui/closures/binder/disallow-const.rs
new file mode 100644
index 000000000..72ad6185d
--- /dev/null
+++ b/tests/ui/closures/binder/disallow-const.rs
@@ -0,0 +1,6 @@
+#![feature(closure_lifetime_binder)]
+
+fn main() {
+ for<const N: i32> || -> () {};
+ //~^ ERROR only lifetime parameters can be used in this context
+}
diff --git a/tests/ui/closures/binder/disallow-const.stderr b/tests/ui/closures/binder/disallow-const.stderr
new file mode 100644
index 000000000..3c3b43d8c
--- /dev/null
+++ b/tests/ui/closures/binder/disallow-const.stderr
@@ -0,0 +1,8 @@
+error: only lifetime parameters can be used in this context
+ --> $DIR/disallow-const.rs:4:15
+ |
+LL | for<const N: i32> || -> () {};
+ | ^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/closures/binder/disallow-ty.rs b/tests/ui/closures/binder/disallow-ty.rs
new file mode 100644
index 000000000..bbe3d8488
--- /dev/null
+++ b/tests/ui/closures/binder/disallow-ty.rs
@@ -0,0 +1,6 @@
+#![feature(closure_lifetime_binder)]
+
+fn main() {
+ for<T> || -> () {};
+ //~^ ERROR only lifetime parameters can be used in this context
+}
diff --git a/tests/ui/closures/binder/disallow-ty.stderr b/tests/ui/closures/binder/disallow-ty.stderr
new file mode 100644
index 000000000..51b6773ed
--- /dev/null
+++ b/tests/ui/closures/binder/disallow-ty.stderr
@@ -0,0 +1,8 @@
+error: only lifetime parameters can be used in this context
+ --> $DIR/disallow-ty.rs:4:9
+ |
+LL | for<T> || -> () {};
+ | ^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/closures/binder/implicit-return.rs b/tests/ui/closures/binder/implicit-return.rs
new file mode 100644
index 000000000..d34e5721d
--- /dev/null
+++ b/tests/ui/closures/binder/implicit-return.rs
@@ -0,0 +1,6 @@
+#![feature(closure_lifetime_binder)]
+
+fn main() {
+ let _f = for<'a> |_: &'a ()| {};
+ //~^ implicit types in closure signatures are forbidden when `for<...>` is present
+}
diff --git a/tests/ui/closures/binder/implicit-return.stderr b/tests/ui/closures/binder/implicit-return.stderr
new file mode 100644
index 000000000..5bfb97113
--- /dev/null
+++ b/tests/ui/closures/binder/implicit-return.stderr
@@ -0,0 +1,10 @@
+error: implicit types in closure signatures are forbidden when `for<...>` is present
+ --> $DIR/implicit-return.rs:4:34
+ |
+LL | let _f = for<'a> |_: &'a ()| {};
+ | ------- ^
+ | |
+ | `for<...>` is here
+
+error: aborting due to previous error
+
diff --git a/tests/ui/closures/binder/implicit-stuff.rs b/tests/ui/closures/binder/implicit-stuff.rs
new file mode 100644
index 000000000..09e4c747a
--- /dev/null
+++ b/tests/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/tests/ui/closures/binder/implicit-stuff.stderr b/tests/ui/closures/binder/implicit-stuff.stderr
new file mode 100644
index 000000000..779a08a44
--- /dev/null
+++ b/tests/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`.
diff --git a/tests/ui/closures/binder/late-bound-in-body.rs b/tests/ui/closures/binder/late-bound-in-body.rs
new file mode 100644
index 000000000..bb5c7552f
--- /dev/null
+++ b/tests/ui/closures/binder/late-bound-in-body.rs
@@ -0,0 +1,9 @@
+// check-pass
+
+#![feature(closure_lifetime_binder)]
+
+fn main() {
+ let _ = for<'a> || -> () {
+ let _: &'a bool = &true;
+ };
+}
diff --git a/tests/ui/closures/binder/nested-closures-regions.rs b/tests/ui/closures/binder/nested-closures-regions.rs
new file mode 100644
index 000000000..6bfc6c80b
--- /dev/null
+++ b/tests/ui/closures/binder/nested-closures-regions.rs
@@ -0,0 +1,9 @@
+// check-pass
+
+#![feature(closure_lifetime_binder)]
+#![feature(rustc_attrs)]
+
+#[rustc_regions]
+fn main() {
+ for<'a> || -> () { for<'c> |_: &'a ()| -> () {}; };
+}
diff --git a/tests/ui/closures/binder/nested-closures-regions.stderr b/tests/ui/closures/binder/nested-closures-regions.stderr
new file mode 100644
index 000000000..b385e0ed6
--- /dev/null
+++ b/tests/ui/closures/binder/nested-closures-regions.stderr
@@ -0,0 +1,38 @@
+note: external requirements
+ --> $DIR/nested-closures-regions.rs:8:24
+ |
+LL | for<'a> || -> () { for<'c> |_: &'a ()| -> () {}; };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: defining type: main::{closure#0}::{closure#0} with closure substs [
+ i8,
+ extern "rust-call" fn((&(),)),
+ (),
+ ]
+ = note: late-bound region is '_#4r
+ = note: late-bound region is '_#2r
+ = note: number of external vids: 3
+ = note: where '_#1r: '_#2r
+ = note: where '_#2r: '_#1r
+
+note: no external requirements
+ --> $DIR/nested-closures-regions.rs:8:5
+ |
+LL | for<'a> || -> () { for<'c> |_: &'a ()| -> () {}; };
+ | ^^^^^^^^^^^^^^^^
+ |
+ = note: defining type: main::{closure#0} with closure substs [
+ i8,
+ extern "rust-call" fn(()),
+ (),
+ ]
+ = note: late-bound region is '_#2r
+
+note: no external requirements
+ --> $DIR/nested-closures-regions.rs:7:1
+ |
+LL | fn main() {
+ | ^^^^^^^^^
+ |
+ = note: defining type: main
+
diff --git a/tests/ui/closures/binder/nested-closures.rs b/tests/ui/closures/binder/nested-closures.rs
new file mode 100644
index 000000000..b3c36e7ee
--- /dev/null
+++ b/tests/ui/closures/binder/nested-closures.rs
@@ -0,0 +1,7 @@
+// check-pass
+
+#![feature(closure_lifetime_binder)]
+
+fn main() {
+ for<'a> || -> () { for<'c> |_: &'a ()| -> () {}; };
+}
diff --git a/tests/ui/closures/binder/suggestion-for-introducing-lifetime-into-binder.rs b/tests/ui/closures/binder/suggestion-for-introducing-lifetime-into-binder.rs
new file mode 100644
index 000000000..b476dd50c
--- /dev/null
+++ b/tests/ui/closures/binder/suggestion-for-introducing-lifetime-into-binder.rs
@@ -0,0 +1,7 @@
+#![feature(closure_lifetime_binder)]
+fn main() {
+ for<> |_: &'a ()| -> () {};
+ //~^ ERROR use of undeclared lifetime name `'a`
+ for<'a> |_: &'b ()| -> () {};
+ //~^ ERROR use of undeclared lifetime name `'b`
+}
diff --git a/tests/ui/closures/binder/suggestion-for-introducing-lifetime-into-binder.stderr b/tests/ui/closures/binder/suggestion-for-introducing-lifetime-into-binder.stderr
new file mode 100644
index 000000000..1381acc15
--- /dev/null
+++ b/tests/ui/closures/binder/suggestion-for-introducing-lifetime-into-binder.stderr
@@ -0,0 +1,33 @@
+error[E0261]: use of undeclared lifetime name `'a`
+ --> $DIR/suggestion-for-introducing-lifetime-into-binder.rs:3:16
+ |
+LL | for<> |_: &'a ()| -> () {};
+ | ^^ undeclared lifetime
+ |
+help: consider introducing lifetime `'a` here
+ |
+LL | for<'a, > |_: &'a ()| -> () {};
+ | +++
+help: consider introducing lifetime `'a` here
+ |
+LL | fn main<'a>() {
+ | ++++
+
+error[E0261]: use of undeclared lifetime name `'b`
+ --> $DIR/suggestion-for-introducing-lifetime-into-binder.rs:5:18
+ |
+LL | for<'a> |_: &'b ()| -> () {};
+ | ^^ undeclared lifetime
+ |
+help: consider introducing lifetime `'b` here
+ |
+LL | for<'b, 'a> |_: &'b ()| -> () {};
+ | +++
+help: consider introducing lifetime `'b` here
+ |
+LL | fn main<'b>() {
+ | ++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0261`.