Skip to content

Conversation

@phip1611
Copy link
Member

@phip1611 phip1611 commented Nov 21, 2025

Follow-up of #7483 and currently my last effort regarding clippy lints to improve developer experience and code quality. We now reached a point where the low-hanging fruits are harvested and the world of rabbit-holes begin.

I actively decided against lints missing_const_for_fn, must_use_candidate, and missing_panics_doc. The first two are very invasive with little benefit for CHV. They might make sense in finer-grained scopes (i.e., not treewide). missing_panics_doc is helpful but very invasive and I didn't want to spend the time so far on that. Further, as we are shipping a binary rather than a (Set of) librarie(s), it is okay to not have that.

Explanation for the lints I've selected (IMHO):

  • map_unwrap_or improve code readability
  • redundant_else improves code readability
  • if_not_else reduces cognitive complexity/mental load when reading code
  • needless_pass_by_value uncovers costly clones and makes it easier to reason about ownership of variables

Hints for Reviewers

  • Please review commit-by-commit
  • I don't have a strong opinion on any of these! I'm happy to discuss with you what is best for the proejct

#7489

@phip1611 phip1611 force-pushed the upstream-clippy-tighten-followup branch from e834007 to 0a578c2 Compare November 25, 2025 13:22
Signed-off-by: Philipp Schuster <[email protected]>
On-behalf-of: SAP [email protected]
Signed-off-by: Philipp Schuster <[email protected]>
On-behalf-of: SAP [email protected]
@phip1611 phip1611 force-pushed the upstream-clippy-tighten-followup branch from 0a578c2 to ce3cc6c Compare November 25, 2025 13:31
@phip1611
Copy link
Member Author

phip1611 commented Nov 25, 2025

@rbradford @likebreath I thoroughly went through all the clippy::pedantic lints that we haven't enabled yet, iterated on that PR, and I believe this remaining set represents one of the last reasonably low-hanging opportunities for improvement that make sense to add to CHV. Please also take a look at my statement in the PR description.

@phip1611 phip1611 force-pushed the upstream-clippy-tighten-followup branch 3 times, most recently from f9e6b8f to b749ca9 Compare November 25, 2025 13:46
This removes cognitive load when reading if statements.
All changes were applied by clippy via `--fix`.

Signed-off-by: Philipp Schuster <[email protected]>
On-behalf-of: SAP [email protected]
This helps to uncover expensive and needless clones in the code base.
For example, I prevented extensive clones in the snapshot path where
(nested) BTreeMap's have been cloned over and over again. Further,
the lint helps devs to much better reason about the ownership of
parameters.

All of these changes have been done manually with the necessary
caution. A few structs that are cheap to clone are now `copy` so that
this lint won't trigger for them.

I didn't enable the lint so far as it is a massive rabbit hole and
needs much more fixes. Nevertheless, it is very useful.

Signed-off-by: Philipp Schuster <[email protected]>
On-behalf-of: SAP [email protected]
@phip1611 phip1611 force-pushed the upstream-clippy-tighten-followup branch from b749ca9 to 048cfd2 Compare November 25, 2025 14:04
Copy link
Member

@rbradford rbradford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these changes move the code base to more idiomatic Rust which is probably a good thing! (Even though I often need to double check what these clever functional programming style methods do!.)

@rbradford rbradford added this pull request to the merge queue Nov 25, 2025
Merged via the queue into cloud-hypervisor:main with commit 6a86c15 Nov 25, 2025
45 checks passed
@phip1611 phip1611 deleted the upstream-clippy-tighten-followup branch November 25, 2025 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants