Open
Conversation
The `else` block adds unnecessary indentation and verbosity. To avoid this, we can simply move `return None` statement outside the `if` statement. This fixes the `redundant_else` clippy lint.
`if !..else` is a confusing syntax, as it does the inverse of what the rest of the lines says. By reordering the `if` statement we can make the `if` statement more clear. This fixes the `if_not_else` clippy lint.
Calling `.iter()` on items that are already iterable is redundant and makes the code more difficult to read. This commit also makes a couple of other related style changes to make the code easier to read. For example, removing the `iter` call on `self.routes` helped clippy find a violation of `for_kv_map`, which I also fixed. Clippy also recommended changing `["one", "two", "three", "four"].iter()` to `&["one", "two", "three", "four"]`, which does indeed match the previous behaviour. However, we can make the code easier to read by removing the unnecessary dereference of `*n` in the last `assert_eq` call by turning the slice into an array (`["one", "two", "three", "four"]`). This makes the code more readable, for free! This fixes the `explicit_iter_loop` clippy lint.
This is likely a leftover from a refactor. This fixes the `unused_peekable` clippy lint.
Remove unnecessary semicolons at the end of control flow statements (`if` and `match`). These are not needed, and can safely be removed to avoid confusion, visual clutter, and improve readability of the code. This fixes the `unnecessary_semicolon` clippy lint.
`assert!` is much more concise and readable than manually triggering a panic via an `if` statement. Once I did this, clippy also found a couple of conditions that could be simplified. I applied those simplifications. This fixes the `manual_assert` clippy lint.
jplatte
reviewed
Jul 11, 2025
Member
jplatte
left a comment
There was a problem hiding this comment.
I'm not sure about the first commit, doesn't seem like a improvement to me. Actually instead of if ... { return Some(_); } else { return None; } we could do return (...).then(|| _);.
| !path.is_empty(), | ||
| "Paths must start with a `/`. Use \"/\" for root routes" | ||
| ); | ||
| // `assert_eq!` is not allowed in constant functions so we have to do it manually. |
Member
There was a problem hiding this comment.
I think I commented on this before, but I wouldn't want assert_eq here even if it was possible, since it adds a LHS-RHS comparison to the output, which would not be helpful here.
| panic!( | ||
| "Overlapping method route. Cannot add two method routes that both handle \ | ||
| assert!( | ||
| !out.is_some(), |
Comment on lines
+840
to
841
| "Overlapping method route. Cannot add two method routes that both handle \ | ||
| `{method_name}`", |
Member
There was a problem hiding this comment.
Does this fit the line as a single line string literal now? If no, please reduce indentation on the second line by 4 spaces.
mladedav
reviewed
Jul 12, 2025
| panic!("Nesting at the root is no longer supported. Use merge instead."); | ||
| } | ||
| assert!( | ||
| !(path.is_empty() || path == "/"), |
Collaborator
There was a problem hiding this comment.
Suggested change
| !(path.is_empty() || path == "/"), | |
| !path.is_empty() && path != "/"), |
| panic!("Nesting at the root is no longer supported. Use fallback_service instead."); | ||
| } | ||
| assert!( | ||
| !(path.is_empty() || path == "/"), |
Collaborator
There was a problem hiding this comment.
Suggested change
| !(path.is_empty() || path == "/"), | |
| !path.is_empty() && path != "/"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
This PR is part of the broader PR #3394 (Activate more lints)
This is an extension to the PR #3399 (Simplify
ifstatements)This PR adds additionally stylistic Clippy lints to improve readability and cleans up redundant, old, leftover code in order to improve maintainability.
Solution
This PR adds 6 new lints to
Cargo.tomland also fixes them in the code:redundant_elseif_not_elseexplicit_iter_loopunused_peekableunnecessary_semicolonmanual_assertSee each individual commit's message for more information.