about summary refs log tree commit diff
path: root/tests/ui/async-await/higher-ranked-auto-trait-5.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/async-await/higher-ranked-auto-trait-5.rs')
-rw-r--r--tests/ui/async-await/higher-ranked-auto-trait-5.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/ui/async-await/higher-ranked-auto-trait-5.rs b/tests/ui/async-await/higher-ranked-auto-trait-5.rs
new file mode 100644
index 00000000000..9a8b3f4357c
--- /dev/null
+++ b/tests/ui/async-await/higher-ranked-auto-trait-5.rs
@@ -0,0 +1,54 @@
+// Repro for <https://github.com/rust-lang/rust/issues/130113#issue-2512517191>.
+//@ edition: 2021
+//@ revisions: assumptions no_assumptions
+//@[assumptions] compile-flags: -Zhigher-ranked-assumptions
+//@[assumptions] check-pass
+//@[no_assumptions] known-bug: #110338
+
+use std::future::Future;
+
+fn main() {
+    let call_me = Wrap(CallMeImpl { value: "test" });
+
+    assert_send(async {
+        call_me.call().await;
+    });
+}
+
+pub fn assert_send<F>(_future: F)
+where
+    F: Future + Send,
+{
+}
+
+pub trait CallMe {
+    fn call(&self) -> impl Future<Output = ()> + Send;
+}
+
+struct Wrap<T>(T);
+
+impl<S> CallMe for Wrap<S>
+where
+    S: CallMe + Send,
+{
+    // adding `+ Send` to this RPIT fixes the issue
+    fn call(&self) -> impl Future<Output = ()> {
+        self.0.call()
+    }
+}
+
+#[derive(Debug, Clone, Copy)]
+pub struct CallMeImpl<T> {
+    value: T,
+}
+
+impl<T> CallMe for CallMeImpl<T>
+where
+    // Can replace `Send` by `ToString`, `Clone`, whatever. When removing the
+    // `Send` bound, the compiler produces a higher-ranked lifetime error.
+    T: Send + 'static,
+{
+    fn call(&self) -> impl Future<Output = ()> {
+        async {}
+    }
+}