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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix clippy lints and run clippy in CI #29
Fix clippy lints and run clippy in CI #29
Changes from 1 commit
d23492c
03b905b
e3640c3
d16e9f2
f2e6269
87c3617
3de03b5
ee40f54
2f562f2
08679d0
a32caee
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this change. Is clippy saying that this thing only ever returns success, so we should drop the Result from the type? That's true, but the caller always wraps the return value in a Result, so it makes sense to me to just do that here, in one place.
If I'm understanding right, I think this is one of those examples of clippy's advice being pretty subjective, which is why we don't run it automatically all the time. I don't really mind this change if there's value in being clippy-clean, but my past experience has been that it's not really worth it (see oxidecomputer/dropshot#4). What about you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for the context with that link.
Clippy itself is pretty configurable - it has different "lint levels" (allow / warn / deny) and "lint groups" (correctness, style, pedantic, complexity, perf, etc) that can be turned on or off depending on invocation.
The default is:
But this can be (and probably should be, depending on a project's requirements) adjusted, at a broad category but also a per-lint basis.
As an example, take a look at the "deny" lint level on https://rust-lang.github.io/rust-clippy/master/index.html - a lot of these things are in the bucket of "technically not a compiler error, but are almost always inadvisable".
Even if there is opposition to some of the on-the-fence lints, I'd still advocate for some threshold of analysis here - the cost is pretty low.
That being said, if there's a preference for (as @ahl suggested) "run[ning] clippy periodically", that seems fine too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With regards to this specific lint, yeah, clippy is identifying that the function type signature is misleading.
For what it's worth, I do not think this lint would be raised on a public function (where API stability matters), but in the context of a private function, my gut instinct agrees with the lint: the prototype is imprecise regarding the behavior of the code - the use of the function implies that an error could be returned, and should be handled, but this is never the case. All the current uses propagate the Result directly, but a future invocation might have more complexity, and error-handling around this function would become impossible-to-reach code.
(I also totally admit, this is a weakly-held opinion, if you feel strongly, I'd be fine reverting the suggestions based on this lint)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a good rule of thumb and it's useful that clippy can identify that. Here's another one: if you have a private function, and it has N callers, and all N callers apply the same transformation to the returned value, then the function ought to apply that transformation instead for the usual DRY reasons. I could imagine a clippy lint for this, too. 🤷
How about this: if you think it's worthwhile for us to pick a set of lints and stay clippy-clean, want to update this PR to do that as part of CI and document it in the README? It's up to you if you think this is worth it. I haven't run it on this code base in months, and I'm mostly indifferent to what it found here (though
matches!
one is a nice readability improvement!).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmkay - I added clippy to the readme, and have the invocation within
.github/workflows/rust.yml
, so it'll run on new PRs too.Disabling a lint is really easy, just add a
-D clippy::lint_name
, and it'll be ignored. I think it's super super reasonable to look at a lint, decide it's irritating, and throw it in that bucket - like your stance onunnecessary_wraps
(which I think is reasonable - removed those changes).For now the linter is catching defaults + filtering out some undesired lints - WDYT? I'm flexible here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the historical record, this specific lint came up again under #38. (It was also pedantic in the latest version of clippy.)