From 351286486c5b88d6fa879ba2d0ccc0335f41dfc1 Mon Sep 17 00:00:00 2001
From: fakeshadow <24548779@qq.com>
Date: Fri, 19 Mar 2021 04:25:35 -0700
Subject: [PATCH] fix clippy warning on nightly (#2088)
* fix clippy warning on nightly
---
actix-files/src/service.rs | 2 +-
actix-http/src/client/connection.rs | 2 +-
actix-http/src/config.rs | 20 +++++---------------
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 +-
tests/test_httpserver.rs | 16 ++++++----------
11 files changed, 30 insertions(+), 52 deletions(-)
diff --git a/actix-files/src/service.rs b/actix-files/src/service.rs
index 14eea6ebc..3214963ed 100644
--- a/actix-files/src/service.rs
+++ b/actix-files/src/service.rs
@@ -1,4 +1,4 @@
-use std::{fmt, io, path::PathBuf, rc::Rc, task::Poll};
+use std::{fmt, io, path::PathBuf, rc::Rc};
use actix_service::Service;
use actix_web::{
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/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,
}
}
diff --git a/tests/test_httpserver.rs b/tests/test_httpserver.rs
index aa2b2ca74..12225b7e5 100644
--- a/tests/test_httpserver.rs
+++ b/tests/test_httpserver.rs
@@ -1,15 +1,11 @@
-use std::sync::mpsc;
-use std::{thread, time::Duration};
-
#[cfg(feature = "openssl")]
extern crate tls_openssl as openssl;
-#[cfg(feature = "rustls")]
-extern crate tls_rustls as rustls;
-#[cfg(feature = "openssl")]
-use openssl::ssl::SslAcceptorBuilder;
-
-use actix_web::{test, web, App, HttpResponse, HttpServer};
+#[cfg(any(unix, feature = "openssl"))]
+use {
+ actix_web::{test, web, App, HttpResponse, HttpServer},
+ std::{sync::mpsc, thread, time::Duration},
+};
#[cfg(unix)]
#[actix_rt::test]
@@ -72,7 +68,7 @@ async fn test_start() {
}
#[cfg(feature = "openssl")]
-fn ssl_acceptor() -> SslAcceptorBuilder {
+fn ssl_acceptor() -> openssl::ssl::SslAcceptorBuilder {
use openssl::{
pkey::PKey,
ssl::{SslAcceptor, SslMethod},