Skip to content
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::match_same_arms #1433

Merged

Conversation

SchahinRohani
Copy link
Contributor

@SchahinRohani SchahinRohani commented Oct 24, 2024

How Has This Been Tested?

bazel test ...

Checklist

  • Updated documentation if needed
  • Tests added/amended
  • bazel test //... passes locally
  • PR is contained in a single commit, using git amend see some docs

This change is Reviewable

Copy link
Member

@aaronmondal aaronmondal left a comment

Choose a reason for hiding this comment

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

Reviewed 10 of 10 files at r1, all commit messages.
Reviewable status: 0 of 1 LGTMs obtained, and all files reviewed, and 8 discussions need to be resolved


nativelink-metric/src/lib.rs line 75 at r1 (raw file):

            2 => MetricKind::String,
            3 => MetricKind::Component,
            4_u64..=u64::MAX => todo!(),

Shouldn't this be MetricKind::Default?


nativelink-metric-collector/src/metrics_visitors.rs line 37 at r1 (raw file):

            MetricKind::Counter => CollectionKind::Counter,
            MetricKind::String => CollectionKind::String,
            MetricKind::Default | MetricKind::Component => todo!(),

Shouldn't this be CollectionKind::String?


nativelink-scheduler/src/store_awaited_action_db.rs line 238 at r1 (raw file):

impl OperationIdToAwaitedAction<'_> {
    fn borrow(&self) -> OperationIdToAwaitedAction<'_> {
        OperationIdToAwaitedAction(Cow::Borrowed(self.0.as_ref()))

Could you elaborate why this is equivalent?


nativelink-util/src/platform_properties.rs line 118 at r1 (raw file):

        match self {
            Self::Exact(value) | Self::Priority(value) | Self::Unknown(value) => {
                Cow::Borrowed(&**value)

Why add the &** here?


nativelink-util/src/retry.rs line 101 at r1 (raw file):

        } else {
            match code {
                // Variants that return `false`

nit: Remove comment


nativelink-util/src/retry.rs line 111 at r1 (raw file):

                | Code::Unauthenticated => false,

                // Variants that return `true`

nit: Remove comment


nativelink-util/src/retry.rs line 121 at r1 (raw file):

                | Code::DataLoss => true,

                // Handle any other variants

nit: Remove comment


nativelink-util/src/retry.rs line 122 at r1 (raw file):

                // Handle any other variants
                _ => todo!(),

Try to avoid todo!() into potentially reachable code. I'd keep this as true.

@SchahinRohani SchahinRohani force-pushed the fix/clippy-match_same_arms branch from 7f08adb to 3227214 Compare October 28, 2024 09:29
Copy link
Contributor Author

@SchahinRohani SchahinRohani left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 LGTMs obtained, and 4 of 10 files reviewed, and pending CI: Bazel Dev / macos-13, Bazel Dev / macos-14, Bazel Dev / ubuntu-24.04, Cargo Dev / macos-13, Cargo Dev / ubuntu-22.04, Coverage, Installation / macos-13, Installation / macos-14, Installation / ubuntu-22.04, Local / ubuntu-22.04, NativeLink.com Cloud / Remote Cache / macos-14, NativeLink.com Cloud / Remote Cache / ubuntu-24.04, Publish image, Publish nativelink-worker-init, Publish nativelink-worker-lre-cc, Remote / large-ubuntu-22.04, asan / ubuntu-22.04, docker-compose-compiles-nativelink (22.04), integration-tests (22.04), macos-13, pre-commit-checks, ubuntu-20.04 / stable, ubuntu-22.04, ubuntu-22.04 / stable, windows-2022 / stable, and 5 discussions need to be resolved


nativelink-metric/src/lib.rs line 75 at r1 (raw file):

Previously, aaronmondal (Aaron Siddhartha Mondal) wrote…

Shouldn't this be MetricKind::Default?

This is the suggestion from the clippy lint. The case for u64::MAX wasn't covered. We should find a way to test all cases properly in future. For now i have set it to MetricKind::Default,


nativelink-metric-collector/src/metrics_visitors.rs line 37 at r1 (raw file):

Previously, aaronmondal (Aaron Siddhartha Mondal) wrote…

Shouldn't this be CollectionKind::String?

Fixed this.


nativelink-scheduler/src/store_awaited_action_db.rs line 238 at r1 (raw file):

Previously, aaronmondal (Aaron Siddhartha Mondal) wrote…

Could you elaborate why this is equivalent?

Sure! In the previous version, the borrow method checks whether self.0 is a Cow::Borrowed or Cow::Owned variant. In both cases, a new OperationIdToAwaitedAction is created with a Cow::Borrowed.

We can simplify this by directly creating the OperationIdToAwaitedAction and passing a reference to it, whether it's borrowed or owned, by using the as_ref function.

The as_ref() method is called on self.0, which always returns a reference to the inner value, regardless of whether self.0 is Borrowed or Owned.


nativelink-util/src/platform_properties.rs line 118 at r1 (raw file):

Previously, aaronmondal (Aaron Siddhartha Mondal) wrote…

Why add the &** here?

Fixed.


nativelink-util/src/retry.rs line 122 at r1 (raw file):

Previously, aaronmondal (Aaron Siddhartha Mondal) wrote…

Try to avoid todo!() into potentially reachable code. I'd keep this as true.

I replaced all cases which return true with a wildcard match which returns true and commented that as a todo.
We probably need to handle all cases so there is no need for a wildcard match in future.

Copy link
Member

@aaronmondal aaronmondal left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 6 of 6 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 1 LGTMs obtained, and all files reviewed

@SchahinRohani SchahinRohani merged commit 51a2fd4 into TraceMachina:main Oct 29, 2024
33 checks passed
@SchahinRohani SchahinRohani deleted the fix/clippy-match_same_arms branch October 29, 2024 08:54
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.

2 participants