// Regression test for #61320 // This is the same issue as #61311, just a larger test case. // check-pass pub struct AndThen where A: Future, B: IntoFuture, { state: (A, B::Future, F), } pub struct FutureResult { inner: Option>, } impl Future for FutureResult { type Item = T; type Error = E; fn poll(&mut self) -> Poll { unimplemented!() } } pub type Poll = Result; impl Future for AndThen where A: Future, B: IntoFuture, F: FnOnce(A::Item) -> B, { type Item = B::Item; type Error = B::Error; fn poll(&mut self) -> Poll { unimplemented!() } } pub trait Future { type Item; type Error; fn poll(&mut self) -> Poll; fn and_then(self, f: F) -> AndThen where F: FnOnce(Self::Item) -> B, B: IntoFuture, Self: Sized, { unimplemented!() } } pub trait IntoFuture { /// The future that this type can be converted into. type Future: Future; /// The item that the future may resolve with. type Item; /// The error that the future may resolve with. type Error; /// Consumes this object and produces a future. fn into_future(self) -> Self::Future; } impl IntoFuture for F { type Future = F; type Item = F::Item; type Error = F::Error; fn into_future(self) -> F { self } } impl Future for ::std::boxed::Box { type Item = F::Item; type Error = F::Error; fn poll(&mut self) -> Poll { (**self).poll() } } impl IntoFuture for Result { type Future = FutureResult; type Item = T; type Error = E; fn into_future(self) -> FutureResult { unimplemented!() } } struct Request(T); trait RequestContext {} impl RequestContext for T {} struct NoContext; impl AsRef for NoContext { fn as_ref(&self) -> &Self { &NoContext } } type BoxedError = Box; type DefaultFuture = Box + Send>; trait Guard: Sized { type Result: IntoFuture; fn from_request(request: &Request<()>) -> Self::Result; } trait FromRequest: Sized { type Context; type Future: Future + Send; fn from_request(request: Request<()>) -> Self::Future; } struct MyGuard; impl Guard for MyGuard { type Result = Result; fn from_request(_request: &Request<()>) -> Self::Result { Ok(MyGuard) } } struct Generic { _inner: I, } impl FromRequest for Generic where MyGuard: Guard, ::Result: IntoFuture, <::Result as IntoFuture>::Future: Send, I: FromRequest, { type Future = DefaultFuture; type Context = NoContext; fn from_request(headers: Request<()>) -> DefaultFuture { let _future = ::from_request(&headers) .into_future() .and_then(move |_| { ::from_request(headers) .into_future() .and_then(move |fld_inner| Ok(Generic { _inner: fld_inner }).into_future()) }); panic!(); } } fn main() {}