diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 6ef48b038..f28e91f31 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -366,10 +366,9 @@ where io.poll_flush(cx) } - fn enter_linger(mut self: Pin<&mut Self>) { - let this = self.as_mut().project(); - this.flags.remove(Flags::KEEP_ALIVE); - this.flags.insert(Flags::LINGER | Flags::FINISHED); + fn enter_linger(flags: &mut Flags) { + flags.remove(Flags::KEEP_ALIVE); + flags.insert(Flags::LINGER | Flags::FINISHED); } fn ensure_linger_timer(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> bool { @@ -464,23 +463,19 @@ where let size = self.as_mut().send_response_inner(res, &body)?; match size { BodySize::None | BodySize::Sized(0) => { - let this = self.as_mut().project(); + let mut this = self.as_mut().project(); if close_after_response { if this.config.client_disconnect_deadline().is_some() { - drop(this); - self.as_mut().enter_linger(); + Self::enter_linger(this.flags); } else { - self.as_mut() - .project() - .flags - .insert(Flags::SHUTDOWN | Flags::FINISHED); + this.flags.insert(Flags::SHUTDOWN | Flags::FINISHED); } } else { this.flags.insert(Flags::FINISHED); } - self.as_mut().project().state.set(State::None); + this.state.set(State::None); } _ => self .as_mut() @@ -509,23 +504,19 @@ where let size = self.as_mut().send_response_inner(res, &body)?; match size { BodySize::None | BodySize::Sized(0) => { - let this = self.as_mut().project(); + let mut this = self.as_mut().project(); if close_after_response { if this.config.client_disconnect_deadline().is_some() { - drop(this); - self.as_mut().enter_linger(); + Self::enter_linger(this.flags); } else { - self.as_mut() - .project() - .flags - .insert(Flags::SHUTDOWN | Flags::FINISHED); + this.flags.insert(Flags::SHUTDOWN | Flags::FINISHED); } } else { this.flags.insert(Flags::FINISHED); } - self.as_mut().project().state.set(State::None); + this.state.set(State::None); } _ => self .as_mut() @@ -646,13 +637,9 @@ where if not_pipelined && close_after_response { if this.config.client_disconnect_deadline().is_some() { - drop(this); - self.as_mut().enter_linger(); + Self::enter_linger(this.flags); } else { - self.as_mut() - .project() - .flags - .insert(Flags::SHUTDOWN | Flags::FINISHED); + this.flags.insert(Flags::SHUTDOWN | Flags::FINISHED); } } else { this.flags.insert(Flags::FINISHED); @@ -708,13 +695,9 @@ where if not_pipelined && close_after_response { if this.config.client_disconnect_deadline().is_some() { - drop(this); - self.as_mut().enter_linger(); + Self::enter_linger(this.flags); } else { - self.as_mut() - .project() - .flags - .insert(Flags::SHUTDOWN | Flags::FINISHED); + this.flags.insert(Flags::SHUTDOWN | Flags::FINISHED); } } else { this.flags.insert(Flags::FINISHED); diff --git a/actix-web-codegen/src/route.rs b/actix-web-codegen/src/route.rs index cd1ad4c66..c2f7dbb31 100644 --- a/actix-web-codegen/src/route.rs +++ b/actix-web-codegen/src/route.rs @@ -513,20 +513,17 @@ pub(crate) fn with_methods(input: TokenStream) -> TokenStream { Err(err) => return input_and_compile_error(input, err), }; - let (methods, others) = ast - .attrs - .into_iter() - .map(|attr| match MethodType::from_path(attr.path()) { - Ok(method) => Ok((method, attr)), - Err(_) => Err(attr), - }) - .partition::, _>(Result::is_ok); + let mut methods = Vec::new(); - ast.attrs = others.into_iter().map(Result::unwrap_err).collect(); + for attr in std::mem::take(&mut ast.attrs) { + match MethodType::from_path(attr.path()) { + Ok(method) => methods.push((method, attr)), + Err(_) => ast.attrs.push(attr), + } + } let methods = match methods .into_iter() - .map(Result::unwrap) .map(|(method, attr)| { attr.parse_args() .and_then(|args| Args::new(args, Some(method)))