From 7072cde23c3a3bb51427f088ac075f9c94e79a32 Mon Sep 17 00:00:00 2001
From: fakeshadow <24548779@qq.com>
Date: Fri, 19 Mar 2021 12:00:06 +0800
Subject: [PATCH] fix clippy warning on nightly
---
actix-http/src/client/connection.rs | 2 +-
actix-http/src/config.rs | 20 +++++---------------
actix-http/src/h1/dispatcher.rs | 5 -----
actix-http/src/header/shared/entity.rs | 5 ++---
actix-http/src/header/shared/extended.rs | 2 +-
src/config.rs | 2 +-
src/lib.rs | 12 ++----------
src/middleware/compress.rs | 17 +++++++++--------
src/resource.rs | 2 +-
src/test.rs | 2 +-
10 files changed, 23 insertions(+), 46 deletions(-)
diff --git a/actix-http/src/client/connection.rs b/actix-http/src/client/connection.rs
index 89dfd59de..78101397d 100644
--- a/actix-http/src/client/connection.rs
+++ b/actix-http/src/client/connection.rs
@@ -325,7 +325,7 @@ where
}
}
-const H2_UNREACHABLE_WRITE: &'static str = "H2Connection can not impl AsyncWrite trait";
+const H2_UNREACHABLE_WRITE: &str = "H2Connection can not impl AsyncWrite trait";
impl AsyncWrite for Connection
where
diff --git a/actix-http/src/config.rs b/actix-http/src/config.rs
index 9f84b8694..9a2293e92 100644
--- a/actix-http/src/config.rs
+++ b/actix-http/src/config.rs
@@ -126,9 +126,7 @@ impl ServiceConfig {
pub fn client_timer(&self) -> Option {
let delay_time = self.0.client_timeout;
if delay_time != 0 {
- Some(sleep_until(
- self.0.date_service.now() + Duration::from_millis(delay_time),
- ))
+ Some(sleep_until(self.now() + Duration::from_millis(delay_time)))
} else {
None
}
@@ -138,7 +136,7 @@ impl ServiceConfig {
pub fn client_timer_expire(&self) -> Option {
let delay = self.0.client_timeout;
if delay != 0 {
- Some(self.0.date_service.now() + Duration::from_millis(delay))
+ Some(self.now() + Duration::from_millis(delay))
} else {
None
}
@@ -148,7 +146,7 @@ impl ServiceConfig {
pub fn client_disconnect_timer(&self) -> Option {
let delay = self.0.client_disconnect;
if delay != 0 {
- Some(self.0.date_service.now() + Duration::from_millis(delay))
+ Some(self.now() + Duration::from_millis(delay))
} else {
None
}
@@ -157,20 +155,12 @@ impl ServiceConfig {
#[inline]
/// Return keep-alive timer delay is configured.
pub fn keep_alive_timer(&self) -> Option {
- if let Some(ka) = self.0.keep_alive {
- Some(sleep_until(self.0.date_service.now() + ka))
- } else {
- None
- }
+ self.keep_alive().map(|ka| sleep_until(self.now() + ka))
}
/// Keep-alive expire time
pub fn keep_alive_expire(&self) -> Option {
- if let Some(ka) = self.0.keep_alive {
- Some(self.0.date_service.now() + ka)
- } else {
- None
- }
+ self.keep_alive().map(|ka| self.now() + ka)
}
#[inline]
diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs
index e5989e5ee..c41f9cb22 100644
--- a/actix-http/src/h1/dispatcher.rs
+++ b/actix-http/src/h1/dispatcher.rs
@@ -648,11 +648,6 @@ where
// go into Some> branch
this.ka_timer.set(Some(sleep_until(deadline)));
return self.poll_keepalive(cx);
- } else {
- this.flags.insert(Flags::READ_DISCONNECT);
- if let Some(mut payload) = this.payload.take() {
- payload.set_error(PayloadError::Incomplete(None));
- }
}
}
}
diff --git a/actix-http/src/header/shared/entity.rs b/actix-http/src/header/shared/entity.rs
index eb383cd6f..2505216f2 100644
--- a/actix-http/src/header/shared/entity.rs
+++ b/actix-http/src/header/shared/entity.rs
@@ -127,9 +127,8 @@ impl Display for EntityTag {
impl FromStr for EntityTag {
type Err = crate::error::ParseError;
- fn from_str(s: &str) -> Result {
- let length: usize = s.len();
- let slice = &s[..];
+ fn from_str(slice: &str) -> Result {
+ let length = slice.len();
// Early exits if it doesn't terminate in a DQUOTE.
if !slice.ends_with('"') || slice.len() < 2 {
return Err(crate::error::ParseError::Header);
diff --git a/actix-http/src/header/shared/extended.rs b/actix-http/src/header/shared/extended.rs
index 6bdcb7922..9fd4cdfb0 100644
--- a/actix-http/src/header/shared/extended.rs
+++ b/actix-http/src/header/shared/extended.rs
@@ -88,9 +88,9 @@ pub fn parse_extended_value(
};
Ok(ExtendedValue {
- value,
charset,
language_tag,
+ value,
})
}
diff --git a/src/config.rs b/src/config.rs
index bd9a25c6f..cd14eb4cc 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -113,7 +113,7 @@ pub struct AppConfig {
impl AppConfig {
pub(crate) fn new(secure: bool, addr: SocketAddr, host: String) -> Self {
- AppConfig { secure, addr, host }
+ AppConfig { secure, host, addr }
}
/// Server host name.
diff --git a/src/lib.rs b/src/lib.rs
index 16b2ab186..136c462b8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -173,11 +173,7 @@ pub mod dev {
impl BodyEncoding for ResponseBuilder {
fn get_encoding(&self) -> Option {
- if let Some(ref enc) = self.extensions().get::() {
- Some(enc.0)
- } else {
- None
- }
+ self.extensions().get::().map(|enc| enc.0)
}
fn encoding(&mut self, encoding: ContentEncoding) -> &mut Self {
@@ -188,11 +184,7 @@ pub mod dev {
impl BodyEncoding for Response {
fn get_encoding(&self) -> Option {
- if let Some(ref enc) = self.extensions().get::() {
- Some(enc.0)
- } else {
- None
- }
+ self.extensions().get::().map(|enc| enc.0)
}
fn encoding(&mut self, encoding: ContentEncoding) -> &mut Self {
diff --git a/src/middleware/compress.rs b/src/middleware/compress.rs
index 698ba768e..fc1a85d30 100644
--- a/src/middleware/compress.rs
+++ b/src/middleware/compress.rs
@@ -197,22 +197,23 @@ impl AcceptEncoding {
/// Parse a raw Accept-Encoding header value into an ordered list.
pub fn parse(raw: &str, encoding: ContentEncoding) -> ContentEncoding {
- let mut encodings: Vec<_> = raw
+ let mut encodings = raw
.replace(' ', "")
.split(',')
.map(|l| AcceptEncoding::new(l))
- .collect();
+ .flatten()
+ .collect::>();
+
encodings.sort();
for enc in encodings {
- if let Some(enc) = enc {
- if encoding == ContentEncoding::Auto {
- return enc.encoding;
- } else if encoding == enc.encoding {
- return encoding;
- }
+ if encoding == ContentEncoding::Auto {
+ return enc.encoding;
+ } else if encoding == enc.encoding {
+ return encoding;
}
}
+
ContentEncoding::Identity
}
}
diff --git a/src/resource.rs b/src/resource.rs
index 1a5619de6..d35131cbb 100644
--- a/src/resource.rs
+++ b/src/resource.rs
@@ -449,9 +449,9 @@ impl ServiceFactory for ResourceFactory {
.collect::, _>>()?;
Ok(ResourceService {
+ routes,
app_data,
default,
- routes,
})
})
}
diff --git a/src/test.rs b/src/test.rs
index dd2426fec..2ebd64558 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -774,10 +774,10 @@ where
};
TestServer {
- ssl,
addr,
client,
system,
+ ssl,
server,
}
}