From e8b7532775f82da45bab850b8a257bba06474fac Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Tue, 29 Mar 2022 10:42:47 +0100 Subject: [PATCH 1/4] Fix all failing clippy lints for CI --- src/body.rs | 10 +++++----- src/cache/cache_control/cache_directive.rs | 1 - src/cache/clear_site_data/mod.rs | 4 ++-- src/conditional/if_match.rs | 4 ++-- src/conditional/if_none_match.rs | 4 ++-- src/error.rs | 2 +- src/method.rs | 2 +- src/mime/parse.rs | 4 ++-- src/version.rs | 2 +- 9 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/body.rs b/src/body.rs index 3eefd82f..542733af 100644 --- a/src/body.rs +++ b/src/body.rs @@ -507,7 +507,7 @@ impl AsyncRead for Body { cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { - let mut buf = match self.length { + let buf = match self.length { None => buf, Some(length) if length == self.bytes_read => return Poll::Ready(Ok(0)), Some(length) => { @@ -516,7 +516,7 @@ impl AsyncRead for Body { } }; - let bytes = ready!(Pin::new(&mut self.reader).poll_read(cx, &mut buf))?; + let bytes = ready!(Pin::new(&mut self.reader).poll_read(cx, buf))?; self.bytes_read += bytes; Poll::Ready(Ok(bytes)) } @@ -551,7 +551,7 @@ async fn peek_mime(file: &mut async_std::fs::File) -> io::Result> { /// This is useful for plain-text formats such as HTML and CSS. #[cfg(all(feature = "fs", not(target_os = "unknown")))] fn guess_ext(path: &std::path::Path) -> Option { - let ext = path.extension().map(|p| p.to_str()).flatten(); + let ext = path.extension().and_then(|p| p.to_str()); ext.and_then(Mime::from_extension) } @@ -565,7 +565,7 @@ mod test { async fn json_status() { #[derive(Debug, Deserialize)] struct Foo { - inner: String, + _inner: String, } let body = Body::empty(); let res = body.into_json::().await; @@ -576,7 +576,7 @@ mod test { async fn form_status() { #[derive(Debug, Deserialize)] struct Foo { - inner: String, + _inner: String, } let body = Body::empty(); let res = body.into_form::().await; diff --git a/src/cache/cache_control/cache_directive.rs b/src/cache/cache_control/cache_directive.rs index 7ca8ce9d..e3cdf531 100644 --- a/src/cache/cache_control/cache_directive.rs +++ b/src/cache/cache_control/cache_directive.rs @@ -88,7 +88,6 @@ impl CacheDirective { return Ok(None); } - s.to_lowercase(); let mut parts = s.split('='); let next = parts.next().unwrap(); diff --git a/src/cache/clear_site_data/mod.rs b/src/cache/clear_site_data/mod.rs index 076cd568..4f58247d 100644 --- a/src/cache/clear_site_data/mod.rs +++ b/src/cache/clear_site_data/mod.rs @@ -96,8 +96,8 @@ impl ClearSiteData { let mut output = String::new(); for (n, etag) in self.entries.iter().enumerate() { match n { - 0 => write!(output, "{}", etag.to_string()).unwrap(), - _ => write!(output, ", {}", etag.to_string()).unwrap(), + 0 => write!(output, "{}", etag).unwrap(), + _ => write!(output, ", {}", etag).unwrap(), }; } diff --git a/src/conditional/if_match.rs b/src/conditional/if_match.rs index c1005f6b..ee62a132 100644 --- a/src/conditional/if_match.rs +++ b/src/conditional/if_match.rs @@ -88,8 +88,8 @@ impl IfMatch { let mut output = String::new(); for (n, etag) in self.entries.iter().enumerate() { match n { - 0 => write!(output, "{}", etag.to_string()).unwrap(), - _ => write!(output, ", {}", etag.to_string()).unwrap(), + 0 => write!(output, "{}", etag).unwrap(), + _ => write!(output, ", {}", etag).unwrap(), }; } diff --git a/src/conditional/if_none_match.rs b/src/conditional/if_none_match.rs index dba76720..b38fc43c 100644 --- a/src/conditional/if_none_match.rs +++ b/src/conditional/if_none_match.rs @@ -94,8 +94,8 @@ impl IfNoneMatch { let mut output = String::new(); for (n, etag) in self.entries.iter().enumerate() { match n { - 0 => write!(output, "{}", etag.to_string()).unwrap(), - _ => write!(output, ", {}", etag.to_string()).unwrap(), + 0 => write!(output, "{}", etag).unwrap(), + _ => write!(output, ", {}", etag).unwrap(), }; } diff --git a/src/error.rs b/src/error.rs index e82b8371..04fbcd8d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -159,7 +159,7 @@ impl Error { /// Retrieves a reference to the type name of the error, if available. pub fn type_name(&self) -> Option<&str> { - self.type_name.as_deref() + self.type_name } /// Converts anything which implements `Display` into an `http_types::Error`. diff --git a/src/method.rs b/src/method.rs index 939957bf..4507b97a 100644 --- a/src/method.rs +++ b/src/method.rs @@ -391,7 +391,7 @@ impl Serialize for Method { where S: Serializer, { - serializer.serialize_str(&self.to_string()) + serializer.serialize_str(self.as_ref()) } } diff --git a/src/mime/parse.rs b/src/mime/parse.rs index 4c02ec4a..f2ec5698 100644 --- a/src/mime/parse.rs +++ b/src/mime/parse.rs @@ -153,12 +153,12 @@ fn is_http_whitespace_char(c: char) -> bool { /// [code point sequence collection](https://infra.spec.whatwg.org/#collect-a-sequence-of-code-points) fn collect_code_point_sequence_char(input: &str, delimiter: char) -> (&str, &str) { - input.split_at(input.find(delimiter).unwrap_or_else(|| input.len())) + input.split_at(input.find(delimiter).unwrap_or(input.len())) } /// [code point sequence collection](https://infra.spec.whatwg.org/#collect-a-sequence-of-code-points) fn collect_code_point_sequence_slice<'a>(input: &'a str, delimiter: &[char]) -> (&'a str, &'a str) { - input.split_at(input.find(delimiter).unwrap_or_else(|| input.len())) + input.split_at(input.find(delimiter).unwrap_or(input.len())) } /// [HTTP quoted string collection](https://fetch.spec.whatwg.org/#collect-an-http-quoted-string) diff --git a/src/version.rs b/src/version.rs index d1a1802d..189c31c3 100644 --- a/src/version.rs +++ b/src/version.rs @@ -24,7 +24,7 @@ impl Serialize for Version { where S: Serializer, { - serializer.serialize_str(&self.to_string()) + serializer.serialize_str(self.as_ref()) } } From 5f8040d35a5ab0dea760e566c1d862bde31e62b0 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Tue, 29 Mar 2022 10:47:51 +0100 Subject: [PATCH 2/4] Fix bug where cache directives are not properly made lowercase --- src/cache/cache_control/cache_directive.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cache/cache_control/cache_directive.rs b/src/cache/cache_control/cache_directive.rs index e3cdf531..a78be117 100644 --- a/src/cache/cache_control/cache_directive.rs +++ b/src/cache/cache_control/cache_directive.rs @@ -88,6 +88,7 @@ impl CacheDirective { return Ok(None); } + let s = s.to_lowercase(); let mut parts = s.split('='); let next = parts.next().unwrap(); From 18278ffc2bf120429483e1da3ccb0c8abdff030c Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Tue, 29 Mar 2022 11:02:28 +0100 Subject: [PATCH 3/4] Round to microsecond accuracy rather than divide for second accuracy --- src/trace/server_timing/parse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trace/server_timing/parse.rs b/src/trace/server_timing/parse.rs index b37e81e6..3e959d8a 100644 --- a/src/trace/server_timing/parse.rs +++ b/src/trace/server_timing/parse.rs @@ -65,7 +65,7 @@ fn parse_entry(s: &str) -> crate::Result { let millis: f64 = value.parse().map_err(|_| { format_err!("Server timing duration params must be a valid double-precision floating-point number.") })?; - dur = Some(Duration::from_secs_f64(millis / 1000.0)); + dur = Some(Duration::from_micros((millis * 1000.0).round() as u64)); } "desc" => { // Ensure quotes line up, and strip them from the resulting output From 72f421d3cb9cb26c6e9015b7fe6802cc55b072d2 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 4 Feb 2022 18:20:34 +0100 Subject: [PATCH 4/4] Backport fix from main instead --- src/trace/server_timing/parse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trace/server_timing/parse.rs b/src/trace/server_timing/parse.rs index 3e959d8a..4469336a 100644 --- a/src/trace/server_timing/parse.rs +++ b/src/trace/server_timing/parse.rs @@ -65,7 +65,7 @@ fn parse_entry(s: &str) -> crate::Result { let millis: f64 = value.parse().map_err(|_| { format_err!("Server timing duration params must be a valid double-precision floating-point number.") })?; - dur = Some(Duration::from_micros((millis * 1000.0).round() as u64)); + dur = Some(Duration::from_secs_f64(millis) / 1000); } "desc" => { // Ensure quotes line up, and strip them from the resulting output