From cc7145d41dd75beb61ee1882ba677c20d5f1fd76 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 25 Sep 2022 20:54:17 +0100 Subject: [PATCH] rust 1.64 clippy run (#2891) --- actix-files/src/service.rs | 2 +- actix-http/src/body/message_body.rs | 2 +- actix-http/src/body/utils.rs | 2 +- actix-http/src/h1/dispatcher_tests.rs | 4 ++-- actix-http/src/header/map.rs | 2 +- actix-http/src/requests/request.rs | 4 ++-- actix-http/src/responses/response.rs | 4 ++-- actix-http/src/ws/frame.rs | 8 ++++---- actix-http/src/ws/proto.rs | 2 +- actix-http/tests/test_rustls.rs | 2 +- actix-multipart/src/server.rs | 14 ++++++-------- actix-router/src/path.rs | 1 + actix-router/src/resource.rs | 18 +++++++++--------- actix-web/src/app.rs | 2 +- actix-web/src/app_service.rs | 2 +- actix-web/src/config.rs | 2 +- actix-web/src/http/header/cache_control.rs | 2 +- actix-web/src/request.rs | 12 ++++++------ actix-web/src/response/builder.rs | 2 +- actix-web/src/rmap.rs | 12 ++++++------ actix-web/src/scope.rs | 5 ++--- awc/src/client/pool.rs | 2 +- awc/src/ws.rs | 4 ++-- awc/tests/test_client.rs | 15 ++++----------- 24 files changed, 58 insertions(+), 67 deletions(-) diff --git a/actix-files/src/service.rs b/actix-files/src/service.rs index ec09af01c..d94fd5850 100644 --- a/actix-files/src/service.rs +++ b/actix-files/src/service.rs @@ -23,7 +23,7 @@ impl Deref for FilesService { type Target = FilesServiceInner; fn deref(&self) -> &Self::Target { - &*self.0 + &self.0 } } diff --git a/actix-http/src/body/message_body.rs b/actix-http/src/body/message_body.rs index bac2fece1..0cfaa8653 100644 --- a/actix-http/src/body/message_body.rs +++ b/actix-http/src/body/message_body.rs @@ -131,7 +131,7 @@ mod foreign_impls { type Error = B::Error; fn size(&self) -> BodySize { - (&**self).size() + (**self).size() } fn poll_next( diff --git a/actix-http/src/body/utils.rs b/actix-http/src/body/utils.rs index 194af47f8..0a6fb0c15 100644 --- a/actix-http/src/body/utils.rs +++ b/actix-http/src/body/utils.rs @@ -42,7 +42,7 @@ pub async fn to_bytes(body: B) -> Result { let body = body.as_mut(); match ready!(body.poll_next(cx)) { - Some(Ok(bytes)) => buf.extend_from_slice(&*bytes), + Some(Ok(bytes)) => buf.extend_from_slice(&bytes), None => return Poll::Ready(Ok(())), Some(Err(err)) => return Poll::Ready(Err(err)), } diff --git a/actix-http/src/h1/dispatcher_tests.rs b/actix-http/src/h1/dispatcher_tests.rs index b3ee3d2bb..3eea859bf 100644 --- a/actix-http/src/h1/dispatcher_tests.rs +++ b/actix-http/src/h1/dispatcher_tests.rs @@ -637,7 +637,7 @@ async fn expect_handling() { if let DispatcherState::Normal { ref inner } = h1.inner { let io = inner.io.as_ref().unwrap(); - let mut res = (&io.write_buf()[..]).to_owned(); + let mut res = io.write_buf()[..].to_owned(); stabilize_date_header(&mut res); assert_eq!( @@ -699,7 +699,7 @@ async fn expect_eager() { if let DispatcherState::Normal { ref inner } = h1.inner { let io = inner.io.as_ref().unwrap(); - let mut res = (&io.write_buf()[..]).to_owned(); + let mut res = io.write_buf()[..].to_owned(); stabilize_date_header(&mut res); // Despite the content-length header and even though the request payload has not diff --git a/actix-http/src/header/map.rs b/actix-http/src/header/map.rs index 8f6d1cead..28906e835 100644 --- a/actix-http/src/header/map.rs +++ b/actix-http/src/header/map.rs @@ -309,7 +309,7 @@ impl HeaderMap { pub fn get_all(&self, key: impl AsHeaderName) -> std::slice::Iter<'_, HeaderValue> { match self.get_value(key) { Some(value) => value.iter(), - None => (&[]).iter(), + None => [].iter(), } } diff --git a/actix-http/src/requests/request.rs b/actix-http/src/requests/request.rs index 0f8e78d46..ac358e8df 100644 --- a/actix-http/src/requests/request.rs +++ b/actix-http/src/requests/request.rs @@ -113,14 +113,14 @@ impl

Request

{ #[inline] /// Http message part of the request pub fn head(&self) -> &RequestHead { - &*self.head + &self.head } #[inline] #[doc(hidden)] /// Mutable reference to a HTTP message part of the request pub fn head_mut(&mut self) -> &mut RequestHead { - &mut *self.head + &mut self.head } /// Mutable reference to the message's headers. diff --git a/actix-http/src/responses/response.rs b/actix-http/src/responses/response.rs index ceb158f65..03908d9ce 100644 --- a/actix-http/src/responses/response.rs +++ b/actix-http/src/responses/response.rs @@ -83,13 +83,13 @@ impl Response { /// Returns a reference to the head of this response. #[inline] pub fn head(&self) -> &ResponseHead { - &*self.head + &self.head } /// Returns a mutable reference to the head of this response. #[inline] pub fn head_mut(&mut self) -> &mut ResponseHead { - &mut *self.head + &mut self.head } /// Returns the status code of this response. diff --git a/actix-http/src/ws/frame.rs b/actix-http/src/ws/frame.rs index 3659b6c3b..c7e0427ea 100644 --- a/actix-http/src/ws/frame.rs +++ b/actix-http/src/ws/frame.rs @@ -313,7 +313,7 @@ mod tests { #[test] fn test_parse_frame_no_mask() { let mut buf = BytesMut::from(&[0b0000_0001u8, 0b0000_0001u8][..]); - buf.extend(&[1u8]); + buf.extend([1u8]); assert!(Parser::parse(&mut buf, true, 1024).is_err()); @@ -326,7 +326,7 @@ mod tests { #[test] fn test_parse_frame_max_size() { let mut buf = BytesMut::from(&[0b0000_0001u8, 0b0000_0010u8][..]); - buf.extend(&[1u8, 1u8]); + buf.extend([1u8, 1u8]); assert!(Parser::parse(&mut buf, true, 1).is_err()); @@ -340,9 +340,9 @@ mod tests { fn test_parse_frame_max_size_recoverability() { let mut buf = BytesMut::new(); // The first text frame with length == 2, payload doesn't matter. - buf.extend(&[0b0000_0001u8, 0b0000_0010u8, 0b0000_0000u8, 0b0000_0000u8]); + buf.extend([0b0000_0001u8, 0b0000_0010u8, 0b0000_0000u8, 0b0000_0000u8]); // Next binary frame with length == 2 and payload == `[0x1111_1111u8, 0x1111_1111u8]`. - buf.extend(&[0b0000_0010u8, 0b0000_0010u8, 0b1111_1111u8, 0b1111_1111u8]); + buf.extend([0b0000_0010u8, 0b0000_0010u8, 0b1111_1111u8, 0b1111_1111u8]); assert_eq!(buf.len(), 8); assert!(matches!( diff --git a/actix-http/src/ws/proto.rs b/actix-http/src/ws/proto.rs index 01fe9dd3c..7222168b7 100644 --- a/actix-http/src/ws/proto.rs +++ b/actix-http/src/ws/proto.rs @@ -244,7 +244,7 @@ pub fn hash_key(key: &[u8]) -> [u8; 28] { }; let mut hash_b64 = [0; 28]; - let n = base64::encode_config_slice(&hash, base64::STANDARD, &mut hash_b64); + let n = base64::encode_config_slice(hash, base64::STANDARD, &mut hash_b64); assert_eq!(n, 28); hash_b64 diff --git a/actix-http/tests/test_rustls.rs b/actix-http/tests/test_rustls.rs index 2bbf1524b..d9ff42b7d 100644 --- a/actix-http/tests/test_rustls.rs +++ b/actix-http/tests/test_rustls.rs @@ -41,7 +41,7 @@ where let body = stream.as_mut(); match ready!(body.poll_next(cx)) { - Some(Ok(bytes)) => buf.extend_from_slice(&*bytes), + Some(Ok(bytes)) => buf.extend_from_slice(&bytes), None => return Poll::Ready(Ok(())), Some(Err(err)) => return Poll::Ready(Err(err)), } diff --git a/actix-multipart/src/server.rs b/actix-multipart/src/server.rs index 6985cb56d..c3757177f 100644 --- a/actix-multipart/src/server.rs +++ b/actix-multipart/src/server.rs @@ -289,10 +289,8 @@ impl InnerMultipart { match self.state { // read until first boundary InnerState::FirstBoundary => { - match InnerMultipart::skip_until_boundary( - &mut *payload, - &self.boundary, - )? { + match InnerMultipart::skip_until_boundary(&mut payload, &self.boundary)? + { Some(eof) => { if eof { self.state = InnerState::Eof; @@ -306,7 +304,7 @@ impl InnerMultipart { } // read boundary InnerState::Boundary => { - match InnerMultipart::read_boundary(&mut *payload, &self.boundary)? { + match InnerMultipart::read_boundary(&mut payload, &self.boundary)? { None => return Poll::Pending, Some(eof) => { if eof { @@ -323,7 +321,7 @@ impl InnerMultipart { // read field headers for next field if self.state == InnerState::Headers { - if let Some(headers) = InnerMultipart::read_headers(&mut *payload)? { + if let Some(headers) = InnerMultipart::read_headers(&mut payload)? { self.state = InnerState::Boundary; headers } else { @@ -652,9 +650,9 @@ impl InnerField { let result = if let Some(mut payload) = self.payload.as_ref().unwrap().get_mut(s) { if !self.eof { let res = if let Some(ref mut len) = self.length { - InnerField::read_len(&mut *payload, len) + InnerField::read_len(&mut payload, len) } else { - InnerField::read_stream(&mut *payload, &self.boundary) + InnerField::read_stream(&mut payload, &self.boundary) }; match res { diff --git a/actix-router/src/path.rs b/actix-router/src/path.rs index 5eef1c1e7..34dabcfbe 100644 --- a/actix-router/src/path.rs +++ b/actix-router/src/path.rs @@ -242,6 +242,7 @@ mod tests { use super::*; + #[allow(clippy::needless_borrow)] #[test] fn deref_impls() { let mut foo = Path::new("/foo"); diff --git a/actix-router/src/resource.rs b/actix-router/src/resource.rs index 3c6754aeb..f198115ad 100644 --- a/actix-router/src/resource.rs +++ b/actix-router/src/resource.rs @@ -1503,31 +1503,31 @@ mod tests { fn build_path_list() { let mut s = String::new(); let resource = ResourceDef::new("/user/{item1}/test"); - assert!(resource.resource_path_from_iter(&mut s, &mut (&["user1"]).iter())); + assert!(resource.resource_path_from_iter(&mut s, &mut ["user1"].iter())); assert_eq!(s, "/user/user1/test"); let mut s = String::new(); let resource = ResourceDef::new("/user/{item1}/{item2}/test"); - assert!(resource.resource_path_from_iter(&mut s, &mut (&["item", "item2"]).iter())); + assert!(resource.resource_path_from_iter(&mut s, &mut ["item", "item2"].iter())); assert_eq!(s, "/user/item/item2/test"); let mut s = String::new(); let resource = ResourceDef::new("/user/{item1}/{item2}"); - assert!(resource.resource_path_from_iter(&mut s, &mut (&["item", "item2"]).iter())); + assert!(resource.resource_path_from_iter(&mut s, &mut ["item", "item2"].iter())); assert_eq!(s, "/user/item/item2"); let mut s = String::new(); let resource = ResourceDef::new("/user/{item1}/{item2}/"); - assert!(resource.resource_path_from_iter(&mut s, &mut (&["item", "item2"]).iter())); + assert!(resource.resource_path_from_iter(&mut s, &mut ["item", "item2"].iter())); assert_eq!(s, "/user/item/item2/"); let mut s = String::new(); - assert!(!resource.resource_path_from_iter(&mut s, &mut (&["item"]).iter())); + assert!(!resource.resource_path_from_iter(&mut s, &mut ["item"].iter())); let mut s = String::new(); - assert!(resource.resource_path_from_iter(&mut s, &mut (&["item", "item2"]).iter())); + assert!(resource.resource_path_from_iter(&mut s, &mut ["item", "item2"].iter())); assert_eq!(s, "/user/item/item2/"); - assert!(!resource.resource_path_from_iter(&mut s, &mut (&["item"]).iter())); + assert!(!resource.resource_path_from_iter(&mut s, &mut ["item"].iter())); let mut s = String::new(); assert!(resource.resource_path_from_iter(&mut s, &mut vec!["item", "item2"].iter())); @@ -1604,10 +1604,10 @@ mod tests { let resource = ResourceDef::new("/user/{item1}*"); let mut s = String::new(); - assert!(!resource.resource_path_from_iter(&mut s, &mut (&[""; 0]).iter())); + assert!(!resource.resource_path_from_iter(&mut s, &mut [""; 0].iter())); let mut s = String::new(); - assert!(resource.resource_path_from_iter(&mut s, &mut (&["user1"]).iter())); + assert!(resource.resource_path_from_iter(&mut s, &mut ["user1"].iter())); assert_eq!(s, "/user/user1"); let mut s = String::new(); diff --git a/actix-web/src/app.rs b/actix-web/src/app.rs index 213c8beff..ec37ff8a4 100644 --- a/actix-web/src/app.rs +++ b/actix-web/src/app.rs @@ -682,7 +682,7 @@ mod tests { "/test", web::get().to(|req: HttpRequest| { HttpResponse::Ok() - .body(req.url_for("youtube", &["12345"]).unwrap().to_string()) + .body(req.url_for("youtube", ["12345"]).unwrap().to_string()) }), ), ) diff --git a/actix-web/src/app_service.rs b/actix-web/src/app_service.rs index 28ff8c614..0b5ba2ab6 100644 --- a/actix-web/src/app_service.rs +++ b/actix-web/src/app_service.rs @@ -173,7 +173,7 @@ impl AppInitServiceState { #[inline] pub(crate) fn rmap(&self) -> &ResourceMap { - &*self.rmap + &self.rmap } #[inline] diff --git a/actix-web/src/config.rs b/actix-web/src/config.rs index 58a099c75..68bea34ca 100644 --- a/actix-web/src/config.rs +++ b/actix-web/src/config.rs @@ -344,7 +344,7 @@ mod tests { "/test", web::get().to(|req: HttpRequest| { HttpResponse::Ok() - .body(req.url_for("youtube", &["12345"]).unwrap().to_string()) + .body(req.url_for("youtube", ["12345"]).unwrap().to_string()) }), ), ) diff --git a/actix-web/src/http/header/cache_control.rs b/actix-web/src/http/header/cache_control.rs index 490d36558..37629313e 100644 --- a/actix-web/src/http/header/cache_control.rs +++ b/actix-web/src/http/header/cache_control.rs @@ -176,7 +176,7 @@ impl str::FromStr for CacheDirective { _ => match s.find('=') { Some(idx) if idx + 1 < s.len() => { - match (&s[..idx], (&s[idx + 1..]).trim_matches('"')) { + match (&s[..idx], s[idx + 1..].trim_matches('"')) { ("max-age", secs) => secs.parse().map(MaxAge).map_err(Some), ("max-stale", secs) => secs.parse().map(MaxStale).map_err(Some), ("min-fresh", secs) => secs.parse().map(MinFresh).map_err(Some), diff --git a/actix-web/src/request.rs b/actix-web/src/request.rs index e2a9bd4e5..6a32bf838 100644 --- a/actix-web/src/request.rs +++ b/actix-web/src/request.rs @@ -219,7 +219,7 @@ impl HttpRequest { /// for urls that do not contain variable parts. pub fn url_for_static(&self, name: &str) -> Result { const NO_PARAMS: [&str; 0] = []; - self.url_for(name, &NO_PARAMS) + self.url_for(name, NO_PARAMS) } /// Get a reference to a `ResourceMap` of current application. @@ -306,7 +306,7 @@ impl HttpRequest { #[inline] fn app_state(&self) -> &AppInitServiceState { - &*self.inner.app_state + &self.inner.app_state } /// Load request cookies. @@ -583,14 +583,14 @@ mod tests { .to_http_request(); assert_eq!( - req.url_for("unknown", &["test"]), + req.url_for("unknown", ["test"]), Err(UrlGenerationError::ResourceNotFound) ); assert_eq!( - req.url_for("index", &["test"]), + req.url_for("index", ["test"]), Err(UrlGenerationError::NotEnoughElements) ); - let url = req.url_for("index", &["test", "html"]); + let url = req.url_for("index", ["test", "html"]); assert_eq!( url.ok().unwrap().as_str(), "http://www.rust-lang.org/user/test.html" @@ -646,7 +646,7 @@ mod tests { rmap.add(&mut rdef, None); let req = TestRequest::default().rmap(rmap).to_http_request(); - let url = req.url_for("youtube", &["oHg5SJYRHA0"]); + let url = req.url_for("youtube", ["oHg5SJYRHA0"]); assert_eq!( url.ok().unwrap().as_str(), "https://youtube.com/watch/oHg5SJYRHA0" diff --git a/actix-web/src/response/builder.rs b/actix-web/src/response/builder.rs index f50aad9f4..120d4c358 100644 --- a/actix-web/src/response/builder.rs +++ b/actix-web/src/response/builder.rs @@ -457,7 +457,7 @@ mod tests { assert_eq!(ct, HeaderValue::from_static("application/json")); assert_body_eq!(res, br#"["v1","v2","v3"]"#); - let res = HttpResponse::Ok().json(&["v1", "v2", "v3"]); + let res = HttpResponse::Ok().json(["v1", "v2", "v3"]); let ct = res.headers().get(CONTENT_TYPE).unwrap(); assert_eq!(ct, HeaderValue::from_static("application/json")); assert_body_eq!(res, br#"["v1","v2","v3"]"#); diff --git a/actix-web/src/rmap.rs b/actix-web/src/rmap.rs index 6a1a187b2..6e10717c3 100644 --- a/actix-web/src/rmap.rs +++ b/actix-web/src/rmap.rs @@ -449,12 +449,12 @@ mod tests { let req = req.to_http_request(); let url = rmap - .url_for(&req, "post", &["u123", "foobar"]) + .url_for(&req, "post", ["u123", "foobar"]) .unwrap() .to_string(); assert_eq!(url, "http://localhost:8888/user/u123/post/foobar"); - assert!(rmap.url_for(&req, "missing", &["u123"]).is_err()); + assert!(rmap.url_for(&req, "missing", ["u123"]).is_err()); } #[test] @@ -490,7 +490,7 @@ mod tests { assert_eq!(url.path(), OUTPUT); assert!(rmap.url_for(&req, "external.2", INPUT).is_err()); - assert!(rmap.url_for(&req, "external.2", &[""]).is_err()); + assert!(rmap.url_for(&req, "external.2", [""]).is_err()); } #[test] @@ -524,7 +524,7 @@ mod tests { let req = req.to_http_request(); assert_eq!( - rmap.url_for(&req, "duck", &["abcd"]).unwrap().to_string(), + rmap.url_for(&req, "duck", ["abcd"]).unwrap().to_string(), "https://duck.com/abcd" ); } @@ -552,9 +552,9 @@ mod tests { let req = crate::test::TestRequest::default().to_http_request(); - let url = rmap.url_for(&req, "nested", &[""; 0]).unwrap().to_string(); + let url = rmap.url_for(&req, "nested", [""; 0]).unwrap().to_string(); assert_eq!(url, "http://localhost:8080/bar/nested"); - assert!(rmap.url_for(&req, "missing", &["u123"]).is_err()); + assert!(rmap.url_for(&req, "missing", ["u123"]).is_err()); } } diff --git a/actix-web/src/scope.rs b/actix-web/src/scope.rs index 07eb1093a..9af05674b 100644 --- a/actix-web/src/scope.rs +++ b/actix-web/src/scope.rs @@ -1133,7 +1133,7 @@ mod tests { "/", web::get().to(|req: HttpRequest| { HttpResponse::Ok() - .body(req.url_for("youtube", &["xxxxxx"]).unwrap().to_string()) + .body(req.url_for("youtube", ["xxxxxx"]).unwrap().to_string()) }), ); })); @@ -1152,8 +1152,7 @@ mod tests { let srv = init_service(App::new().service(web::scope("/a").service( web::scope("/b").service(web::resource("/c/{stuff}").name("c").route( web::get().to(|req: HttpRequest| { - HttpResponse::Ok() - .body(format!("{}", req.url_for("c", &["12345"]).unwrap())) + HttpResponse::Ok().body(format!("{}", req.url_for("c", ["12345"]).unwrap())) }), )), ))) diff --git a/awc/src/client/pool.rs b/awc/src/client/pool.rs index cc3e4d7c0..5655b5845 100644 --- a/awc/src/client/pool.rs +++ b/awc/src/client/pool.rs @@ -97,7 +97,7 @@ where type Target = ConnectionPoolInnerPriv; fn deref(&self) -> &Self::Target { - &*self.0 + &self.0 } } diff --git a/awc/src/ws.rs b/awc/src/ws.rs index d8ed4c879..b316f68b4 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -321,7 +321,7 @@ impl WebsocketsRequest { // Generate a random key for the `Sec-WebSocket-Key` header which is a base64-encoded // (see RFC 4648 §4) value that, when decoded, is 16 bytes in length (RFC 6455 §1.3). let sec_key: [u8; 16] = rand::random(); - let key = base64::encode(&sec_key); + let key = base64::encode(sec_key); self.head.headers.insert( header::SEC_WEBSOCKET_KEY, @@ -513,7 +513,7 @@ mod tests { .origin("test-origin") .max_frame_size(100) .server_mode() - .protocols(&["v1", "v2"]) + .protocols(["v1", "v2"]) .set_header_if_none(header::CONTENT_TYPE, "json") .set_header_if_none(header::CONTENT_TYPE, "text") .cookie(Cookie::build("cookie1", "value1").finish()); diff --git a/awc/tests/test_client.rs b/awc/tests/test_client.rs index 165d8faf0..c4b468eeb 100644 --- a/awc/tests/test_client.rs +++ b/awc/tests/test_client.rs @@ -707,8 +707,7 @@ async fn client_cookie_handling() { async move { // Check cookies were sent correctly - let res: Result<(), Error> = req - .cookie("cookie1") + req.cookie("cookie1") .ok_or(()) .and_then(|c1| { if c1.value() == "value1" { @@ -725,16 +724,10 @@ async fn client_cookie_handling() { Err(()) } }) - .map_err(|_| Error::from(IoError::from(ErrorKind::NotFound))); + .map_err(|_| Error::from(IoError::from(ErrorKind::NotFound)))?; - if let Err(e) = res { - Err(e) - } else { - // Send some cookies back - Ok::<_, Error>( - HttpResponse::Ok().cookie(cookie1).cookie(cookie2).finish(), - ) - } + // Send some cookies back + Ok::<_, Error>(HttpResponse::Ok().cookie(cookie1).cookie(cookie2).finish()) } }), )