From 92b5bcd13fc8e2014b8a5dfb9c217079c72c0a8f Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 22 Jul 2020 08:28:33 +0900 Subject: [PATCH] Check format and tweak CI config (#1619) --- .github/PULL_REQUEST_TEMPLATE.md | 1 + .github/workflows/bench.yml | 7 +- .github/workflows/clippy-fmt.yml | 32 ++++++++ .github/workflows/linux.yml | 7 +- .github/workflows/macos.yml | 7 +- .github/workflows/windows.yml | 7 +- actix-files/src/lib.rs | 50 +++++------- actix-files/src/named.rs | 7 +- actix-http/src/body.rs | 15 +--- actix-http/src/client/h2proto.rs | 5 +- actix-http/src/client/pool.rs | 5 +- actix-http/src/error.rs | 1 - actix-http/src/extensions.rs | 2 +- actix-http/src/h1/dispatcher.rs | 12 +-- actix-http/src/h2/dispatcher.rs | 80 ++++++++++--------- actix-http/src/header/common/allow.rs | 2 +- actix-http/src/header/common/mod.rs | 17 ++-- actix-http/src/httpmessage.rs | 1 - actix-http/src/ws/mask.rs | 2 +- actix-http/tests/test_openssl.rs | 4 +- actix-http/tests/test_rustls.rs | 4 +- actix-http/tests/test_server.rs | 4 +- actix-multipart/src/server.rs | 8 +- actix-web-actors/tests/test_ws.rs | 6 +- actix-web-codegen/src/route.rs | 9 ++- actix-web-codegen/tests/test_macro.rs | 13 ++- awc/src/response.rs | 9 ++- awc/tests/test_client.rs | 6 +- awc/tests/test_connector.rs | 3 +- awc/tests/test_rustls_client.rs | 5 +- awc/tests/test_ssl_client.rs | 5 +- src/app.rs | 21 +++-- src/app_service.rs | 2 +- src/config.rs | 11 ++- src/data.rs | 17 ++-- src/middleware/logger.rs | 2 +- src/middleware/normalize.rs | 6 +- src/resource.rs | 19 +++-- src/responder.rs | 2 +- src/route.rs | 2 +- src/scope.rs | 109 +++++++++++--------------- src/test.rs | 1 - src/types/form.rs | 12 ++- src/types/json.rs | 6 +- tests/test_server.rs | 2 +- 45 files changed, 276 insertions(+), 272 deletions(-) create mode 100644 .github/workflows/clippy-fmt.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 1c0d467b..b779b33f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -15,6 +15,7 @@ Check your PR fulfills the following: - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] A changelog entry has been made for the appropriate packages. +- [ ] Format code with the latest stable rustfmt ## Overview diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index ce8a7da7..754091dd 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -1,6 +1,11 @@ name: Benchmark (Linux) -on: [push, pull_request] +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: + - master jobs: check_benchmark: diff --git a/.github/workflows/clippy-fmt.yml b/.github/workflows/clippy-fmt.yml new file mode 100644 index 00000000..fb1ed7f3 --- /dev/null +++ b/.github/workflows/clippy-fmt.yml @@ -0,0 +1,32 @@ +on: + pull_request: + types: [opened, synchronize, reopened] + +name: Clippy and rustfmt Check +jobs: + clippy_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt + override: true + - name: Check with rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + components: clippy + override: true + - name: Check with Clippy + uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features --all --tests diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 688db6ce..d49874ce 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -1,6 +1,11 @@ name: CI (Linux) -on: [push, pull_request] +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: + - master jobs: build_and_test: diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 6c360bac..0683fcc8 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -1,6 +1,11 @@ name: CI (macOS) -on: [push, pull_request] +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: + - master jobs: build_and_test: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 5fd785fa..c09c7cea 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,6 +1,11 @@ name: CI (Windows) -on: [push, pull_request] +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: + - master env: VCPKGRS_DYNAMIC: 1 diff --git a/actix-files/src/lib.rs b/actix-files/src/lib.rs index 76c68ce2..ae0204a7 100644 --- a/actix-files/src/lib.rs +++ b/actix-files/src/lib.rs @@ -26,7 +26,6 @@ use actix_web::{web, FromRequest, HttpRequest, HttpResponse}; use bytes::Bytes; use futures_core::Stream; use futures_util::future::{ok, ready, Either, FutureExt, LocalBoxFuture, Ready}; -use mime; use mime_guess::from_ext; use percent_encoding::{utf8_percent_encode, CONTROLS}; use v_htmlescape::escape as escape_html_entity; @@ -250,6 +249,8 @@ pub struct Files { renderer: Rc, mime_override: Option>, file_flags: named::Flags, + // FIXME: Should re-visit later. + #[allow(clippy::redundant_allocation)] guards: Option>>, } @@ -462,6 +463,8 @@ pub struct FilesService { renderer: Rc, mime_override: Option>, file_flags: named::Flags, + // FIXME: Should re-visit later. + #[allow(clippy::redundant_allocation)] guards: Option>>, } @@ -501,11 +504,8 @@ impl Service for FilesService { // execute user defined guards (**guard).check(req.head()) } else { - // default behaviour - match *req.method() { - Method::HEAD | Method::GET => true, - _ => false, - } + // default behavior + matches!(*req.method(), Method::HEAD | Method::GET) }; if !is_method_valid { @@ -952,9 +952,7 @@ mod tests { #[actix_rt::test] async fn test_named_file_content_range_headers() { - let srv = test::start(|| { - App::new().service(Files::new("/", ".")) - }); + let srv = test::start(|| App::new().service(Files::new("/", "."))); // Valid range header let response = srv @@ -979,9 +977,7 @@ mod tests { #[actix_rt::test] async fn test_named_file_content_length_headers() { - let srv = test::start(|| { - App::new().service(Files::new("/", ".")) - }); + let srv = test::start(|| App::new().service(Files::new("/", "."))); // Valid range header let response = srv @@ -1020,15 +1016,9 @@ mod tests { #[actix_rt::test] async fn test_head_content_length_headers() { - let srv = test::start(|| { - App::new().service(Files::new("/", ".")) - }); + let srv = test::start(|| App::new().service(Files::new("/", "."))); - let response = srv - .head("/tests/test.binary") - .send() - .await - .unwrap(); + let response = srv.head("/tests/test.binary").send().await.unwrap(); let content_length = response .headers() @@ -1097,12 +1087,10 @@ mod tests { #[actix_rt::test] async fn test_named_file_content_encoding() { let mut srv = test::init_service(App::new().wrap(Compress::default()).service( - web::resource("/").to(|| { - async { - NamedFile::open("Cargo.toml") - .unwrap() - .set_content_encoding(header::ContentEncoding::Identity) - } + web::resource("/").to(|| async { + NamedFile::open("Cargo.toml") + .unwrap() + .set_content_encoding(header::ContentEncoding::Identity) }), )) .await; @@ -1119,12 +1107,10 @@ mod tests { #[actix_rt::test] async fn test_named_file_content_encoding_gzip() { let mut srv = test::init_service(App::new().wrap(Compress::default()).service( - web::resource("/").to(|| { - async { - NamedFile::open("Cargo.toml") - .unwrap() - .set_content_encoding(header::ContentEncoding::Gzip) - } + web::resource("/").to(|| async { + NamedFile::open("Cargo.toml") + .unwrap() + .set_content_encoding(header::ContentEncoding::Gzip) }), )) .await; diff --git a/actix-files/src/named.rs b/actix-files/src/named.rs index 6ee561a4..12da722d 100644 --- a/actix-files/src/named.rs +++ b/actix-files/src/named.rs @@ -8,7 +8,6 @@ use std::time::{SystemTime, UNIX_EPOCH}; use std::os::unix::fs::MetadataExt; use bitflags::bitflags; -use mime; use mime_guess::from_path; use actix_http::body::SizedStream; @@ -90,7 +89,7 @@ impl NamedFile { }; let ct = from_path(&path).first_or_octet_stream(); - let disposition_type = match ct.type_() { + let disposition = match ct.type_() { mime::IMAGE | mime::TEXT | mime::VIDEO => DispositionType::Inline, _ => DispositionType::Attachment, }; @@ -104,8 +103,8 @@ impl NamedFile { })) } let cd = ContentDisposition { - disposition: disposition_type, - parameters: parameters, + disposition, + parameters, }; (ct, cd) }; diff --git a/actix-http/src/body.rs b/actix-http/src/body.rs index 137f462a..8bea8e6b 100644 --- a/actix-http/src/body.rs +++ b/actix-http/src/body.rs @@ -21,12 +21,7 @@ pub enum BodySize { impl BodySize { pub fn is_eof(&self) -> bool { - match self { - BodySize::None - | BodySize::Empty - | BodySize::Sized(0) => true, - _ => false, - } + matches!(self, BodySize::None | BodySize::Empty | BodySize::Sized(0)) } } @@ -470,9 +465,9 @@ where #[cfg(test)] mod tests { use super::*; - use futures_util::stream; use futures_util::future::poll_fn; use futures_util::pin_mut; + use futures_util::stream; impl Body { pub(crate) fn get_ref(&self) -> &[u8] { @@ -606,10 +601,6 @@ mod tests { #[actix_rt::test] async fn test_body_eq() { - assert!(Body::None == Body::None); - assert!(Body::None != Body::Empty); - assert!(Body::Empty == Body::Empty); - assert!(Body::Empty != Body::None); assert!( Body::Bytes(Bytes::from_static(b"1")) == Body::Bytes(Bytes::from_static(b"1")) @@ -621,7 +612,7 @@ mod tests { async fn test_body_debug() { assert!(format!("{:?}", Body::None).contains("Body::None")); assert!(format!("{:?}", Body::Empty).contains("Body::Empty")); - assert!(format!("{:?}", Body::Bytes(Bytes::from_static(b"1"))).contains("1")); + assert!(format!("{:?}", Body::Bytes(Bytes::from_static(b"1"))).contains('1')); } #[actix_rt::test] diff --git a/actix-http/src/client/h2proto.rs b/actix-http/src/client/h2proto.rs index 7d1d3dc5..3f9a981f 100644 --- a/actix-http/src/client/h2proto.rs +++ b/actix-http/src/client/h2proto.rs @@ -37,7 +37,10 @@ where trace!("Sending client request: {:?} {:?}", head, body.size()); let head_req = head.as_ref().method == Method::HEAD; let length = body.size(); - let eof = matches!(length, BodySize::None | BodySize::Empty | BodySize::Sized(0)); + let eof = matches!( + length, + BodySize::None | BodySize::Empty | BodySize::Sized(0) + ); let mut req = Request::new(()); *req.uri_mut() = head.as_ref().uri.clone(); diff --git a/actix-http/src/client/pool.rs b/actix-http/src/client/pool.rs index 3ce44379..f2c5b041 100644 --- a/actix-http/src/client/pool.rs +++ b/actix-http/src/client/pool.rs @@ -69,10 +69,7 @@ where inner: Rc::downgrade(&inner_rc), }); - ConnectionPool( - connector_rc, - inner_rc, - ) + ConnectionPool(connector_rc, inner_rc) } } diff --git a/actix-http/src/error.rs b/actix-http/src/error.rs index f0a4b70b..d0754ce8 100644 --- a/actix-http/src/error.rs +++ b/actix-http/src/error.rs @@ -964,7 +964,6 @@ impl ResponseError for actix::actors::resolver::ResolverError {} mod tests { use super::*; use http::{Error as HttpError, StatusCode}; - use httparse; use std::io; #[test] diff --git a/actix-http/src/extensions.rs b/actix-http/src/extensions.rs index 4e391853..96e01767 100644 --- a/actix-http/src/extensions.rs +++ b/actix-http/src/extensions.rs @@ -72,7 +72,7 @@ impl fmt::Debug for Extensions { #[cfg(test)] mod tests { use super::*; - + #[test] fn test_remove() { let mut map = Extensions::new(); diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index a9ab2988..00b36562 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -132,19 +132,11 @@ where B: MessageBody, { fn is_empty(&self) -> bool { - if let State::None = self { - true - } else { - false - } + matches!(self, State::None) } fn is_call(&self) -> bool { - if let State::ServiceCall(_) = self { - true - } else { - false - } + matches!(self, State::ServiceCall(_)) } } enum PollResponse { diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index 33fb3a81..534ce928 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -303,55 +303,59 @@ where } } }, - ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => loop { + ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => { 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)); + 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)); - if let Err(e) = stream.send_data(bytes, false) { + if let Err(e) = stream.send_data(bytes, false) { + 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 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) => { - if let Err(e) = stream.send_data(Bytes::new(), true) { - warn!("{:?}", e); + } else { + match body.as_mut().poll_next(cx) { + Poll::Pending => return Poll::Pending, + Poll::Ready(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( + chunk.len(), + CHUNK_SIZE, + )); + *this.buffer = Some(chunk); + } + Poll::Ready(Some(Err(e))) => { + error!("Response payload stream error: {:?}", e); + return Poll::Ready(()); } - return Poll::Ready(()); - } - Poll::Ready(Some(Ok(chunk))) => { - stream.reserve_capacity(std::cmp::min( - chunk.len(), - CHUNK_SIZE, - )); - *this.buffer = Some(chunk); - } - Poll::Ready(Some(Err(e))) => { - error!("Response payload stream error: {:?}", e); - return Poll::Ready(()); } } } } - }, + } } } } diff --git a/actix-http/src/header/common/allow.rs b/actix-http/src/header/common/allow.rs index 432cc00d..88c21763 100644 --- a/actix-http/src/header/common/allow.rs +++ b/actix-http/src/header/common/allow.rs @@ -1,5 +1,5 @@ -use http::Method; use http::header; +use http::Method; header! { /// `Allow` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.1) diff --git a/actix-http/src/header/common/mod.rs b/actix-http/src/header/common/mod.rs index 08950ea8..83489b86 100644 --- a/actix-http/src/header/common/mod.rs +++ b/actix-http/src/header/common/mod.rs @@ -9,11 +9,13 @@ pub use self::accept_charset::AcceptCharset; //pub use self::accept_encoding::AcceptEncoding; -pub use self::accept_language::AcceptLanguage; pub use self::accept::Accept; +pub use self::accept_language::AcceptLanguage; pub use self::allow::Allow; pub use self::cache_control::{CacheControl, CacheDirective}; -pub use self::content_disposition::{ContentDisposition, DispositionType, DispositionParam}; +pub use self::content_disposition::{ + ContentDisposition, DispositionParam, DispositionType, +}; pub use self::content_language::ContentLanguage; pub use self::content_range::{ContentRange, ContentRangeSpec}; pub use self::content_type::ContentType; @@ -47,7 +49,7 @@ macro_rules! __hyper__deref { &mut self.0 } } - } + }; } #[doc(hidden)] @@ -74,8 +76,8 @@ macro_rules! test_header { ($id:ident, $raw:expr) => { #[test] fn $id() { - use $crate::test; use super::*; + use $crate::test; let raw = $raw; let a: Vec> = raw.iter().map(|x| x.to_vec()).collect(); @@ -118,7 +120,7 @@ macro_rules! test_header { // Test formatting if typed.is_some() { let raw = &($raw)[..]; - let mut iter = raw.iter().map(|b|str::from_utf8(&b[..]).unwrap()); + let mut iter = raw.iter().map(|b| str::from_utf8(&b[..]).unwrap()); let mut joined = String::new(); joined.push_str(iter.next().unwrap()); for s in iter { @@ -128,7 +130,7 @@ macro_rules! test_header { assert_eq!(format!("{}", typed.unwrap()), joined); } } - } + }; } #[macro_export] @@ -330,11 +332,10 @@ macro_rules! header { }; } - mod accept_charset; //mod accept_encoding; -mod accept_language; mod accept; +mod accept_language; mod allow; mod cache_control; mod content_disposition; diff --git a/actix-http/src/httpmessage.rs b/actix-http/src/httpmessage.rs index e1c4136b..471fbbcd 100644 --- a/actix-http/src/httpmessage.rs +++ b/actix-http/src/httpmessage.rs @@ -167,7 +167,6 @@ where mod tests { use bytes::Bytes; use encoding_rs::ISO_8859_2; - use mime; use super::*; use crate::test::TestRequest; diff --git a/actix-http/src/ws/mask.rs b/actix-http/src/ws/mask.rs index 7eb5d148..367fb021 100644 --- a/actix-http/src/ws/mask.rs +++ b/actix-http/src/ws/mask.rs @@ -139,7 +139,7 @@ mod tests { let mut masked = unmasked.clone(); apply_mask_fallback(&mut masked[1..], &mask); - let mut masked_fast = unmasked.clone(); + let mut masked_fast = unmasked; apply_mask(&mut masked_fast[1..], mask_u32); assert_eq!(masked, masked_fast); diff --git a/actix-http/tests/test_openssl.rs b/actix-http/tests/test_openssl.rs index 3a7bfa40..795deacd 100644 --- a/actix-http/tests/test_openssl.rs +++ b/actix-http/tests/test_openssl.rs @@ -274,9 +274,7 @@ async fn test_h2_head_empty() { async fn test_h2_head_binary() { let mut srv = test_server(move || { HttpService::build() - .h2(|_| { - ok::<_, ()>(Response::Ok().body(STR)) - }) + .h2(|_| ok::<_, ()>(Response::Ok().body(STR))) .openssl(ssl_acceptor()) .map_err(|_| ()) }) diff --git a/actix-http/tests/test_rustls.rs b/actix-http/tests/test_rustls.rs index 465cba6d..beae359d 100644 --- a/actix-http/tests/test_rustls.rs +++ b/actix-http/tests/test_rustls.rs @@ -280,9 +280,7 @@ async fn test_h2_head_empty() { async fn test_h2_head_binary() { let mut srv = test_server(move || { HttpService::build() - .h2(|_| { - ok::<_, ()>(Response::Ok().body(STR)) - }) + .h2(|_| ok::<_, ()>(Response::Ok().body(STR))) .rustls(ssl_acceptor()) }) .await; diff --git a/actix-http/tests/test_server.rs b/actix-http/tests/test_server.rs index bee5ebef..0375b6f6 100644 --- a/actix-http/tests/test_server.rs +++ b/actix-http/tests/test_server.rs @@ -489,9 +489,7 @@ async fn test_h1_head_empty() { async fn test_h1_head_binary() { let mut srv = test_server(|| { HttpService::build() - .h1(|_| { - ok::<_, ()>(Response::Ok().body(STR)) - }) + .h1(|_| ok::<_, ()>(Response::Ok().body(STR))) .tcp() }) .await; diff --git a/actix-multipart/src/server.rs b/actix-multipart/src/server.rs index f96a7821..449c7da2 100644 --- a/actix-multipart/src/server.rs +++ b/actix-multipart/src/server.rs @@ -9,8 +9,6 @@ use std::{cmp, fmt}; use bytes::{Bytes, BytesMut}; use futures_util::stream::{LocalBoxStream, Stream, StreamExt}; -use httparse; -use mime; use actix_utils::task::LocalWaker; use actix_web::error::{ParseError, PayloadError}; @@ -876,11 +874,11 @@ mod tests { impl SlowStream { fn new(bytes: Bytes) -> SlowStream { - return SlowStream { - bytes: bytes, + SlowStream { + bytes, pos: 0, ready: false, - }; + } } } diff --git a/actix-web-actors/tests/test_ws.rs b/actix-web-actors/tests/test_ws.rs index 25977c2c..dda9f6f0 100644 --- a/actix-web-actors/tests/test_ws.rs +++ b/actix-web-actors/tests/test_ws.rs @@ -30,8 +30,8 @@ impl StreamHandler> for Ws { async fn test_simple() { let mut srv = test::start(|| { App::new().service(web::resource("/").to( - |req: HttpRequest, stream: web::Payload| { - async move { ws::start(Ws, &req, stream) } + |req: HttpRequest, stream: web::Payload| async move { + ws::start(Ws, &req, stream) }, )) }); @@ -51,7 +51,7 @@ async fn test_simple() { .await .unwrap(); let item = framed.next().await.unwrap().unwrap(); - assert_eq!(item, ws::Frame::Binary(Bytes::from_static(b"text").into())); + assert_eq!(item, ws::Frame::Binary(Bytes::from_static(b"text"))); framed.send(ws::Message::Ping("text".into())).await.unwrap(); let item = framed.next().await.unwrap().unwrap(); diff --git a/actix-web-codegen/src/route.rs b/actix-web-codegen/src/route.rs index 7e3d43f1..676e75e0 100644 --- a/actix-web-codegen/src/route.rs +++ b/actix-web-codegen/src/route.rs @@ -3,7 +3,7 @@ extern crate proc_macro; use proc_macro::TokenStream; use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::{format_ident, quote, ToTokens, TokenStreamExt}; -use syn::{AttributeArgs, Ident, NestedMeta, parse_macro_input}; +use syn::{parse_macro_input, AttributeArgs, Ident, NestedMeta}; enum ResourceType { Async, @@ -196,7 +196,12 @@ impl ToTokens for Route { name, guard, ast, - args: Args { path, guards, wrappers }, + args: + Args { + path, + guards, + wrappers, + }, resource_type, } = self; let resource_name = name.to_string(); diff --git a/actix-web-codegen/tests/test_macro.rs b/actix-web-codegen/tests/test_macro.rs index 0ef7e1c7..13e9120f 100644 --- a/actix-web-codegen/tests/test_macro.rs +++ b/actix-web-codegen/tests/test_macro.rs @@ -2,11 +2,11 @@ use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; -use actix_web::{http, test, web::Path, App, HttpResponse, Responder, Error}; -use actix_web::dev::{Service, Transform, ServiceRequest, ServiceResponse}; +use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform}; +use actix_web::http::header::{HeaderName, HeaderValue}; +use actix_web::{http, test, web::Path, App, Error, HttpResponse, Responder}; use actix_web_codegen::{connect, delete, get, head, options, patch, post, put, trace}; use futures_util::future; -use actix_web::http::header::{HeaderName, HeaderValue}; // Make sure that we can name function as 'config' #[get("/config")] @@ -112,6 +112,7 @@ where type Request = ServiceRequest; type Response = ServiceResponse; type Error = Error; + #[allow(clippy::type_complexity)] type Future = Pin>>>; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { @@ -119,7 +120,6 @@ where } fn call(&mut self, req: ServiceRequest) -> Self::Future { - let fut = self.service.call(req); Box::pin(async move { @@ -223,10 +223,7 @@ async fn test_auto_async() { #[actix_rt::test] async fn test_wrap() { - let srv = test::start(|| { - App::new() - .service(get_wrap) - }); + let srv = test::start(|| App::new().service(get_wrap)); let request = srv.request(http::Method::GET, srv.url("/test/wrap")); let response = request.send().await.unwrap(); diff --git a/awc/src/response.rs b/awc/src/response.rs index d1490cb9..8364aa55 100644 --- a/awc/src/response.rs +++ b/awc/src/response.rs @@ -402,9 +402,12 @@ mod tests { fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool { match err { - JsonPayloadError::Payload(PayloadError::Overflow) => - matches!(other, JsonPayloadError::Payload(PayloadError::Overflow)), - JsonPayloadError::ContentType => matches!(other, JsonPayloadError::ContentType), + JsonPayloadError::Payload(PayloadError::Overflow) => { + matches!(other, JsonPayloadError::Payload(PayloadError::Overflow)) + } + JsonPayloadError::ContentType => { + matches!(other, JsonPayloadError::ContentType) + } _ => false, } } diff --git a/awc/tests/test_client.rs b/awc/tests/test_client.rs index cc61f100..21be155e 100644 --- a/awc/tests/test_client.rs +++ b/awc/tests/test_client.rs @@ -167,8 +167,7 @@ async fn test_connection_reuse() { }) .and_then( HttpService::new(map_config( - App::new() - .service(web::resource("/").route(web::to(|| HttpResponse::Ok()))), + App::new().service(web::resource("/").route(web::to(HttpResponse::Ok))), |_| AppConfig::default(), )) .tcp(), @@ -205,8 +204,7 @@ async fn test_connection_force_close() { }) .and_then( HttpService::new(map_config( - App::new() - .service(web::resource("/").route(web::to(|| HttpResponse::Ok()))), + App::new().service(web::resource("/").route(web::to(HttpResponse::Ok))), |_| AppConfig::default(), )) .tcp(), diff --git a/awc/tests/test_connector.rs b/awc/tests/test_connector.rs index b352eaab..633ac2d5 100644 --- a/awc/tests/test_connector.rs +++ b/awc/tests/test_connector.rs @@ -32,8 +32,7 @@ async fn test_connection_window_size() { let srv = test_server(move || { HttpService::build() .h2(map_config( - App::new() - .service(web::resource("/").route(web::to(|| HttpResponse::Ok()))), + App::new().service(web::resource("/").route(web::to(HttpResponse::Ok))), |_| AppConfig::default(), )) .openssl(ssl_acceptor()) diff --git a/awc/tests/test_rustls_client.rs b/awc/tests/test_rustls_client.rs index 0c6be76d..8fb43c43 100644 --- a/awc/tests/test_rustls_client.rs +++ b/awc/tests/test_rustls_client.rs @@ -64,9 +64,8 @@ async fn _test_connection_reuse_h2() { .and_then( HttpService::build() .h2(map_config( - App::new().service( - web::resource("/").route(web::to(|| HttpResponse::Ok())), - ), + App::new() + .service(web::resource("/").route(web::to(HttpResponse::Ok))), |_| AppConfig::default(), )) .openssl(ssl_acceptor()) diff --git a/awc/tests/test_ssl_client.rs b/awc/tests/test_ssl_client.rs index b2a2e178..ca65fb24 100644 --- a/awc/tests/test_ssl_client.rs +++ b/awc/tests/test_ssl_client.rs @@ -45,9 +45,8 @@ async fn test_connection_reuse_h2() { .and_then( HttpService::build() .h2(map_config( - App::new().service( - web::resource("/").route(web::to(|| HttpResponse::Ok())), - ), + App::new() + .service(web::resource("/").route(web::to(HttpResponse::Ok))), |_| AppConfig::default(), )) .openssl(ssl_acceptor()) diff --git a/src/app.rs b/src/app.rs index ae3d9fdf..fdedb0a7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -489,7 +489,7 @@ mod tests { #[actix_rt::test] async fn test_default_resource() { let mut srv = init_service( - App::new().service(web::resource("/test").to(|| HttpResponse::Ok())), + App::new().service(web::resource("/test").to(HttpResponse::Ok)), ) .await; let req = TestRequest::with_uri("/test").to_request(); @@ -502,13 +502,13 @@ mod tests { let mut srv = init_service( App::new() - .service(web::resource("/test").to(|| HttpResponse::Ok())) + .service(web::resource("/test").to(HttpResponse::Ok)) .service( web::resource("/test2") .default_service(|r: ServiceRequest| { ok(r.into_response(HttpResponse::Created())) }) - .route(web::get().to(|| HttpResponse::Ok())), + .route(web::get().to(HttpResponse::Ok)), ) .default_service(|r: ServiceRequest| { ok(r.into_response(HttpResponse::MethodNotAllowed())) @@ -585,7 +585,7 @@ mod tests { DefaultHeaders::new() .header(header::CONTENT_TYPE, HeaderValue::from_static("0001")), ) - .route("/test", web::get().to(|| HttpResponse::Ok())), + .route("/test", web::get().to(HttpResponse::Ok)), ) .await; let req = TestRequest::with_uri("/test").to_request(); @@ -601,7 +601,7 @@ mod tests { async fn test_router_wrap() { let mut srv = init_service( App::new() - .route("/test", web::get().to(|| HttpResponse::Ok())) + .route("/test", web::get().to(HttpResponse::Ok)) .wrap( DefaultHeaders::new() .header(header::CONTENT_TYPE, HeaderValue::from_static("0001")), @@ -632,7 +632,7 @@ mod tests { Ok(res) } }) - .service(web::resource("/test").to(|| HttpResponse::Ok())), + .service(web::resource("/test").to(HttpResponse::Ok)), ) .await; let req = TestRequest::with_uri("/test").to_request(); @@ -648,7 +648,7 @@ mod tests { async fn test_router_wrap_fn() { let mut srv = init_service( App::new() - .route("/test", web::get().to(|| HttpResponse::Ok())) + .route("/test", web::get().to(HttpResponse::Ok)) .wrap_fn(|req, srv| { let fut = srv.call(req); async { @@ -679,10 +679,9 @@ mod tests { .route( "/test", web::get().to(|req: HttpRequest| { - HttpResponse::Ok().body(format!( - "{}", - req.url_for("youtube", &["12345"]).unwrap() - )) + HttpResponse::Ok().body( + req.url_for("youtube", &["12345"]).unwrap().to_string(), + ) }), ), ) diff --git a/src/app_service.rs b/src/app_service.rs index d41cee9f..98d8c8a8 100644 --- a/src/app_service.rs +++ b/src/app_service.rs @@ -475,7 +475,7 @@ mod tests { let mut app = init_service( App::new() .data(DropData(data.clone())) - .service(web::resource("/test").to(|| HttpResponse::Ok())), + .service(web::resource("/test").to(HttpResponse::Ok)), ) .await; let req = TestRequest::with_uri("/test").to_request(); diff --git a/src/config.rs b/src/config.rs index 19a5ccc7..0f49288e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -311,10 +311,9 @@ mod tests { .route( "/test", web::get().to(|req: HttpRequest| { - HttpResponse::Ok().body(format!( - "{}", - req.url_for("youtube", &["12345"]).unwrap() - )) + HttpResponse::Ok().body( + req.url_for("youtube", &["12345"]).unwrap().to_string(), + ) }), ), ) @@ -330,9 +329,9 @@ mod tests { async fn test_service() { let mut srv = init_service(App::new().configure(|cfg| { cfg.service( - web::resource("/test").route(web::get().to(|| HttpResponse::Created())), + web::resource("/test").route(web::get().to(HttpResponse::Created)), ) - .route("/index.html", web::get().to(|| HttpResponse::Ok())); + .route("/index.html", web::get().to(HttpResponse::Ok)); })) .await; diff --git a/src/data.rs b/src/data.rs index 34ada863..c50b3032 100644 --- a/src/data.rs +++ b/src/data.rs @@ -200,14 +200,14 @@ mod tests { #[actix_rt::test] async fn test_route_data_extractor() { - let mut srv = - init_service(App::new().service(web::resource("/").data(10usize).route( - web::get().to(|data: web::Data| { - let _ = data.clone(); - HttpResponse::Ok() - }), - ))) - .await; + let mut srv = init_service( + App::new().service( + web::resource("/") + .data(10usize) + .route(web::get().to(|_data: web::Data| HttpResponse::Ok())), + ), + ) + .await; let req = TestRequest::default().to_request(); let resp = srv.call(req).await.unwrap(); @@ -233,7 +233,6 @@ mod tests { web::resource("/").data(10usize).route(web::get().to( |data: web::Data| { assert_eq!(**data, 10); - let _ = data.clone(); HttpResponse::Ok() }, )), diff --git a/src/middleware/logger.rs b/src/middleware/logger.rs index 57b640bd..dc6468ab 100644 --- a/src/middleware/logger.rs +++ b/src/middleware/logger.rs @@ -626,7 +626,7 @@ mod tests { Ok(()) }; let s = format!("{}", FormatDisplay(&render)); - assert!(s.contains(&format!("{}", now.format("%Y-%m-%dT%H:%M:%S")))); + assert!(s.contains(&now.format("%Y-%m-%dT%H:%M:%S"))); } #[actix_rt::test] diff --git a/src/middleware/normalize.rs b/src/middleware/normalize.rs index 3d5d30c8..a1021ed1 100644 --- a/src/middleware/normalize.rs +++ b/src/middleware/normalize.rs @@ -91,9 +91,9 @@ where // That approach fails when a trailing slash is added, // and a duplicate slash is removed, // since the length of the strings remains the same - // + // // For example, the path "/v1//s" will be normalized to "/v1/s/" - // Both of the paths have the same length, + // Both of the paths have the same length, // so the change can not be deduced from the length comparison if path != original_path { let mut parts = head.uri.clone().into_parts(); @@ -129,7 +129,7 @@ mod tests { let mut app = init_service( App::new() .wrap(NormalizePath::default()) - .service(web::resource("/v1/something/").to(|| HttpResponse::Ok())), + .service(web::resource("/v1/something/").to(HttpResponse::Ok)), ) .await; diff --git a/src/resource.rs b/src/resource.rs index 5da1de62..dd9b2301 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -607,7 +607,7 @@ mod tests { header::CONTENT_TYPE, HeaderValue::from_static("0001"), )) - .route(web::get().to(|| HttpResponse::Ok())), + .route(web::get().to(HttpResponse::Ok)), ), ) .await; @@ -637,7 +637,7 @@ mod tests { }) } }) - .route(web::get().to(|| HttpResponse::Ok())), + .route(web::get().to(HttpResponse::Ok)), ), ) .await; @@ -684,9 +684,7 @@ mod tests { async fn test_default_resource() { let mut srv = init_service( App::new() - .service( - web::resource("/test").route(web::get().to(|| HttpResponse::Ok())), - ) + .service(web::resource("/test").route(web::get().to(HttpResponse::Ok))) .default_service(|r: ServiceRequest| { ok(r.into_response(HttpResponse::BadRequest())) }), @@ -705,7 +703,7 @@ mod tests { let mut srv = init_service( App::new().service( web::resource("/test") - .route(web::get().to(|| HttpResponse::Ok())) + .route(web::get().to(HttpResponse::Ok)) .default_service(|r: ServiceRequest| { ok(r.into_response(HttpResponse::BadRequest())) }), @@ -731,17 +729,17 @@ mod tests { .service( web::resource("/test/{p}") .guard(guard::Get()) - .to(|| HttpResponse::Ok()), + .to(HttpResponse::Ok), ) .service( web::resource("/test/{p}") .guard(guard::Put()) - .to(|| HttpResponse::Created()), + .to(HttpResponse::Created), ) .service( web::resource("/test/{p}") .guard(guard::Delete()) - .to(|| HttpResponse::NoContent()), + .to(HttpResponse::NoContent), ), ) .await; @@ -783,7 +781,8 @@ mod tests { data3: web::Data| { assert_eq!(**data1, 10); assert_eq!(**data2, '*'); - assert_eq!(**data3, 1.0); + let error = std::f64::EPSILON; + assert!((**data3 - 1.0).abs() < error); HttpResponse::Ok() }, ), diff --git a/src/responder.rs b/src/responder.rs index e102d23e..fc80831b 100644 --- a/src/responder.rs +++ b/src/responder.rs @@ -480,7 +480,7 @@ pub(crate) mod tests { assert_eq!(resp.status(), StatusCode::OK); match resp.response().body() { ResponseBody::Body(Body::Bytes(ref b)) => { - let bytes: Bytes = b.clone().into(); + let bytes = b.clone(); assert_eq!(bytes, Bytes::from_static(b"some")); } _ => panic!(), diff --git a/src/route.rs b/src/route.rs index b17fa9b0..3a833bdf 100644 --- a/src/route.rs +++ b/src/route.rs @@ -362,7 +362,7 @@ mod tests { App::new() .service( web::resource("/test") - .route(web::get().to(|| HttpResponse::Ok())) + .route(web::get().to(HttpResponse::Ok)) .route(web::put().to(|| async { Err::(error::ErrorBadRequest("err")) })) diff --git a/src/scope.rs b/src/scope.rs index b9166a4b..c4b01d26 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -678,12 +678,9 @@ mod tests { #[actix_rt::test] async fn test_scope() { - let mut srv = init_service( - App::new().service( - web::scope("/app") - .service(web::resource("/path1").to(|| HttpResponse::Ok())), - ), - ) + let mut srv = init_service(App::new().service( + web::scope("/app").service(web::resource("/path1").to(HttpResponse::Ok)), + )) .await; let req = TestRequest::with_uri("/app/path1").to_request(); @@ -696,8 +693,8 @@ mod tests { let mut srv = init_service( App::new().service( web::scope("/app") - .service(web::resource("").to(|| HttpResponse::Ok())) - .service(web::resource("/").to(|| HttpResponse::Created())), + .service(web::resource("").to(HttpResponse::Ok)) + .service(web::resource("/").to(HttpResponse::Created)), ), ) .await; @@ -714,7 +711,7 @@ mod tests { #[actix_rt::test] async fn test_scope_root2() { let mut srv = init_service(App::new().service( - web::scope("/app/").service(web::resource("").to(|| HttpResponse::Ok())), + web::scope("/app/").service(web::resource("").to(HttpResponse::Ok)), )) .await; @@ -730,7 +727,7 @@ mod tests { #[actix_rt::test] async fn test_scope_root3() { let mut srv = init_service(App::new().service( - web::scope("/app/").service(web::resource("/").to(|| HttpResponse::Ok())), + web::scope("/app/").service(web::resource("/").to(HttpResponse::Ok)), )) .await; @@ -748,8 +745,8 @@ mod tests { let mut srv = init_service( App::new().service( web::scope("app") - .route("/path1", web::get().to(|| HttpResponse::Ok())) - .route("/path1", web::delete().to(|| HttpResponse::Ok())), + .route("/path1", web::get().to(HttpResponse::Ok)) + .route("/path1", web::delete().to(HttpResponse::Ok)), ), ) .await; @@ -777,8 +774,8 @@ mod tests { App::new().service( web::scope("app").service( web::resource("path1") - .route(web::get().to(|| HttpResponse::Ok())) - .route(web::delete().to(|| HttpResponse::Ok())), + .route(web::get().to(HttpResponse::Ok)) + .route(web::delete().to(HttpResponse::Ok)), ), ), ) @@ -807,7 +804,7 @@ mod tests { App::new().service( web::scope("/app") .guard(guard::Get()) - .service(web::resource("/path1").to(|| HttpResponse::Ok())), + .service(web::resource("/path1").to(HttpResponse::Ok)), ), ) .await; @@ -842,7 +839,7 @@ mod tests { match resp.response().body() { ResponseBody::Body(Body::Bytes(ref b)) => { - let bytes: Bytes = b.clone().into(); + let bytes = b.clone(); assert_eq!(bytes, Bytes::from_static(b"project: project1")); } _ => panic!(), @@ -855,14 +852,9 @@ mod tests { #[actix_rt::test] async fn test_nested_scope() { - let mut srv = init_service( - App::new().service( - web::scope("/app") - .service(web::scope("/t1").service( - web::resource("/path1").to(|| HttpResponse::Created()), - )), - ), - ) + let mut srv = init_service(App::new().service(web::scope("/app").service( + web::scope("/t1").service(web::resource("/path1").to(HttpResponse::Created)), + ))) .await; let req = TestRequest::with_uri("/app/t1/path1").to_request(); @@ -872,14 +864,9 @@ mod tests { #[actix_rt::test] async fn test_nested_scope_no_slash() { - let mut srv = init_service( - App::new().service( - web::scope("/app") - .service(web::scope("t1").service( - web::resource("/path1").to(|| HttpResponse::Created()), - )), - ), - ) + let mut srv = init_service(App::new().service(web::scope("/app").service( + web::scope("t1").service(web::resource("/path1").to(HttpResponse::Created)), + ))) .await; let req = TestRequest::with_uri("/app/t1/path1").to_request(); @@ -893,8 +880,8 @@ mod tests { App::new().service( web::scope("/app").service( web::scope("/t1") - .service(web::resource("").to(|| HttpResponse::Ok())) - .service(web::resource("/").to(|| HttpResponse::Created())), + .service(web::resource("").to(HttpResponse::Ok)) + .service(web::resource("/").to(HttpResponse::Created)), ), ), ) @@ -916,7 +903,7 @@ mod tests { web::scope("/app").service( web::scope("/t1") .guard(guard::Get()) - .service(web::resource("/path1").to(|| HttpResponse::Ok())), + .service(web::resource("/path1").to(HttpResponse::Ok)), ), ), ) @@ -953,7 +940,7 @@ mod tests { match resp.response().body() { ResponseBody::Body(Body::Bytes(ref b)) => { - let bytes: Bytes = b.clone().into(); + let bytes = b.clone(); assert_eq!(bytes, Bytes::from_static(b"project: project_1")); } _ => panic!(), @@ -981,7 +968,7 @@ mod tests { match resp.response().body() { ResponseBody::Body(Body::Bytes(ref b)) => { - let bytes: Bytes = b.clone().into(); + let bytes = b.clone(); assert_eq!(bytes, Bytes::from_static(b"project: test - 1")); } _ => panic!(), @@ -997,7 +984,7 @@ mod tests { let mut srv = init_service( App::new().service( web::scope("/app") - .service(web::resource("/path1").to(|| HttpResponse::Ok())) + .service(web::resource("/path1").to(HttpResponse::Ok)) .default_service(|r: ServiceRequest| { ok(r.into_response(HttpResponse::BadRequest())) }), @@ -1018,9 +1005,10 @@ mod tests { async fn test_default_resource_propagation() { let mut srv = init_service( App::new() - .service(web::scope("/app1").default_service( - web::resource("").to(|| HttpResponse::BadRequest()), - )) + .service( + web::scope("/app1") + .default_service(web::resource("").to(HttpResponse::BadRequest)), + ) .service(web::scope("/app2")) .default_service(|r: ServiceRequest| { ok(r.into_response(HttpResponse::MethodNotAllowed())) @@ -1043,21 +1031,21 @@ mod tests { #[actix_rt::test] async fn test_middleware() { - let mut srv = - init_service( - App::new().service( - web::scope("app") - .wrap(DefaultHeaders::new().header( + let mut srv = init_service( + App::new().service( + web::scope("app") + .wrap( + DefaultHeaders::new().header( header::CONTENT_TYPE, HeaderValue::from_static("0001"), - )) - .service( - web::resource("/test") - .route(web::get().to(|| HttpResponse::Ok())), ), - ), - ) - .await; + ) + .service( + web::resource("/test").route(web::get().to(HttpResponse::Ok)), + ), + ), + ) + .await; let req = TestRequest::with_uri("/app/test").to_request(); let resp = call_service(&mut srv, req).await; @@ -1084,7 +1072,7 @@ mod tests { Ok(res) } }) - .route("/test", web::get().to(|| HttpResponse::Ok())), + .route("/test", web::get().to(HttpResponse::Ok)), ), ) .await; @@ -1105,7 +1093,6 @@ mod tests { "/t", web::get().to(|data: web::Data| { assert_eq!(**data, 10); - let _ = data.clone(); HttpResponse::Ok() }), ), @@ -1141,7 +1128,6 @@ mod tests { "/t", web::get().to(|data: web::Data| { assert_eq!(**data, 10); - let _ = data.clone(); HttpResponse::Ok() }), ), @@ -1157,7 +1143,7 @@ mod tests { async fn test_scope_config() { let mut srv = init_service(App::new().service(web::scope("/app").configure(|s| { - s.route("/path1", web::get().to(|| HttpResponse::Ok())); + s.route("/path1", web::get().to(HttpResponse::Ok)); }))) .await; @@ -1171,7 +1157,7 @@ mod tests { let mut srv = init_service(App::new().service(web::scope("/app").configure(|s| { s.service(web::scope("/v1").configure(|s| { - s.route("/", web::get().to(|| HttpResponse::Ok())); + s.route("/", web::get().to(HttpResponse::Ok)); })); }))) .await; @@ -1193,10 +1179,9 @@ mod tests { s.route( "/", web::get().to(|req: HttpRequest| async move { - HttpResponse::Ok().body(format!( - "{}", - req.url_for("youtube", &["xxxxxx"]).unwrap().as_str() - )) + HttpResponse::Ok().body( + req.url_for("youtube", &["xxxxxx"]).unwrap().to_string(), + ) }), ); })); diff --git a/src/test.rs b/src/test.rs index a64ec3a7..49c5cc21 100644 --- a/src/test.rs +++ b/src/test.rs @@ -23,7 +23,6 @@ use futures_util::future::ok; use futures_util::StreamExt; use serde::de::DeserializeOwned; use serde::Serialize; -use serde_json; use socket2::{Domain, Protocol, Socket, Type}; pub use actix_http::test::TestBuffer; diff --git a/src/types/form.rs b/src/types/form.rs index d7db595c..ea061d55 100644 --- a/src/types/form.rs +++ b/src/types/form.rs @@ -407,9 +407,15 @@ mod tests { fn eq(err: UrlencodedError, other: UrlencodedError) -> bool { match err { - UrlencodedError::Overflow { .. } => matches!(other, UrlencodedError::Overflow { .. }), - UrlencodedError::UnknownLength => matches!(other, UrlencodedError::UnknownLength), - UrlencodedError::ContentType => matches!(other, UrlencodedError::ContentType), + UrlencodedError::Overflow { .. } => { + matches!(other, UrlencodedError::Overflow { .. }) + } + UrlencodedError::UnknownLength => { + matches!(other, UrlencodedError::UnknownLength) + } + UrlencodedError::ContentType => { + matches!(other, UrlencodedError::ContentType) + } _ => false, } } diff --git a/src/types/json.rs b/src/types/json.rs index 1665ca95..527b4b61 100644 --- a/src/types/json.rs +++ b/src/types/json.rs @@ -434,7 +434,9 @@ mod tests { fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool { match err { JsonPayloadError::Overflow => matches!(other, JsonPayloadError::Overflow), - JsonPayloadError::ContentType => matches!(other, JsonPayloadError::ContentType), + JsonPayloadError::ContentType => { + matches!(other, JsonPayloadError::ContentType) + } _ => false, } } @@ -480,7 +482,7 @@ mod tests { .to_http_parts(); let s = Json::::from_request(&req, &mut pl).await; - let mut resp = Response::from_error(s.err().unwrap().into()); + let mut resp = Response::from_error(s.err().unwrap()); assert_eq!(resp.status(), StatusCode::BAD_REQUEST); let body = load_stream(resp.take_body()).await.unwrap(); diff --git a/tests/test_server.rs b/tests/test_server.rs index 0ac4b023..fa8a93f0 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -851,7 +851,7 @@ async fn test_slow_request() { use std::net; let srv = test::start_with(test::config().client_timeout(200), || { - App::new().service(web::resource("/").route(web::to(|| HttpResponse::Ok()))) + App::new().service(web::resource("/").route(web::to(HttpResponse::Ok))) }); let mut stream = net::TcpStream::connect(srv.addr()).unwrap();