Skip to content

Commit 0cb4906

Browse files
authored
Resolve clippy lints (#658)
* Disable type_complexity clippy lint warning: very complex type used. Consider factoring parts into `type` definitions --> examples/websocket/src/ws.rs:28:6 | 28 | ) -> Result< | ______^ 29 | | ( 30 | | Response<Body>, 31 | | impl Future<Output = Result<WebSocketStream<Upgraded>, hyper::Error>>, 32 | | ), 33 | | (), 34 | | > { | |_^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default * Resolve needless_as_bytes clippy lint warning: needless call to `as_bytes` --> gotham/src/test/mod.rs:532:55 | 532 | assert_eq!(content_length, &format!("{}", data.as_bytes().len())); | ^^^^^^^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `data.len()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#needless_as_bytes = note: `#[warn(clippy::needless_as_bytes)]` on by default * Resolve mismatched_lifetime_syntaxes lint warning: eliding a lifetime that's named elsewhere is confusing --> gotham/src/router/tree/mod.rs:59:18 | 57 | &'a self, | -- the lifetime is named here 58 | req_path_segments: &'a [PercentDecoded], | -- the lifetime is named here 59 | ) -> Option<(&Node, SegmentMapping<'a>, usize)> { | ^^^^^ -- the same lifetime is named here | | | the same lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default help: consistently use `'a` | 59 | ) -> Option<(&'a Node, SegmentMapping<'a>, usize)> { | ++ * Resolve io_other_error clippy lint warning: this can be `std::io::Error::other(_)` --> gotham/src/lib.rs:101:9 | 101 | io::Error::new(io::ErrorKind::Other, "unable to resolve listener address") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#io_other_error help: use `std::io::Error::other` | 101 - io::Error::new(io::ErrorKind::Other, "unable to resolve listener address") 101 + io::Error::other("unable to resolve listener address") | warning: this can be `std::io::Error::other(_)` --> gotham/src/handler/assets/mod.rs:267:57 | 267 | HeaderValue::from_str(&val).map_err(|e| io::Error::new(ErrorKind::Other, e))?, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#io_other_error = note: `#[warn(clippy::io_other_error)]` on by default help: use `std::io::Error::other` | 267 - HeaderValue::from_str(&val).map_err(|e| io::Error::new(ErrorKind::Other, e))?, 267 + HeaderValue::from_str(&val).map_err(|e| io::Error::other(e))?, | warning: this can be `std::io::Error::other(_)` --> gotham/src/middleware/session/mod.rs:1003:25 | 1003 | let e = io::Error::new( | _________________________^ 1004 | | io::ErrorKind::Other, 1005 | | format!("backend failed to return session: {:?}", e), 1006 | | ); | |_________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#io_other_error help: use `std::io::Error::other` | 1003 ~ let e = io::Error::other( 1004 ~ format!("backend failed to return session: {:?}", e), | * Resolve extra_unused_lifetimes clippy lint warning: this lifetime isn't used in the function definition --> gotham/src/lib.rs:112:26 | 112 | pub async fn bind_server<'a, NH, F, Wrapped, Wrap>( | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#extra_unused_lifetimes = note: `#[warn(clippy::extra_unused_lifetimes)]` on by default * Resolve empty_line_after_doc_comments clippy lint warning: empty line after doc comment --> gotham/src/router/route/matcher/accept.rs:88:1 | 88 | / /// assert!(matcher.is_match(&state).is_ok()); 89 | | | |_^ ... 100 | pub struct AcceptHeaderRouteMatcher { | ----------------------------------- the comment documents this struct | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#empty_line_after_doc_comments = note: `#[warn(clippy::empty_line_after_doc_comments)]` on by default = help: if the empty line is unintentional, remove it help: if the documentation should include the empty line include it in the comment | 89 | /// | * Disable readonly_write_lock clippy lint warning: this write lock is used only for reading --> gotham/src/test/mod.rs:111:23 | 111 | let runtime = self.runtime.write().unwrap(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using a read lock instead: `self.runtime.read()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#readonly_write_lock = note: `#[warn(clippy::readonly_write_lock)]` on by default * Resolve unnecessary_get_then_check clippy lint warning: unnecessary use of `get(&type_id).is_some()` --> gotham/src/state/mod.rs:221:19 | 221 | self.data.get(&type_id).is_some() | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key(&type_id)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#unnecessary_get_then_check = note: `#[warn(clippy::unnecessary_get_then_check)]` on by default * Resovle needless_maybe_sized clippy lint warning: `?Sized` bound is ignored because of a `Sized` requirement --> gotham/src/router/route/matcher/lookup_table.rs:15:23 | 15 | T: Into<String> + ?Sized, | ^^^^^^ | note: `T` cannot be unsized because of the bound --> gotham/src/router/route/matcher/lookup_table.rs:15:8 | 15 | T: Into<String> + ?Sized, | ^^^^^^^^^^^^ = note: ...because `Into` has the bound `Sized` = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#needless_maybe_sized = note: `#[warn(clippy::needless_maybe_sized)]` on by default help: change the bounds that require `Sized`, or remove the `?Sized` bound | 15 - T: Into<String> + ?Sized, 15 + T: Into<String>, | * Resolve non_canonical_partial_ord_impl clippy lint warning: non-canonical implementation of `partial_cmp` on an `Ord` type --> gotham/src/router/tree/regex.rs:51:1 | 51 | / impl PartialOrd for ConstrainedSegmentRegex { 52 | | fn partial_cmp(&self, other: &ConstrainedSegmentRegex) -> Option<Ordering> { | | ________________________________________________________________________________- 53 | || Some(self.as_str().cmp(other.as_str())) 54 | || } | ||_____- help: change this to: `{ Some(self.cmp(other)) }` 55 | | } | |__^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#non_canonical_partial_ord_impl = note: `#[warn(clippy::non_canonical_partial_ord_impl)]` on by default * Resolve redundant_closure clippy lint warning: redundant closure --> gotham/src/handler/assets/mod.rs:267:53 | 267 | HeaderValue::from_str(&val).map_err(|e| io::Error::other(e))?, | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the associated function itself: `io::Error::other` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#redundant_closure = note: `#[warn(clippy::redundant_closure)]` on by default * Ignore unused fields of ExtractorError warning: field `0` is never read --> gotham/src/extractor/internal.rs:27:26 | 27 | UnexpectedTargetType(&'static str), | -------------------- ^^^^^^^^^^^^ | | | field in this variant | = note: `ExtractorError` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 27 - UnexpectedTargetType(&'static str), 27 + UnexpectedTargetType(()), | warning: field `0` is never read --> gotham/src/extractor/internal.rs:41:25 | 41 | UnexpectedValueType(&'static str), | ------------------- ^^^^^^^^^^^^ | | | field in this variant | = note: `ExtractorError` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 41 - UnexpectedValueType(&'static str), 41 + UnexpectedValueType(()), | warning: field `0` is never read --> gotham/src/extractor/internal.rs:62:31 | 62 | UnexpectedEnumVariantType(&'static str), | ------------------------- ^^^^^^^^^^^^ | | | field in this variant | = note: `ExtractorError` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 62 - UnexpectedEnumVariantType(&'static str), 62 + UnexpectedEnumVariantType(()), | warning: field `0` is never read --> gotham/src/extractor/internal.rs:79:16 | 79 | ParseError(String), | ---------- ^^^^^^ | | | field in this variant | = note: `ExtractorError` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 79 - ParseError(String), 79 + ParseError(()), | warning: field `0` is never read --> gotham/src/extractor/internal.rs:84:12 | 84 | Custom(String), | ------ ^^^^^^ | | | field in this variant | = note: `ExtractorError` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 84 - Custom(String), 84 + Custom(()), | * Resolve legacy_numeric_constants clippy lint warning: usage of a legacy numeric constant --> gotham/src/extractor/internal.rs:769:43 | 769 | assert!((p.f32_val - 1.4).abs() < std::f32::EPSILON); | ^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#legacy_numeric_constants = note: `#[warn(clippy::legacy_numeric_constants)]` on by default help: use the associated constant instead | 769 - assert!((p.f32_val - 1.4).abs() < std::f32::EPSILON); 769 + assert!((p.f32_val - 1.4).abs() < f32::EPSILON); | warning: usage of a legacy numeric constant --> gotham/src/extractor/internal.rs:770:43 | 770 | assert!((p.f64_val - 2.6).abs() < std::f64::EPSILON); | ^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#legacy_numeric_constants help: use the associated constant instead | 770 - assert!((p.f64_val - 2.6).abs() < std::f64::EPSILON); 770 + assert!((p.f64_val - 2.6).abs() < f64::EPSILON); | warning: usage of a legacy numeric constant --> gotham/src/extractor/internal.rs:848:43 | 848 | assert!((p.f32_val - 1.4).abs() < std::f32::EPSILON); | ^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#legacy_numeric_constants help: use the associated constant instead | 848 - assert!((p.f32_val - 1.4).abs() < std::f32::EPSILON); 848 + assert!((p.f32_val - 1.4).abs() < f32::EPSILON); | warning: usage of a legacy numeric constant --> gotham/src/extractor/internal.rs:849:43 | 849 | assert!((p.f64_val - 2.6).abs() < std::f64::EPSILON); | ^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#legacy_numeric_constants help: use the associated constant instead | 849 - assert!((p.f64_val - 2.6).abs() < std::f64::EPSILON); 849 + assert!((p.f64_val - 2.6).abs() < f64::EPSILON); | * Update CI's clippy toolchain from 1.77 to 1.93
1 parent 79cb135 commit 0cb4906

File tree

12 files changed

+27
-26
lines changed

12 files changed

+27
-26
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
- uses: dtolnay/rust-toolchain@master
7878
id: rust-toolchain
7979
with:
80-
toolchain: "1.77"
80+
toolchain: "1.93"
8181
components: clippy
8282

8383
- uses: actions/cache@v4

examples/websocket/src/ws.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::type_complexity)]
2+
13
use base64::prelude::*;
24
use gotham::hyper::header::{
35
HeaderValue, CONNECTION, SEC_WEBSOCKET_ACCEPT, SEC_WEBSOCKET_KEY, UPGRADE,

gotham/src/extractor/internal.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(crate) enum ExtractorError {
2424
/// The `PathExtractor` type is not one which can be deserialized from a
2525
/// `ExtractorDeserializer`. This deserializer requires a structured type (usually a custom
2626
/// struct) which can be deserialized from key / value pairs.
27-
UnexpectedTargetType(&'static str),
27+
UnexpectedTargetType(#[allow(dead_code)] &'static str),
2828

2929
/// An invalid state occurred wherein a "key" (i.e. the name of a route segment) was
3030
/// deserialized as something other than an `identifier`.
@@ -38,7 +38,7 @@ pub(crate) enum ExtractorError {
3838
/// Attempting to deserialize a value into a struct is one example where this error will be
3939
/// triggered, since a list of `0..n` values can't be converted into key/value pairs for
4040
/// mapping into the struct fields.
41-
UnexpectedValueType(&'static str),
41+
UnexpectedValueType(#[allow(dead_code)] &'static str),
4242

4343
/// The enum variant is not able to be deserialized from the value, because the variant is not
4444
/// of the correct type. Only unit variants are supported - that is, enum variants with no data
@@ -59,7 +59,7 @@ pub(crate) enum ExtractorError {
5959
/// #
6060
/// # fn main() {}
6161
/// ```
62-
UnexpectedEnumVariantType(&'static str),
62+
UnexpectedEnumVariantType(#[allow(dead_code)] &'static str),
6363

6464
/// An invalid internal state occurred where a segment mapping had no values. This should never
6565
/// occur because the presence of a key implies the presence of a value.
@@ -76,12 +76,12 @@ pub(crate) enum ExtractorError {
7676
/// An error occurred while parsing a string into a value type for one of the fields. For
7777
/// example, in a route for `/resource/:id`, and with `id: i32` in the `PathExtractor` struct,
7878
/// a request for `/resource/abc` would result in a parse error trying to convert to `i32`.
79-
ParseError(String),
79+
ParseError(#[allow(dead_code)] String),
8080

8181
/// An error occurred, and a `Deserialize` impl provided a custom error message. This is used
8282
/// in the implementation of the `serde::de::Error` trait for external types to provide
8383
/// informative error messages.
84-
Custom(String),
84+
Custom(#[allow(dead_code)] String),
8585
}
8686

8787
impl Display for ExtractorError {
@@ -766,8 +766,8 @@ mod tests {
766766
assert_eq!(p.u16_val, 40511);
767767
assert_eq!(p.u32_val, 4_000_000_000);
768768
assert_eq!(p.u64_val, 9_000_000_000);
769-
assert!((p.f32_val - 1.4).abs() < std::f32::EPSILON);
770-
assert!((p.f64_val - 2.6).abs() < std::f64::EPSILON);
769+
assert!((p.f32_val - 1.4).abs() < f32::EPSILON);
770+
assert!((p.f64_val - 2.6).abs() < f64::EPSILON);
771771
assert_eq!(p.string_val, "this is an owned string");
772772
assert_eq!(p.char_val, 'a');
773773
assert_eq!(p.optional_val, Some("this is optional".to_owned()));
@@ -845,8 +845,8 @@ mod tests {
845845
assert_eq!(p.u16_val, 40511);
846846
assert_eq!(p.u32_val, 4_000_000_000);
847847
assert_eq!(p.u64_val, 9_000_000_000);
848-
assert!((p.f32_val - 1.4).abs() < std::f32::EPSILON);
849-
assert!((p.f64_val - 2.6).abs() < std::f64::EPSILON);
848+
assert!((p.f32_val - 1.4).abs() < f32::EPSILON);
849+
assert!((p.f64_val - 2.6).abs() < f64::EPSILON);
850850
assert_eq!(p.string_val, "this is an owned string");
851851
assert_eq!(p.char_val, 'a');
852852
assert_eq!(p.optional_val, Some("this is optional".to_owned()));

gotham/src/handler/assets/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::state::{FromState, State, StateData};
2626

2727
use std::convert::From;
2828
use std::fs::Metadata;
29-
use std::io::{ErrorKind, SeekFrom};
29+
use std::io::SeekFrom;
3030
use std::iter::FromIterator;
3131
use std::mem::MaybeUninit;
3232
use std::path::{Component, Path, PathBuf};
@@ -264,7 +264,7 @@ fn create_file_response(options: FileOptions, state: State) -> Pin<Box<HandlerFu
264264
);
265265
response = response.status(StatusCode::PARTIAL_CONTENT).header(
266266
CONTENT_RANGE,
267-
HeaderValue::from_str(&val).map_err(|e| io::Error::new(ErrorKind::Other, e))?,
267+
HeaderValue::from_str(&val).map_err(io::Error::other)?,
268268
);
269269
}
270270

gotham/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ async fn tcp_listener<A>(addr: A) -> io::Result<TcpListener>
9797
where
9898
A: ToSocketAddrs + 'static,
9999
{
100-
let addr = addr.to_socket_addrs()?.next().ok_or_else(|| {
101-
io::Error::new(io::ErrorKind::Other, "unable to resolve listener address")
102-
})?;
100+
let addr = addr
101+
.to_socket_addrs()?
102+
.next()
103+
.ok_or_else(|| io::Error::other("unable to resolve listener address"))?;
103104
TcpListener::bind(addr).await
104105
}
105106

@@ -109,7 +110,7 @@ where
109110
/// support. The wrap argument is a function that will receive a tokio-io TcpStream and should wrap
110111
/// the socket as necessary. Errors returned by this function will be ignored and the connection
111112
/// will be dropped if the future returned by the wrapper resolves to an error.
112-
pub async fn bind_server<'a, NH, F, Wrapped, Wrap>(
113+
pub async fn bind_server<NH, F, Wrapped, Wrap>(
113114
listener: TcpListener,
114115
new_handler: NH,
115116
wrap: Wrap,

gotham/src/middleware/session/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,10 +1000,7 @@ where
10001000
e
10011001
);
10021002

1003-
let e = io::Error::new(
1004-
io::ErrorKind::Other,
1005-
format!("backend failed to return session: {:?}", e),
1006-
);
1003+
let e = io::Error::other(format!("backend failed to return session: {:?}", e));
10071004

10081005
future::err((state, e.into()))
10091006
}

gotham/src/router/route/matcher/accept.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl core::str::FromStr for QMime {
8686
/// headers.insert(ACCEPT, "application/json".parse().unwrap());
8787
/// state.put(headers);
8888
/// assert!(matcher.is_match(&state).is_ok());
89-
89+
///
9090
/// // Accept header of `image/*`
9191
/// let mut headers = HeaderMap::new();
9292
/// headers.insert(ACCEPT, "image/*".parse().unwrap());

gotham/src/router/route/matcher/lookup_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(crate) trait LookupTableFromTypes {
1212

1313
fn insert<T>(into: &mut LookupTable, key: T, value: usize)
1414
where
15-
T: Into<String> + ?Sized,
15+
T: Into<String>,
1616
{
1717
into.entry(key.into()).or_default().push(value);
1818
}

gotham/src/router/tree/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Tree {
5656
pub(crate) fn traverse<'a>(
5757
&'a self,
5858
req_path_segments: &'a [PercentDecoded],
59-
) -> Option<(&Node, SegmentMapping<'a>, usize)> {
59+
) -> Option<(&'a Node, SegmentMapping<'a>, usize)> {
6060
trace!(" starting tree traversal");
6161
self.root.match_node(req_path_segments)
6262
}

gotham/src/router/tree/regex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Eq for ConstrainedSegmentRegex {}
5050

5151
impl PartialOrd for ConstrainedSegmentRegex {
5252
fn partial_cmp(&self, other: &ConstrainedSegmentRegex) -> Option<Ordering> {
53-
Some(self.as_str().cmp(other.as_str()))
53+
Some(self.cmp(other))
5454
}
5555
}
5656

0 commit comments

Comments
 (0)