summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/supertrait-hint-cycle.rs
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/supertrait-hint-cycle.rs
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/supertrait-hint-cycle.rs')
-rw-r--r--tests/ui/closures/supertrait-hint-cycle.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/ui/closures/supertrait-hint-cycle.rs b/tests/ui/closures/supertrait-hint-cycle.rs
new file mode 100644
index 000000000..dbb06b2ef
--- /dev/null
+++ b/tests/ui/closures/supertrait-hint-cycle.rs
@@ -0,0 +1,65 @@
+// edition:2021
+// check-pass
+
+#![feature(type_alias_impl_trait)]
+#![feature(closure_lifetime_binder)]
+
+use std::future::Future;
+
+trait AsyncFn<I, R>: FnMut(I) -> Self::Fut {
+ type Fut: Future<Output = R>;
+}
+
+impl<F, I, R, Fut> AsyncFn<I, R> for F
+where
+ Fut: Future<Output = R>,
+ F: FnMut(I) -> Fut,
+{
+ type Fut = Fut;
+}
+
+async fn call<C, R, F>(mut ctx: C, mut f: F) -> Result<R, ()>
+where
+ F: for<'a> AsyncFn<&'a mut C, Result<R, ()>>,
+{
+ loop {
+ match f(&mut ctx).await {
+ Ok(val) => return Ok(val),
+ Err(_) => continue,
+ }
+ }
+}
+
+trait Cap<'a> {}
+impl<T> Cap<'_> for T {}
+
+fn works(ctx: &mut usize) {
+ let mut inner = 0;
+
+ type Ret<'a, 'b: 'a> = impl Future<Output = Result<usize, ()>> + 'a + Cap<'b>;
+
+ let callback = for<'a, 'b> |c: &'a mut &'b mut usize| -> Ret<'a, 'b> {
+ inner += 1;
+ async move {
+ let _c = c;
+ Ok(1usize)
+ }
+ };
+ call(ctx, callback);
+}
+
+fn doesnt_work_but_should(ctx: &mut usize) {
+ let mut inner = 0;
+
+ type Ret<'a, 'b: 'a> = impl Future<Output = Result<usize, ()>> + 'a + Cap<'b>;
+
+ call(ctx, for<'a, 'b> |c: &'a mut &'b mut usize| -> Ret<'a, 'b> {
+ inner += 1;
+ async move {
+ let _c = c;
+ Ok(1usize)
+ }
+ });
+}
+
+fn main() {}