diff --git a/actix-http/benches/status-line.rs b/actix-http/benches/status-line.rs index 51f840f89..252a54dea 100644 --- a/actix-http/benches/status-line.rs +++ b/actix-http/benches/status-line.rs @@ -176,7 +176,7 @@ mod _original { buf[5] = b'0'; buf[7] = b'9'; } - _ => (), + _ => {}, } let mut curr: isize = 12; diff --git a/actix-http/src/body.rs b/actix-http/src/body.rs index c5d831c45..9636f2941 100644 --- a/actix-http/src/body.rs +++ b/actix-http/src/body.rs @@ -371,7 +371,7 @@ impl MessageBody for String { pub struct BodyStream { #[pin] stream: S, - _t: PhantomData, + _phantom: PhantomData, } impl BodyStream @@ -382,7 +382,7 @@ where pub fn new(stream: S) -> Self { BodyStream { stream, - _t: PhantomData, + _phantom: PhantomData, } } } diff --git a/actix-http/src/builder.rs b/actix-http/src/builder.rs index ecb4327df..fa430c4fe 100644 --- a/actix-http/src/builder.rs +++ b/actix-http/src/builder.rs @@ -28,7 +28,7 @@ pub struct HttpServiceBuilder { expect: X, upgrade: Option, on_connect_ext: Option>>, - _t: PhantomData, + _phantom: PhantomData, } impl HttpServiceBuilder @@ -49,7 +49,7 @@ where expect: ExpectHandler, upgrade: None, on_connect_ext: None, - _t: PhantomData, + _phantom: PhantomData, } } } @@ -138,7 +138,7 @@ where expect: expect.into_factory(), upgrade: self.upgrade, on_connect_ext: self.on_connect_ext, - _t: PhantomData, + _phantom: PhantomData, } } @@ -163,7 +163,7 @@ where expect: self.expect, upgrade: Some(upgrade.into_factory()), on_connect_ext: self.on_connect_ext, - _t: PhantomData, + _phantom: PhantomData, } } diff --git a/actix-http/src/client/connector.rs b/actix-http/src/client/connector.rs index b638336f7..326a2fc60 100644 --- a/actix-http/src/client/connector.rs +++ b/actix-http/src/client/connector.rs @@ -52,7 +52,7 @@ pub struct Connector { config: ConnectorConfig, #[allow(dead_code)] ssl: SslConnector, - _t: PhantomData, + _phantom: PhantomData, } trait Io: AsyncRead + AsyncWrite + Unpin {} @@ -72,7 +72,7 @@ impl Connector<(), ()> { ssl: Self::build_ssl(vec![b"h2".to_vec(), b"http/1.1".to_vec()]), connector: default_connector(), config: ConnectorConfig::default(), - _t: PhantomData, + _phantom: PhantomData, } } @@ -126,7 +126,7 @@ impl Connector { connector, config: self.config, ssl: self.ssl, - _t: PhantomData, + _phantom: PhantomData, } } } @@ -468,11 +468,11 @@ mod connect_impl { match req.uri.scheme_str() { Some("https") | Some("wss") => Either::Right(InnerConnectorResponseB { fut: self.ssl_pool.call(req), - _t: PhantomData, + _phantom: PhantomData, }), _ => Either::Left(InnerConnectorResponseA { fut: self.tcp_pool.call(req), - _t: PhantomData, + _phantom: PhantomData, }), } } @@ -486,7 +486,7 @@ mod connect_impl { { #[pin] fut: as Service>::Future, - _t: PhantomData, + _phantom: PhantomData, } impl Future for InnerConnectorResponseA @@ -513,7 +513,7 @@ mod connect_impl { { #[pin] fut: as Service>::Future, - _t: PhantomData, + _phantom: PhantomData, } impl Future for InnerConnectorResponseB diff --git a/actix-http/src/client/h1proto.rs b/actix-http/src/client/h1proto.rs index 754c53968..3265394f0 100644 --- a/actix-http/src/client/h1proto.rs +++ b/actix-http/src/client/h1proto.rs @@ -72,7 +72,7 @@ where // send request body match body.size() { - BodySize::None | BodySize::Empty | BodySize::Sized(0) => (), + BodySize::None | BodySize::Empty | BodySize::Sized(0) => {}, _ => send_body(body, Pin::new(&mut framed_inner)).await?, }; diff --git a/actix-http/src/client/h2proto.rs b/actix-http/src/client/h2proto.rs index 3f9a981f4..d35f9e24b 100644 --- a/actix-http/src/client/h2proto.rs +++ b/actix-http/src/client/h2proto.rs @@ -89,7 +89,7 @@ where CONNECTION | TRANSFER_ENCODING => continue, // http2 specific CONTENT_LENGTH if skip_len => continue, // DATE => has_date = true, - _ => (), + _ => {}, } req.headers_mut().append(key, value.clone()); } diff --git a/actix-http/src/client/pool.rs b/actix-http/src/client/pool.rs index f9973a850..cee823a42 100644 --- a/actix-http/src/client/pool.rs +++ b/actix-http/src/client/pool.rs @@ -334,7 +334,7 @@ where let mut read_buf = ReadBuf::new(&mut buf); if let ConnectionType::H1(ref mut s) = io { match Pin::new(s).poll_read(cx, &mut read_buf) { - Poll::Pending => (), + Poll::Pending => {}, Poll::Ready(Ok(())) if !read_buf.filled().is_empty() => { if let Some(timeout) = self.config.disconnect_timeout { if let ConnectionType::H1(io) = io { diff --git a/actix-http/src/h1/decoder.rs b/actix-http/src/h1/decoder.rs index 8e891dc5c..d3ac497b6 100644 --- a/actix-http/src/h1/decoder.rs +++ b/actix-http/src/h1/decoder.rs @@ -137,7 +137,7 @@ pub(crate) trait MessageType: Sized { expect = true; } } - _ => (), + _ => {}, } headers.append(name, value); @@ -685,7 +685,7 @@ mod tests { match MessageDecoder::::default().decode($e) { Err(err) => match err { ParseError::Io(_) => unreachable!("Parse error expected"), - _ => (), + _ => {}, }, _ => unreachable!("Error expected"), } diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 41caea902..41e923b6e 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -736,7 +736,7 @@ where let _ = this.ka_timer.as_mut().as_pin_mut().unwrap().poll(cx); } } - Poll::Pending => (), + Poll::Pending => {}, } Ok(()) diff --git a/actix-http/src/h1/encoder.rs b/actix-http/src/h1/encoder.rs index 4fadbb518..69800e861 100644 --- a/actix-http/src/h1/encoder.rs +++ b/actix-http/src/h1/encoder.rs @@ -21,7 +21,7 @@ const AVERAGE_HEADER_SIZE: usize = 30; pub(crate) struct MessageEncoder { pub length: BodySize, pub te: TransferEncoding, - _t: PhantomData, + _phantom: PhantomData, } impl Default for MessageEncoder { @@ -29,7 +29,7 @@ impl Default for MessageEncoder { MessageEncoder { length: BodySize::None, te: TransferEncoding::empty(), - _t: PhantomData, + _phantom: PhantomData, } } } @@ -118,7 +118,7 @@ pub(crate) trait MessageType: Sized { dst.put_slice(b"connection: close\r\n") } } - _ => (), + _ => {}, } // merging headers from head and extra headers. HeaderMap::new() does not allocate. @@ -148,7 +148,7 @@ pub(crate) trait MessageType: Sized { CONNECTION => continue, TRANSFER_ENCODING | CONTENT_LENGTH if skip_len => continue, DATE => has_date = true, - _ => (), + _ => {}, } let k = key.as_str().as_bytes(); diff --git a/actix-http/src/h1/service.rs b/actix-http/src/h1/service.rs index 67f1127c7..34b7e31a1 100644 --- a/actix-http/src/h1/service.rs +++ b/actix-http/src/h1/service.rs @@ -30,7 +30,7 @@ pub struct H1Service { expect: X, upgrade: Option, on_connect_ext: Option>>, - _t: PhantomData, + _phantom: PhantomData, } impl H1Service @@ -52,7 +52,7 @@ where expect: ExpectHandler, upgrade: None, on_connect_ext: None, - _t: PhantomData, + _phantom: PhantomData, } } } @@ -211,7 +211,7 @@ where srv: self.srv, upgrade: self.upgrade, on_connect_ext: self.on_connect_ext, - _t: PhantomData, + _phantom: PhantomData, } } @@ -227,7 +227,7 @@ where srv: self.srv, expect: self.expect, on_connect_ext: self.on_connect_ext, - _t: PhantomData, + _phantom: PhantomData, } } @@ -270,7 +270,7 @@ where upgrade: None, on_connect_ext: self.on_connect_ext.clone(), cfg: Some(self.cfg.clone()), - _t: PhantomData, + _phantom: PhantomData, } } } @@ -299,7 +299,7 @@ where upgrade: Option, on_connect_ext: Option>>, cfg: Option, - _t: PhantomData<(T, B)>, + _phantom: PhantomData<(T, B)>, } impl Future for H1ServiceResponse @@ -371,7 +371,7 @@ where upgrade: Option>, on_connect_ext: Option>>, cfg: ServiceConfig, - _t: PhantomData, + _phantom: PhantomData, } impl H1ServiceHandler @@ -398,7 +398,7 @@ where upgrade: upgrade.map(CloneableService::new), cfg, on_connect_ext, - _t: PhantomData, + _phantom: PhantomData, } } } diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index 4aeda942a..b8828edd0 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -1,14 +1,15 @@ -use std::convert::TryFrom; use std::future::Future; use std::marker::PhantomData; use std::net; use std::pin::Pin; use std::task::{Context, Poll}; +use std::{cmp, convert::TryFrom}; use actix_codec::{AsyncRead, AsyncWrite}; use actix_rt::time::{Instant, Sleep}; use actix_service::Service; use bytes::{Bytes, BytesMut}; +use futures_core::ready; use h2::server::{Connection, SendResponse}; use h2::SendStream; use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING}; @@ -27,7 +28,7 @@ use crate::Extensions; const CHUNK_SIZE: usize = 16_384; -/// Dispatcher for HTTP/2 protocol +/// Dispatcher for HTTP/2 protocol. #[pin_project::pin_project] pub struct Dispatcher where @@ -42,7 +43,7 @@ where peer_addr: Option, ka_expire: Instant, ka_timer: Option, - _t: PhantomData, + _phantom: PhantomData, } impl Dispatcher @@ -50,7 +51,6 @@ where T: AsyncRead + AsyncWrite + Unpin, S: Service, S::Error: Into, - // S::Future: 'static, S::Response: Into>, B: MessageBody, { @@ -86,7 +86,7 @@ where on_connect_data, ka_expire, ka_timer, - _t: PhantomData, + _phantom: PhantomData, } } } @@ -107,10 +107,12 @@ where let this = self.get_mut(); loop { - match Pin::new(&mut this.connection).poll_accept(cx) { - Poll::Ready(None) => return Poll::Ready(Ok(())), - Poll::Ready(Some(Err(err))) => return Poll::Ready(Err(err.into())), - Poll::Ready(Some(Ok((req, res)))) => { + match ready!(Pin::new(&mut this.connection).poll_accept(cx)) { + None => return Poll::Ready(Ok(())), + + Some(Err(err)) => return Poll::Ready(Err(err.into())), + + Some(Ok((req, res))) => { // update keep-alive expire if this.ka_timer.is_some() { if let Some(expire) = this.config.keep_alive_expire() { @@ -119,11 +121,9 @@ where } let (parts, body) = req.into_parts(); - let mut req = Request::with_payload(Payload::< - crate::payload::PayloadStream, - >::H2( - crate::h2::Payload::new(body) - )); + let pl = crate::h2::Payload::new(body); + let pl = Payload::::H2(pl); + let mut req = Request::with_payload(pl); let head = &mut req.head_mut(); head.uri = parts.uri; @@ -135,22 +135,18 @@ where // merge on_connect_ext data into request extensions req.extensions_mut().drain_from(&mut this.on_connect_data); - actix_rt::spawn(ServiceResponse::< - S::Future, - S::Response, - S::Error, - B, - > { + let svc = ServiceResponse:: { state: ServiceResponseState::ServiceCall( this.service.call(req), Some(res), ), config: this.config.clone(), buffer: None, - _t: PhantomData, - }); + _phantom: PhantomData, + }; + + actix_rt::spawn(svc); } - Poll::Pending => return Poll::Pending, } } } @@ -162,7 +158,7 @@ struct ServiceResponse { state: ServiceResponseState, config: ServiceConfig, buffer: Option, - _t: PhantomData<(I, E)>, + _phantom: PhantomData<(I, E)>, } #[pin_project::pin_project(project = ServiceResponseStateProj)] @@ -199,8 +195,9 @@ where skip_len = true; *size = BodySize::Stream; } - _ => (), + _ => {} } + let _ = match size { BodySize::None | BodySize::Stream => None, BodySize::Empty => res @@ -215,11 +212,13 @@ where // copy headers for (key, value) in head.headers.iter() { match *key { - CONNECTION | TRANSFER_ENCODING => continue, // http2 specific + // omit HTTP/1 only headers + CONNECTION | TRANSFER_ENCODING => continue, CONTENT_LENGTH if skip_len => continue, DATE => has_date = true, - _ => (), + _ => {} } + res.headers_mut().append(key, value.clone()); } @@ -251,109 +250,117 @@ where let mut this = self.as_mut().project(); match this.state.project() { - ServiceResponseStateProj::ServiceCall(call, send) => match call.poll(cx) { - Poll::Ready(Ok(res)) => { - let (res, body) = res.into().replace_body(()); + ServiceResponseStateProj::ServiceCall(call, send) => { + match ready!(call.poll(cx)) { + Ok(res) => { + let (res, body) = res.into().replace_body(()); - let mut send = send.take().unwrap(); - let mut size = body.size(); - let h2_res = self.as_mut().prepare_response(res.head(), &mut size); - this = self.as_mut().project(); + let mut send = send.take().unwrap(); + let mut size = body.size(); + let h2_res = + self.as_mut().prepare_response(res.head(), &mut size); + this = self.as_mut().project(); - let stream = match send.send_response(h2_res, size.is_eof()) { - Err(e) => { - trace!("Error sending h2 response: {:?}", e); - return Poll::Ready(()); + let stream = match send.send_response(h2_res, size.is_eof()) { + Err(e) => { + trace!("Error sending HTTP/2 response: {:?}", e); + return Poll::Ready(()); + } + Ok(stream) => stream, + }; + + if size.is_eof() { + Poll::Ready(()) + } else { + this.state + .set(ServiceResponseState::SendPayload(stream, body)); + self.poll(cx) } - Ok(stream) => stream, - }; + } - if size.is_eof() { - Poll::Ready(()) - } else { - this.state - .set(ServiceResponseState::SendPayload(stream, body)); - self.poll(cx) + Err(e) => { + let res: Response = e.into().into(); + let (res, body) = res.replace_body(()); + + let mut send = send.take().unwrap(); + let mut size = body.size(); + let h2_res = + self.as_mut().prepare_response(res.head(), &mut size); + this = self.as_mut().project(); + + let stream = match send.send_response(h2_res, size.is_eof()) { + Err(e) => { + trace!("Error sending HTTP/2 response: {:?}", e); + return Poll::Ready(()); + } + Ok(stream) => stream, + }; + + if size.is_eof() { + Poll::Ready(()) + } else { + this.state.set(ServiceResponseState::SendPayload( + stream, + body.into_body(), + )); + self.poll(cx) + } } } - Poll::Pending => Poll::Pending, - Poll::Ready(Err(e)) => { - let res: Response = e.into().into(); - let (res, body) = res.replace_body(()); + } - let mut send = send.take().unwrap(); - let mut size = body.size(); - let h2_res = self.as_mut().prepare_response(res.head(), &mut size); - this = self.as_mut().project(); - - let stream = match send.send_response(h2_res, size.is_eof()) { - Err(e) => { - trace!("Error sending h2 response: {:?}", e); - return Poll::Ready(()); - } - Ok(stream) => stream, - }; - - if size.is_eof() { - Poll::Ready(()) - } else { - this.state.set(ServiceResponseState::SendPayload( - stream, - body.into_body(), - )); - self.poll(cx) - } - } - }, ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => { loop { loop { - if let Some(ref mut buffer) = this.buffer { - match stream.poll_capacity(cx) { - Poll::Pending => return Poll::Pending, - Poll::Ready(None) => return Poll::Ready(()), - Poll::Ready(Some(Ok(cap))) => { - let len = buffer.len(); - let bytes = buffer.split_to(std::cmp::min(cap, len)); + match this.buffer { + Some(ref mut buffer) => { + match ready!(stream.poll_capacity(cx)) { + None => return Poll::Ready(()), - if let Err(e) = stream.send_data(bytes, false) { + Some(Ok(cap)) => { + let len = buffer.len(); + let bytes = buffer.split_to(cmp::min(cap, len)); + + if let Err(e) = stream.send_data(bytes, false) { + warn!("{:?}", e); + return Poll::Ready(()); + } else if !buffer.is_empty() { + let cap = cmp::min(buffer.len(), CHUNK_SIZE); + stream.reserve_capacity(cap); + } else { + this.buffer.take(); + } + } + + Some(Err(e)) => { warn!("{:?}", e); return Poll::Ready(()); - } else if !buffer.is_empty() { - let cap = - std::cmp::min(buffer.len(), CHUNK_SIZE); - stream.reserve_capacity(cap); - } else { - this.buffer.take(); } } - Poll::Ready(Some(Err(e))) => { - warn!("{:?}", e); - return Poll::Ready(()); - } } - } else { - match body.as_mut().poll_next(cx) { - Poll::Pending => return Poll::Pending, - Poll::Ready(None) => { + + None => match ready!(body.as_mut().poll_next(cx)) { + None => { if let Err(e) = stream.send_data(Bytes::new(), true) { warn!("{:?}", e); } return Poll::Ready(()); } - Poll::Ready(Some(Ok(chunk))) => { - stream.reserve_capacity(std::cmp::min( + + Some(Ok(chunk)) => { + stream.reserve_capacity(cmp::min( chunk.len(), CHUNK_SIZE, )); *this.buffer = Some(chunk); } - Poll::Ready(Some(Err(e))) => { + + Some(Err(e)) => { error!("Response payload stream error: {:?}", e); return Poll::Ready(()); } - } + }, } } } diff --git a/actix-http/src/h2/mod.rs b/actix-http/src/h2/mod.rs index b00969227..c05ee609d 100644 --- a/actix-http/src/h2/mod.rs +++ b/actix-http/src/h2/mod.rs @@ -1,9 +1,12 @@ -//! HTTP/2 implementation -use std::pin::Pin; -use std::task::{Context, Poll}; +//! HTTP/2 implementation. + +use std::{ + pin::Pin, + task::{Context, Poll}, +}; use bytes::Bytes; -use futures_core::Stream; +use futures_core::{ready, Stream}; use h2::RecvStream; mod dispatcher; @@ -13,14 +16,14 @@ pub use self::dispatcher::Dispatcher; pub use self::service::H2Service; use crate::error::PayloadError; -/// H2 receive stream +/// HTTP/2 peer stream. pub struct Payload { - pl: RecvStream, + stream: RecvStream, } impl Payload { - pub(crate) fn new(pl: RecvStream) -> Self { - Self { pl } + pub(crate) fn new(stream: RecvStream) -> Self { + Self { stream } } } @@ -33,18 +36,17 @@ impl Stream for Payload { ) -> Poll> { let this = self.get_mut(); - match Pin::new(&mut this.pl).poll_data(cx) { - Poll::Ready(Some(Ok(chunk))) => { + match ready!(Pin::new(&mut this.stream).poll_data(cx)) { + Some(Ok(chunk)) => { let len = chunk.len(); - if let Err(err) = this.pl.flow_control().release_capacity(len) { - Poll::Ready(Some(Err(err.into()))) - } else { - Poll::Ready(Some(Ok(chunk))) + + match this.stream.flow_control().release_capacity(len) { + Ok(()) => Poll::Ready(Some(Ok(chunk))), + Err(err) => Poll::Ready(Some(Err(err.into()))), } } - Poll::Ready(Some(Err(err))) => Poll::Ready(Some(Err(err.into()))), - Poll::Pending => Poll::Pending, - Poll::Ready(None) => Poll::Ready(None), + Some(Err(err)) => Poll::Ready(Some(Err(err.into()))), + None => Poll::Ready(None), } } } diff --git a/actix-http/src/h2/service.rs b/actix-http/src/h2/service.rs index 719f3622c..462f5c2c1 100644 --- a/actix-http/src/h2/service.rs +++ b/actix-http/src/h2/service.rs @@ -26,12 +26,12 @@ use crate::{ConnectCallback, Extensions}; use super::dispatcher::Dispatcher; -/// `ServiceFactory` implementation for HTTP2 transport +/// `ServiceFactory` implementation for HTTP/2 transport pub struct H2Service { srv: S, cfg: ServiceConfig, on_connect_ext: Option>>, - _t: PhantomData<(T, B)>, + _phantom: PhantomData<(T, B)>, } impl H2Service @@ -42,7 +42,7 @@ where >::Future: 'static, B: MessageBody + 'static, { - /// Create new `HttpService` instance with config. + /// Create new `H2Service` instance with config. pub(crate) fn with_config>( cfg: ServiceConfig, service: F, @@ -51,7 +51,7 @@ where cfg, on_connect_ext: None, srv: service.into_factory(), - _t: PhantomData, + _phantom: PhantomData, } } @@ -70,7 +70,7 @@ where >::Future: 'static, B: MessageBody + 'static, { - /// Create simple tcp based service + /// Create plain TCP based service pub fn tcp( self, ) -> impl ServiceFactory< @@ -106,7 +106,7 @@ mod openssl { >::Future: 'static, B: MessageBody + 'static, { - /// Create ssl based service + /// Create OpenSSL based service pub fn openssl( self, acceptor: SslAcceptor, @@ -149,7 +149,7 @@ mod rustls { >::Future: 'static, B: MessageBody + 'static, { - /// Create openssl based service + /// Create Rustls based service pub fn rustls( self, mut config: ServerConfig, @@ -200,7 +200,7 @@ where fut: self.srv.new_service(()), cfg: Some(self.cfg.clone()), on_connect_ext: self.on_connect_ext.clone(), - _t: PhantomData, + _phantom: PhantomData, } } } @@ -215,7 +215,7 @@ where fut: S::Future, cfg: Option, on_connect_ext: Option>>, - _t: PhantomData, + _phantom: PhantomData, } impl Future for H2ServiceResponse @@ -232,14 +232,14 @@ where fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let this = self.as_mut().project(); - Poll::Ready(ready!(this.fut.poll(cx)).map(|service| { + this.fut.poll(cx).map_ok(|service| { let this = self.as_mut().project(); H2ServiceHandler::new( this.cfg.take().unwrap(), this.on_connect_ext.clone(), service, ) - })) + }) } } @@ -251,7 +251,7 @@ where srv: CloneableService, cfg: ServiceConfig, on_connect_ext: Option>>, - _t: PhantomData, + _phantom: PhantomData, } impl H2ServiceHandler @@ -271,7 +271,7 @@ where cfg, on_connect_ext, srv: CloneableService::new(srv), - _t: PhantomData, + _phantom: PhantomData, } } } @@ -363,8 +363,8 @@ where ref peer_addr, ref mut on_connect_data, ref mut handshake, - ) => match Pin::new(handshake).poll(cx) { - Poll::Ready(Ok(conn)) => { + ) => match ready!(Pin::new(handshake).poll(cx)) { + Ok(conn) => { self.state = State::Incoming(Dispatcher::new( srv.take().unwrap(), conn, @@ -375,11 +375,10 @@ where )); self.poll(cx) } - Poll::Ready(Err(err)) => { + Err(err) => { trace!("H2 handshake error: {}", err); Poll::Ready(Err(err.into())) } - Poll::Pending => Poll::Pending, }, } } diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs index f23115cd5..af625b1bf 100644 --- a/actix-http/src/service.rs +++ b/actix-http/src/service.rs @@ -28,7 +28,7 @@ pub struct HttpService { expect: X, upgrade: Option, on_connect_ext: Option>>, - _t: PhantomData, + _phantom: PhantomData, } impl HttpService @@ -65,7 +65,7 @@ where expect: h1::ExpectHandler, upgrade: None, on_connect_ext: None, - _t: PhantomData, + _phantom: PhantomData, } } @@ -80,7 +80,7 @@ where expect: h1::ExpectHandler, upgrade: None, on_connect_ext: None, - _t: PhantomData, + _phantom: PhantomData, } } } @@ -112,7 +112,7 @@ where srv: self.srv, upgrade: self.upgrade, on_connect_ext: self.on_connect_ext, - _t: PhantomData, + _phantom: PhantomData, } } @@ -133,7 +133,7 @@ where srv: self.srv, expect: self.expect, on_connect_ext: self.on_connect_ext, - _t: PhantomData, + _phantom: PhantomData, } } @@ -348,7 +348,7 @@ where upgrade: None, on_connect_ext: self.on_connect_ext.clone(), cfg: self.cfg.clone(), - _t: PhantomData, + _phantom: PhantomData, } } } @@ -371,7 +371,7 @@ where upgrade: Option, on_connect_ext: Option>>, cfg: ServiceConfig, - _t: PhantomData<(T, B)>, + _phantom: PhantomData<(T, B)>, } impl Future for HttpServiceResponse @@ -446,7 +446,7 @@ where upgrade: Option>, cfg: ServiceConfig, on_connect_ext: Option>>, - _t: PhantomData, + _phantom: PhantomData, } impl HttpServiceHandler @@ -474,7 +474,7 @@ where srv: CloneableService::new(srv), expect: CloneableService::new(expect), upgrade: upgrade.map(CloneableService::new), - _t: PhantomData, + _phantom: PhantomData, } } } diff --git a/actix-http/src/ws/codec.rs b/actix-http/src/ws/codec.rs index 7c9628b1a..bb68a4d76 100644 --- a/actix-http/src/ws/codec.rs +++ b/actix-http/src/ws/codec.rs @@ -184,7 +184,7 @@ impl Encoder for Codec { } } }, - Message::Nop => (), + Message::Nop => {}, } Ok(()) } diff --git a/actix-http/src/ws/frame.rs b/actix-http/src/ws/frame.rs index 0598a9b4e..25231b2f3 100644 --- a/actix-http/src/ws/frame.rs +++ b/actix-http/src/ws/frame.rs @@ -125,7 +125,7 @@ impl Parser { debug!("Received close frame with payload length exceeding 125. Morphing to protocol close frame."); return Ok(Some((true, OpCode::Close, None))); } - _ => (), + _ => {}, } // unmask diff --git a/actix-http/src/ws/proto.rs b/actix-http/src/ws/proto.rs index fc271a8f5..06db60c67 100644 --- a/actix-http/src/ws/proto.rs +++ b/actix-http/src/ws/proto.rs @@ -222,7 +222,7 @@ mod test { macro_rules! opcode_into { ($from:expr => $opcode:pat) => { match OpCode::from($from) { - e @ $opcode => (), + e @ $opcode => {}, e => unreachable!("{:?}", e), } }; @@ -232,7 +232,7 @@ mod test { ($from:expr => $opcode:pat) => { let res: u8 = $from.into(); match res { - e @ $opcode => (), + e @ $opcode => {}, e => unreachable!("{:?}", e), } }; diff --git a/actix-multipart/src/server.rs b/actix-multipart/src/server.rs index b476f1791..73b2756e5 100644 --- a/actix-multipart/src/server.rs +++ b/actix-multipart/src/server.rs @@ -326,7 +326,7 @@ impl InnerMultipart { } } } - _ => (), + _ => {}, } // read field headers for next field @@ -835,7 +835,7 @@ mod tests { async fn test_boundary() { let headers = HeaderMap::new(); match Multipart::boundary(&headers) { - Err(MultipartError::NoContentType) => (), + Err(MultipartError::NoContentType) => {}, _ => unreachable!("should not happen"), } @@ -846,7 +846,7 @@ mod tests { ); match Multipart::boundary(&headers) { - Err(MultipartError::ParseContentType) => (), + Err(MultipartError::ParseContentType) => {}, _ => unreachable!("should not happen"), } @@ -856,7 +856,7 @@ mod tests { header::HeaderValue::from_static("multipart/mixed"), ); match Multipart::boundary(&headers) { - Err(MultipartError::Boundary) => (), + Err(MultipartError::Boundary) => {}, _ => unreachable!("should not happen"), } @@ -956,17 +956,17 @@ mod tests { let mut multipart = Multipart::new(&headers, payload); match multipart.next().await.unwrap() { - Ok(_) => (), + Ok(_) => {}, _ => unreachable!(), } match multipart.next().await.unwrap() { - Ok(_) => (), + Ok(_) => {}, _ => unreachable!(), } match multipart.next().await { - None => (), + None => {}, _ => unreachable!(), } } @@ -993,7 +993,7 @@ mod tests { _ => unreachable!(), } match field.next().await { - None => (), + None => {}, _ => unreachable!(), } } @@ -1010,7 +1010,7 @@ mod tests { _ => unreachable!(), } match field.next().await { - None => (), + None => {}, _ => unreachable!(), } } @@ -1018,7 +1018,7 @@ mod tests { } match multipart.next().await { - None => (), + None => {}, _ => unreachable!(), } } @@ -1066,7 +1066,7 @@ mod tests { } match multipart.next().await { - None => (), + None => {}, _ => unreachable!(), } } diff --git a/actix-web-actors/tests/test_ws.rs b/actix-web-actors/tests/test_ws.rs index dda9f6f0b..a8ade9ff4 100644 --- a/actix-web-actors/tests/test_ws.rs +++ b/actix-web-actors/tests/test_ws.rs @@ -21,7 +21,7 @@ impl StreamHandler> for Ws { ws::Message::Text(text) => ctx.text(text), ws::Message::Binary(bin) => ctx.binary(bin), ws::Message::Close(reason) => ctx.close(reason), - _ => (), + _ => {}, } } } diff --git a/awc/src/request.rs b/awc/src/request.rs index 1e49aae3c..abfd39351 100644 --- a/awc/src/request.rs +++ b/awc/src/request.rs @@ -523,7 +523,7 @@ impl ClientRequest { return Err(InvalidUrl::MissingScheme.into()); } else if let Some(scheme) = uri.scheme() { match scheme.as_str() { - "http" | "ws" | "https" | "wss" => (), + "http" | "ws" | "https" | "wss" => {}, _ => return Err(InvalidUrl::UnknownScheme.into()), } } else { diff --git a/awc/src/response.rs b/awc/src/response.rs index 8364aa556..c9886252e 100644 --- a/awc/src/response.rs +++ b/awc/src/response.rs @@ -234,7 +234,7 @@ pub struct JsonBody { length: Option, err: Option, fut: Option>, - _t: PhantomData, + _phantom: PhantomData, } impl JsonBody @@ -255,7 +255,7 @@ where length: None, fut: None, err: Some(JsonPayloadError::ContentType), - _t: PhantomData, + _phantom: PhantomData, }; } @@ -272,7 +272,7 @@ where length: len, err: None, fut: Some(ReadBody::new(req.take_payload(), 65536)), - _t: PhantomData, + _phantom: PhantomData, } } @@ -370,14 +370,14 @@ mod tests { async fn test_body() { let mut req = TestResponse::with_header(header::CONTENT_LENGTH, "xxxx").finish(); match req.body().await.err().unwrap() { - PayloadError::UnknownLength => (), + PayloadError::UnknownLength => {}, _ => unreachable!("error"), } let mut req = TestResponse::with_header(header::CONTENT_LENGTH, "1000000").finish(); match req.body().await.err().unwrap() { - PayloadError::Overflow => (), + PayloadError::Overflow => {}, _ => unreachable!("error"), } @@ -390,7 +390,7 @@ mod tests { .set_payload(Bytes::from_static(b"11111111111111")) .finish(); match req.body().limit(5).await.err().unwrap() { - PayloadError::Overflow => (), + PayloadError::Overflow => {}, _ => unreachable!("error"), } } diff --git a/awc/src/sender.rs b/awc/src/sender.rs index b5ff61da5..ef65c18dd 100644 --- a/awc/src/sender.rs +++ b/awc/src/sender.rs @@ -86,7 +86,7 @@ impl Future for SendClientRequest { SendClientRequest::Fut(send, delay, response_decompress) => { if delay.is_some() { match Pin::new(delay.as_mut().unwrap()).poll(cx) { - Poll::Pending => (), + Poll::Pending => {}, _ => return Poll::Ready(Err(SendRequestError::Timeout)), } } @@ -127,7 +127,7 @@ impl Future for SendClientRequest { SendClientRequest::Fut(send, delay, _) => { if delay.is_some() { match Pin::new(delay.as_mut().unwrap()).poll(cx) { - Poll::Pending => (), + Poll::Pending => {}, _ => return Poll::Ready(Err(SendRequestError::Timeout)), } } diff --git a/awc/src/ws.rs b/awc/src/ws.rs index dd43d08b3..9065302d9 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -259,7 +259,7 @@ impl WebsocketsRequest { return Err(InvalidUrl::MissingScheme.into()); } else if let Some(scheme) = uri.scheme() { match scheme.as_str() { - "http" | "ws" | "https" | "wss" => (), + "http" | "ws" | "https" | "wss" => {}, _ => return Err(InvalidUrl::UnknownScheme.into()), } } else { diff --git a/awc/tests/test_client.rs b/awc/tests/test_client.rs index 1b7413312..114563b31 100644 --- a/awc/tests/test_client.rs +++ b/awc/tests/test_client.rs @@ -127,7 +127,7 @@ async fn test_timeout() { let request = client.get(srv.url("/")).send(); match request.await { - Err(SendRequestError::Timeout) => (), + Err(SendRequestError::Timeout) => {}, _ => panic!(), } } @@ -149,7 +149,7 @@ async fn test_timeout_override() { .timeout(Duration::from_millis(50)) .send(); match request.await { - Err(SendRequestError::Timeout) => (), + Err(SendRequestError::Timeout) => {}, _ => panic!(), } } diff --git a/src/app.rs b/src/app.rs index d41d692ee..fc336e857 100644 --- a/src/app.rs +++ b/src/app.rs @@ -38,7 +38,7 @@ pub struct App { data_factories: Vec, external: Vec, extensions: Extensions, - _t: PhantomData, + _phantom: PhantomData, } impl App { @@ -55,7 +55,7 @@ impl App { factory_ref: fref, external: Vec::new(), extensions: Extensions::new(), - _t: PhantomData, + _phantom: PhantomData, } } } @@ -381,7 +381,7 @@ where factory_ref: self.factory_ref, external: self.external, extensions: self.extensions, - _t: PhantomData, + _phantom: PhantomData, } } @@ -443,7 +443,7 @@ where factory_ref: self.factory_ref, external: self.external, extensions: self.extensions, - _t: PhantomData, + _phantom: PhantomData, } } } diff --git a/src/app_service.rs b/src/app_service.rs index 2f120cf13..686be6312 100644 --- a/src/app_service.rs +++ b/src/app_service.rs @@ -123,7 +123,7 @@ where ), config, rmap, - _t: PhantomData, + _phantom: PhantomData, } } } @@ -148,7 +148,7 @@ where data: Rc<[Box]>, extensions: Option, - _t: PhantomData, + _phantom: PhantomData, } impl Future for AppInitResult diff --git a/src/handler.rs b/src/handler.rs index 14e8cb40b..30cc59842 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -49,7 +49,7 @@ where R::Output: Responder, { hnd: F, - _t: PhantomData<(T, R)>, + _phantom: PhantomData<(T, R)>, } impl HandlerService @@ -62,7 +62,7 @@ where pub fn new(hnd: F) -> Self { Self { hnd, - _t: PhantomData, + _phantom: PhantomData, } } } @@ -77,7 +77,7 @@ where fn clone(&self) -> Self { Self { hnd: self.hnd.clone(), - _t: PhantomData, + _phantom: PhantomData, } } } diff --git a/src/info.rs b/src/info.rs index 975604041..cefe87eb4 100644 --- a/src/info.rs +++ b/src/info.rs @@ -55,7 +55,7 @@ impl ConnectionInfo { host = Some(val.trim()); } } - _ => (), + _ => {}, } } } diff --git a/src/middleware/compress.rs b/src/middleware/compress.rs index faff5003a..b6ad2c4b5 100644 --- a/src/middleware/compress.rs +++ b/src/middleware/compress.rs @@ -104,7 +104,7 @@ where CompressResponse { encoding, fut: self.service.call(req), - _t: PhantomData, + _phantom: PhantomData, } } } @@ -119,7 +119,7 @@ where #[pin] fut: S::Future, encoding: ContentEncoding, - _t: PhantomData, + _phantom: PhantomData, } impl Future for CompressResponse diff --git a/src/middleware/logger.rs b/src/middleware/logger.rs index 2a543f66f..83ff5b9ec 100644 --- a/src/middleware/logger.rs +++ b/src/middleware/logger.rs @@ -236,7 +236,7 @@ where fut: self.service.call(req), format: None, time: OffsetDateTime::now_utc(), - _t: PhantomData, + _phantom: PhantomData, } } else { let now = OffsetDateTime::now_utc(); @@ -249,7 +249,7 @@ where fut: self.service.call(req), format: Some(format), time: now, - _t: PhantomData, + _phantom: PhantomData, } } } @@ -266,7 +266,7 @@ where fut: S::Future, time: OffsetDateTime, format: Option, - _t: PhantomData, + _phantom: PhantomData, } impl Future for LoggerResponse @@ -522,7 +522,7 @@ impl FormatText { }; *self = FormatText::Str(s.to_string()) } - _ => (), + _ => {}, } } @@ -587,7 +587,7 @@ impl FormatText { *self = s; } - _ => (), + _ => {}, } } } diff --git a/src/responder.rs b/src/responder.rs index d1c22323f..58e33f39d 100644 --- a/src/responder.rs +++ b/src/responder.rs @@ -349,14 +349,14 @@ where pub struct ResponseFuture { #[pin] fut: T, - _t: PhantomData, + _phantom: PhantomData, } impl ResponseFuture { pub fn new(fut: T) -> Self { ResponseFuture { fut, - _t: PhantomData, + _phantom: PhantomData, } } } diff --git a/src/server.rs b/src/server.rs index fc80cbed8..26089ccba 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,6 +1,6 @@ use std::{ any::Any, - fmt, io, + cmp, fmt, io, marker::PhantomData, net, sync::{Arc, Mutex}, @@ -71,7 +71,7 @@ where sockets: Vec, builder: ServerBuilder, on_connect_fn: Option>, - _t: PhantomData<(S, B)>, + _phantom: PhantomData<(S, B)>, } impl HttpServer @@ -100,7 +100,7 @@ where sockets: Vec::new(), builder: ServerBuilder::default(), on_connect_fn: None, - _t: PhantomData, + _phantom: PhantomData, } } @@ -125,7 +125,7 @@ where sockets: self.sockets, builder: self.builder, on_connect_fn: Some(Arc::new(f)), - _t: PhantomData, + _phantom: PhantomData, } } @@ -653,7 +653,7 @@ fn create_tcp_listener( socket.set_reuse_address(true)?; socket.bind(&addr.into())?; // clamp backlog to max u32 that fits in i32 range - let backlog = backlog.min(i32::MAX as u32) as i32; + let backlog = cmp::min(backlog, i32::MAX as u32) as i32; socket.listen(backlog)?; Ok(socket.into_tcp_listener()) } diff --git a/src/types/payload.rs b/src/types/payload.rs index 9228b37aa..1b1c1ad73 100644 --- a/src/types/payload.rs +++ b/src/types/payload.rs @@ -539,7 +539,7 @@ mod tests { .into_parts(); let res = HttpMessageBody::new(&req, &mut pl).await; match res.err().unwrap() { - PayloadError::UnknownLength => (), + PayloadError::UnknownLength => {}, _ => unreachable!("error"), } @@ -548,7 +548,7 @@ mod tests { .into_parts(); let res = HttpMessageBody::new(&req, &mut pl).await; match res.err().unwrap() { - PayloadError::Overflow => (), + PayloadError::Overflow => {}, _ => unreachable!("error"), } @@ -563,7 +563,7 @@ mod tests { .to_http_parts(); let res = HttpMessageBody::new(&req, &mut pl).limit(5).await; match res.err().unwrap() { - PayloadError::Overflow => (), + PayloadError::Overflow => {}, _ => unreachable!("error"), } }