From e90950fee137f3e161a975bbb27b5aab5d25306f Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 4 Mar 2020 11:27:58 -0500 Subject: [PATCH] Re-apply commit 2cf7b3ad20fb823314426a5e33b0805045ec1d8a This ended up getting reverted by #1367, which re-introduced an unsound use of `Pin::new_unchecked` See my original PR #1374 for the reasoning behind this change. --- actix-http/src/h1/dispatcher.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 6276653d..ffdcd8d9 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -73,7 +73,7 @@ where U::Error: fmt::Display, { Normal(#[pin] InnerDispatcher), - Upgrade(#[pin] U::Future), + Upgrade(Pin>), } #[pin_project] @@ -123,8 +123,8 @@ where B: MessageBody, { None, - ExpectCall(#[pin] X::Future), - ServiceCall(#[pin] S::Future), + ExpectCall(Pin>), + ServiceCall(Pin>), SendPayload(#[pin] ResponseBody), } @@ -391,11 +391,11 @@ where } None => None, }, - State::ExpectCall(fut) => match fut.poll(cx) { + State::ExpectCall(fut) => match fut.as_mut().poll(cx) { Poll::Ready(Ok(req)) => { self.as_mut().send_continue(); this = self.as_mut().project(); - this.state.set(State::ServiceCall(this.service.call(req))); + this.state.set(State::ServiceCall(Box::pin(this.service.call(req)))); continue; } Poll::Ready(Err(e)) => { @@ -405,7 +405,7 @@ where } Poll::Pending => None, }, - State::ServiceCall(fut) => match fut.poll(cx) { + State::ServiceCall(fut) => match fut.as_mut().poll(cx) { Poll::Ready(Ok(res)) => { let (res, body) = res.into().replace_body(()); let state = self.as_mut().send_response(res, body)?; @@ -485,8 +485,8 @@ where ) -> Result, DispatchError> { // Handle `EXPECT: 100-Continue` header let req = if req.head().expect() { - let mut task = self.as_mut().project().expect.call(req); - match unsafe { Pin::new_unchecked(&mut task) }.poll(cx) { + let mut task = Box::pin(self.as_mut().project().expect.call(req)); + match task.as_mut().poll(cx) { Poll::Ready(Ok(req)) => { self.as_mut().send_continue(); req @@ -504,8 +504,8 @@ where }; // Call service - let mut task = self.as_mut().project().service.call(req); - match unsafe { Pin::new_unchecked(&mut task) }.poll(cx) { + let mut task = Box::pin(self.as_mut().project().service.call(req)); + match task.as_mut().poll(cx) { Poll::Ready(Ok(res)) => { let (res, body) = res.into().replace_body(()); self.send_response(res, body) @@ -807,7 +807,7 @@ where self.as_mut() .project() .inner - .set(DispatcherState::Upgrade(upgrade)); + .set(DispatcherState::Upgrade(Box::pin(upgrade))); return self.poll(cx); } @@ -855,7 +855,7 @@ where } } } - DispatcherState::Upgrade(fut) => fut.poll(cx).map_err(|e| { + DispatcherState::Upgrade(fut) => fut.as_mut().poll(cx).map_err(|e| { error!("Upgrade handler error: {}", e); DispatchError::Upgrade }),