diff --git a/tests/ui/type-alias-impl-trait/send-bound-nested-async-95719.rs b/tests/ui/type-alias-impl-trait/send-bound-nested-async-95719.rs new file mode 100644 index 0000000000000..9f73dea641197 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/send-bound-nested-async-95719.rs @@ -0,0 +1,53 @@ +// Regression test for . +// The `Send` bound of a GAT `impl Future` was lost when the future was +// wrapped in another `async fn`, failing with "the parameter type `G` may +// not live long enough". +//@ check-pass +//@ edition: 2021 + +#![feature(impl_trait_in_assoc_type)] + +use std::future::Future; + +pub trait Get: Send + Sync { + type Ret<'a>: Future + Send + 'a + where + Self: 'a; + fn get<'a>(&'a self) -> Self::Ret<'a> + where + Self: 'a; +} + +impl Get for usize { + type Ret<'a> + = impl Future + Send + 'a + where + Self: 'a; + + fn get<'a>(&'a self) -> Self::Ret<'a> + where + Self: 'a, + { + async move { *self } + } +} + +fn is_send + Send>(_f: &F) -> bool { + true +} + +async fn wrap(g: &G) -> usize { + let fut = g.get(); + assert!(is_send(&fut)); + fut.await +} + +async fn wrap_wrap(g: &G) -> usize { + let fut = wrap(g); + assert!(is_send(&fut)); + fut.await +} + +fn main() { + let _ = wrap_wrap(&0usize); +}