1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-10 17:29:36 +00:00

clippy warnings

This commit is contained in:
Nikolay Kim 2019-07-17 15:08:30 +06:00
parent ef3e1037a8
commit 4092c7f326
26 changed files with 84 additions and 90 deletions

View file

@ -1,3 +1,4 @@
#![allow(clippy::borrow_interior_mutable_const, clippy::type_complexity)]
//! Cross-origin resource sharing (CORS) for Actix applications
//!
//! CORS middleware could be used with application and with resource.
@ -162,6 +163,7 @@ impl<T> AllOrSome<T> {
/// .max_age(3600);
/// # }
/// ```
#[derive(Default)]
pub struct Cors {
cors: Option<Inner>,
methods: bool,

View file

@ -1,3 +1,5 @@
#![allow(clippy::borrow_interior_mutable_const, clippy::type_complexity)]
//! Static files support
use std::cell::RefCell;
use std::fmt::Write;
@ -57,7 +59,7 @@ pub struct ChunkedReadFile {
fn handle_error(err: BlockingError<io::Error>) -> Error {
match err {
BlockingError::Error(err) => err.into(),
BlockingError::Canceled => ErrorInternalServerError("Unexpected error").into(),
BlockingError::Canceled => ErrorInternalServerError("Unexpected error"),
}
}

View file

@ -24,8 +24,8 @@ use crate::ChunkedReadFile;
bitflags! {
pub(crate) struct Flags: u32 {
const ETAG = 0b00000001;
const LAST_MD = 0b00000010;
const ETAG = 0b0000_0001;
const LAST_MD = 0b0000_0010;
}
}
@ -311,8 +311,8 @@ impl Responder for NamedFile {
return Ok(resp.streaming(reader));
}
match req.method() {
&Method::HEAD | &Method::GET => (),
match *req.method() {
Method::HEAD | Method::GET => (),
_ => {
return Ok(HttpResponse::MethodNotAllowed()
.header(header::CONTENT_TYPE, "text/plain")

View file

@ -1,3 +1,9 @@
#![allow(
clippy::type_complexity,
clippy::new_without_default,
dead_code,
deprecated
)]
mod app;
mod helpers;
mod request;

View file

@ -333,8 +333,7 @@ struct CookieIdentityExtention {
impl CookieIdentityInner {
fn new(key: &[u8]) -> CookieIdentityInner {
let key_v2: Vec<u8> =
key.iter().chain([1, 0, 0, 0].iter()).map(|e| *e).collect();
let key_v2: Vec<u8> = key.iter().chain([1, 0, 0, 0].iter()).cloned().collect();
CookieIdentityInner {
key: Key::from_master(key),
key_v2: Key::from_master(&key_v2),
@ -585,13 +584,14 @@ impl IdentityPolicy for CookieIdentityPolicy {
)
} else if self.0.always_update_cookie() && id.is_some() {
let visit_timestamp = SystemTime::now();
let mut login_timestamp = None;
if self.0.requires_oob_data() {
let login_timestamp = if self.0.requires_oob_data() {
let CookieIdentityExtention {
login_timestamp: lt,
} = res.request().extensions_mut().remove().unwrap();
login_timestamp = lt;
}
lt
} else {
None
};
self.0.set_cookie(
res,
Some(CookieValue {

View file

@ -1,3 +1,5 @@
#![allow(clippy::borrow_interior_mutable_const)]
mod error;
mod extractor;
mod server;

View file

@ -418,7 +418,7 @@ impl Stream for Field {
inner.poll(&self.safety)
} else if !self.safety.is_clean() {
return Err(MultipartError::NotConsumed);
Err(MultipartError::NotConsumed)
} else {
Ok(Async::NotReady)
}
@ -533,11 +533,9 @@ impl InnerField {
let b_size = boundary.len() + b_len;
if len < b_size {
return Ok(Async::NotReady);
} else {
if &payload.buf[b_len..b_size] == boundary.as_bytes() {
// found boundary
return Ok(Async::Ready(None));
}
} else if &payload.buf[b_len..b_size] == boundary.as_bytes() {
// found boundary
return Ok(Async::Ready(None));
}
}
}
@ -557,7 +555,7 @@ impl InnerField {
// check boundary
if (&payload.buf[cur..cur + 2] == b"\r\n"
&& &payload.buf[cur + 2..cur + 4] == b"--")
|| (&payload.buf[cur..cur + 1] == b"\r"
|| (&payload.buf[cur..=cur] == b"\r"
&& &payload.buf[cur + 1..cur + 3] == b"--")
{
if cur != 0 {

View file

@ -342,7 +342,7 @@ where
}
}
(SessionStatus::Purged, _) => {
inner.remove_cookie(&mut res);
let _ = inner.remove_cookie(&mut res);
res
}
_ => res,

View file

@ -1,3 +1,4 @@
#![allow(clippy::borrow_interior_mutable_const)]
//! Actix actors integration for Actix web framework
mod context;
pub mod ws;

View file

@ -435,7 +435,7 @@ where
}
}
Frame::Binary(data) => Message::Binary(
data.map(|b| b.freeze()).unwrap_or_else(|| Bytes::new()),
data.map(|b| b.freeze()).unwrap_or_else(Bytes::new),
),
Frame::Ping(s) => Message::Ping(s),
Frame::Pong(s) => Message::Pong(s),

View file

@ -12,9 +12,9 @@ enum ResourceType {
impl fmt::Display for ResourceType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&ResourceType::Async => write!(f, "to_async"),
&ResourceType::Sync => write!(f, "to"),
match *self {
ResourceType::Async => write!(f, "to_async"),
ResourceType::Sync => write!(f, "to"),
}
}
}
@ -34,16 +34,16 @@ pub enum GuardType {
impl fmt::Display for GuardType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&GuardType::Get => write!(f, "Get"),
&GuardType::Post => write!(f, "Post"),
&GuardType::Put => write!(f, "Put"),
&GuardType::Delete => write!(f, "Delete"),
&GuardType::Head => write!(f, "Head"),
&GuardType::Connect => write!(f, "Connect"),
&GuardType::Options => write!(f, "Options"),
&GuardType::Trace => write!(f, "Trace"),
&GuardType::Patch => write!(f, "Patch"),
match *self {
GuardType::Get => write!(f, "Get"),
GuardType::Post => write!(f, "Post"),
GuardType::Put => write!(f, "Put"),
GuardType::Delete => write!(f, "Delete"),
GuardType::Head => write!(f, "Head"),
GuardType::Connect => write!(f, "Connect"),
GuardType::Options => write!(f, "Options"),
GuardType::Trace => write!(f, "Trace"),
GuardType::Patch => write!(f, "Patch"),
}
}
}
@ -92,37 +92,27 @@ impl actix_web::dev::HttpServiceFactory for {name} {{
fn guess_resource_type(typ: &syn::Type) -> ResourceType {
let mut guess = ResourceType::Sync;
match typ {
syn::Type::ImplTrait(typ) => {
for bound in typ.bounds.iter() {
match bound {
syn::TypeParamBound::Trait(bound) => {
for bound in bound.path.segments.iter() {
if bound.ident == "Future" {
guess = ResourceType::Async;
break;
} else if bound.ident == "Responder" {
guess = ResourceType::Sync;
break;
}
}
if let syn::Type::ImplTrait(typ) = typ {
for bound in typ.bounds.iter() {
if let syn::TypeParamBound::Trait(bound) = bound {
for bound in bound.path.segments.iter() {
if bound.ident == "Future" {
guess = ResourceType::Async;
break;
} else if bound.ident == "Responder" {
guess = ResourceType::Sync;
break;
}
_ => (),
}
}
}
_ => (),
}
guess
}
impl Args {
pub fn new(
args: &Vec<syn::NestedMeta>,
input: TokenStream,
guard: GuardType,
) -> Self {
pub fn new(args: &[syn::NestedMeta], input: TokenStream, guard: GuardType) -> Self {
if args.is_empty() {
panic!(
"invalid server definition, expected: #[{}(\"some path\")]",
@ -164,9 +154,10 @@ impl Args {
ResourceType::Async
} else {
match ast.decl.output {
syn::ReturnType::Default => {
panic!("Function {} has no return type. Cannot be used as handler")
}
syn::ReturnType::Default => panic!(
"Function {} has no return type. Cannot be used as handler",
name
),
syn::ReturnType::Type(_, ref typ) => guess_resource_type(typ.as_ref()),
}
};

View file

@ -21,6 +21,12 @@ pub struct ClientBuilder {
max_redirects: usize,
}
impl Default for ClientBuilder {
fn default() -> Self {
Self::new()
}
}
impl ClientBuilder {
pub fn new() -> Self {
ClientBuilder {

View file

@ -1,3 +1,4 @@
#![allow(clippy::borrow_interior_mutable_const)]
//! An HTTP Client
//!
//! ```rust

View file

@ -185,9 +185,7 @@ impl ClientRequest {
{
match HeaderName::try_from(key) {
Ok(key) => match value.try_into() {
Ok(value) => {
let _ = self.head.headers.append(key, value);
}
Ok(value) => self.head.headers.append(key, value),
Err(e) => self.err = Some(e.into()),
},
Err(e) => self.err = Some(e.into()),
@ -203,9 +201,7 @@ impl ClientRequest {
{
match HeaderName::try_from(key) {
Ok(key) => match value.try_into() {
Ok(value) => {
let _ = self.head.headers.insert(key, value);
}
Ok(value) => self.head.headers.insert(key, value),
Err(e) => self.err = Some(e.into()),
},
Err(e) => self.err = Some(e.into()),
@ -223,9 +219,7 @@ impl ClientRequest {
Ok(key) => {
if !self.head.headers.contains_key(&key) {
match value.try_into() {
Ok(value) => {
let _ = self.head.headers.insert(key, value);
}
Ok(value) => self.head.headers.insert(key, value),
Err(e) => self.err = Some(e.into()),
}
}
@ -257,9 +251,7 @@ impl ClientRequest {
HeaderValue: HttpTryFrom<V>,
{
match HeaderValue::try_from(value) {
Ok(value) => {
let _ = self.head.headers.insert(header::CONTENT_TYPE, value);
}
Ok(value) => self.head.headers.insert(header::CONTENT_TYPE, value),
Err(e) => self.err = Some(e.into()),
}
self
@ -321,7 +313,7 @@ impl ClientRequest {
/// }));
/// }
/// ```
pub fn cookie<'c>(mut self, cookie: Cookie<'c>) -> Self {
pub fn cookie(mut self, cookie: Cookie<'_>) -> Self {
if self.cookies.is_none() {
let mut jar = CookieJar::new();
jar.add(cookie.into_owned());
@ -465,7 +457,7 @@ impl ClientRequest {
});
// set request timeout
if let Some(timeout) = slf.timeout.or_else(|| config.timeout.clone()) {
if let Some(timeout) = slf.timeout.or_else(|| config.timeout) {
Either::B(Either::A(Timeout::new(fut, timeout).map_err(|e| {
if let Some(e) = e.into_inner() {
e

View file

@ -68,7 +68,7 @@ impl TestResponse {
}
/// Set cookie for this response
pub fn cookie<'a>(mut self, cookie: Cookie<'a>) -> Self {
pub fn cookie(mut self, cookie: Cookie<'_>) -> Self {
self.cookies.add(cookie.into_owned());
self
}

View file

@ -90,7 +90,7 @@ impl WebsocketsRequest {
}
/// Set a cookie
pub fn cookie<'c>(mut self, cookie: Cookie<'c>) -> Self {
pub fn cookie(mut self, cookie: Cookie<'_>) -> Self {
if self.cookies.is_none() {
let mut jar = CookieJar::new();
jar.add(cookie.into_owned());

View file

@ -25,11 +25,7 @@ impl ConnectionInfo {
Ref::map(req.extensions(), |e| e.get().unwrap())
}
#[allow(
clippy::cyclomatic_complexity,
clippy::cognitive_complexity,
clippy::borrow_interior_mutable_const
)]
#[allow(clippy::cognitive_complexity)]
fn new(req: &RequestHead, cfg: &AppConfig) -> ConnectionInfo {
let mut host = None;
let mut scheme = None;

View file

@ -1,3 +1,4 @@
#![allow(clippy::borrow_interior_mutable_const)]
//! Actix web is a small, pragmatic, and extremely fast web framework
//! for Rust.
//!

View file

@ -107,7 +107,6 @@ where
self.service.poll_ready()
}
#[allow(clippy::borrow_interior_mutable_const)]
fn call(&mut self, req: ServiceRequest) -> Self::Future {
// negotiate content-encoding
let encoding = if let Some(val) = req.headers().get(&ACCEPT_ENCODING) {

View file

@ -125,7 +125,6 @@ where
self.service.poll_ready()
}
#[allow(clippy::borrow_interior_mutable_const)]
fn call(&mut self, req: ServiceRequest) -> Self::Future {
let inner = self.inner.clone();

View file

@ -288,13 +288,13 @@ where
lst,
move || {
let c = cfg.lock();
acceptor.clone().map_err(|e| SslError::Ssl(e)).and_then(
acceptor.clone().map_err(SslError::Ssl).and_then(
HttpService::build()
.keep_alive(c.keep_alive)
.client_timeout(c.client_timeout)
.client_disconnect(c.client_shutdown)
.finish(factory())
.map_err(|e| SslError::Service(e))
.map_err(SslError::Service)
.map_init_err(|_| ()),
)
},
@ -339,13 +339,13 @@ where
lst,
move || {
let c = cfg.lock();
acceptor.clone().map_err(|e| SslError::Ssl(e)).and_then(
acceptor.clone().map_err(SslError::Ssl).and_then(
HttpService::build()
.keep_alive(c.keep_alive)
.client_timeout(c.client_timeout)
.client_disconnect(c.client_shutdown)
.finish(factory())
.map_err(|e| SslError::Service(e))
.map_err(SslError::Service)
.map_init_err(|_| ()),
)
},

View file

@ -79,7 +79,7 @@ where
F: FnOnce() -> R,
R: IntoFuture,
{
RT.with(move |rt| rt.borrow_mut().get_mut().block_on(lazy(|| f())))
RT.with(move |rt| rt.borrow_mut().get_mut().block_on(lazy(f)))
}
#[doc(hidden)]

View file

@ -192,7 +192,6 @@ pub struct UrlEncoded<U> {
impl<U> UrlEncoded<U> {
/// Create a new future to URL encode a request
#[allow(clippy::borrow_interior_mutable_const)]
pub fn new(req: &HttpRequest, payload: &mut Payload) -> UrlEncoded<U> {
// check content type
if req.content_type().to_lowercase() != "application/x-www-form-urlencoded" {

View file

@ -298,7 +298,6 @@ where
U: DeserializeOwned + 'static,
{
/// Create `JsonBody` for request.
#[allow(clippy::borrow_interior_mutable_const)]
pub fn new(
req: &HttpRequest,
payload: &mut Payload,

View file

@ -298,7 +298,6 @@ pub struct HttpMessageBody {
impl HttpMessageBody {
/// Create `MessageBody` for request.
#[allow(clippy::borrow_interior_mutable_const)]
pub fn new(req: &HttpRequest, payload: &mut dev::Payload) -> HttpMessageBody {
let mut len = None;
if let Some(l) = req.headers().get(&header::CONTENT_LENGTH) {

View file

@ -65,7 +65,7 @@ where
F: FnOnce() -> R,
R: IntoFuture,
{
RT.with(move |rt| rt.borrow_mut().get_mut().block_on(lazy(|| f())))
RT.with(move |rt| rt.borrow_mut().get_mut().block_on(lazy(f)))
}
/// The `TestServer` type.
@ -107,6 +107,7 @@ pub struct TestServerRuntime {
}
impl TestServer {
#[allow(clippy::new_ret_no_self)]
/// Start new test server with application factory
pub fn new<F: StreamServiceFactory>(factory: F) -> TestServerRuntime {
let (tx, rx) = mpsc::channel();
@ -191,7 +192,7 @@ impl TestServerRuntime {
F: FnOnce() -> R,
R: Future,
{
self.rt.block_on(lazy(|| f()))
self.rt.block_on(lazy(f))
}
/// Execute function on current core