Skip to content

Commit

Permalink
Fix clippy::match_same_arms (TraceMachina#1433)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchahinRohani authored Oct 29, 2024
1 parent d0eb00c commit 51a2fd4
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect

# TODO(aaronmondal): Extend these flags until we can run with clippy::pedantic.
build --@rules_rust//:clippy_flags=-Dwarnings,-Dclippy::uninlined_format_args,-Dclippy::manual_string_new,-Dclippy::manual_let_else,-Dclippy::single_match_else,-Dclippy::redundant_closure_for_method_calls,-Dclippy::semicolon_if_nothing_returned,-Dclippy::unreadable_literal,-Dclippy::range_plus_one,-Dclippy::inconsistent_struct_constructor,-Dclippy::match_wildcard_for_single_variants,-Dclippy::implicit_clone,-Dclippy::needless_pass_by_value,-Dclippy::explicit_deref_methods,-Dclippy::trivially_copy_pass_by_ref,-Dclippy::unnecessary_wraps,-Dclippy::cast_lossless,-Dclippy::map_unwrap_or,-Dclippy::ref_as_ptr,-Dclippy::inline_always,-Dclippy::redundant_else,-Dclippy::return_self_not_must_use
build --@rules_rust//:clippy_flags=-Dwarnings,-Dclippy::uninlined_format_args,-Dclippy::manual_string_new,-Dclippy::manual_let_else,-Dclippy::single_match_else,-Dclippy::redundant_closure_for_method_calls,-Dclippy::semicolon_if_nothing_returned,-Dclippy::unreadable_literal,-Dclippy::range_plus_one,-Dclippy::inconsistent_struct_constructor,-Dclippy::match_wildcard_for_single_variants,-Dclippy::implicit_clone,-Dclippy::needless_pass_by_value,-Dclippy::explicit_deref_methods,-Dclippy::trivially_copy_pass_by_ref,-Dclippy::unnecessary_wraps,-Dclippy::cast_lossless,-Dclippy::map_unwrap_or,-Dclippy::ref_as_ptr,-Dclippy::inline_always,-Dclippy::redundant_else,-Dclippy::return_self_not_must_use,-Dclippy::match_same_arms
build --@rules_rust//:clippy.toml=//:clippy.toml

test --@rules_rust//:rustfmt.toml=//:.rustfmt.toml
Expand Down
5 changes: 3 additions & 2 deletions nativelink-metric-collector/src/metrics_visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ impl From<MetricKind> for CollectionKind {
fn from(kind: MetricKind) -> Self {
match kind {
MetricKind::Counter => CollectionKind::Counter,
MetricKind::String => CollectionKind::String,
_ => CollectionKind::String,
MetricKind::Default | MetricKind::String | MetricKind::Component => {
CollectionKind::String
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions nativelink-metric/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ pub enum MetricKind {
impl From<u64> for MetricKind {
fn from(value: u64) -> Self {
match value {
0 => MetricKind::Default,
0 | 4_u64..=u64::MAX => MetricKind::Default,
1 => MetricKind::Counter,
2 => MetricKind::String,
3 => MetricKind::Component,
_ => MetricKind::Default,
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions nativelink-scheduler/src/memory_awaited_action_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ impl SortedAwaitedActions {
ActionStage::CacheCheck => &mut self.cache_check,
ActionStage::Queued => &mut self.queued,
ActionStage::Executing => &mut self.executing,
ActionStage::Completed(_) => &mut self.completed,
ActionStage::CompletedFromCache(_) => &mut self.completed,
ActionStage::Completed(_) | ActionStage::CompletedFromCache(_) => &mut self.completed,
}
}

Expand Down
5 changes: 3 additions & 2 deletions nativelink-scheduler/src/simple_scheduler_state_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,9 @@ where
ActionStage::CacheCheck => OperationStageFlags::CacheCheck,
ActionStage::Queued => OperationStageFlags::Queued,
ActionStage::Executing => OperationStageFlags::Executing,
ActionStage::Completed(_) => OperationStageFlags::Completed,
ActionStage::CompletedFromCache(_) => OperationStageFlags::Completed,
ActionStage::Completed(_) | ActionStage::CompletedFromCache(_) => {
OperationStageFlags::Completed
}
};
if !filter.stages.intersects(stage_flag) {
return false;
Expand Down
5 changes: 1 addition & 4 deletions nativelink-scheduler/src/store_awaited_action_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@ const CLIENT_ID_TO_OPERATION_ID_KEY_PREFIX: &str = "cid_";
struct OperationIdToAwaitedAction<'a>(Cow<'a, OperationId>);
impl OperationIdToAwaitedAction<'_> {
fn borrow(&self) -> OperationIdToAwaitedAction<'_> {
match self.0 {
Cow::Borrowed(operation_id) => OperationIdToAwaitedAction(Cow::Borrowed(operation_id)),
Cow::Owned(ref operation_id) => OperationIdToAwaitedAction(Cow::Borrowed(operation_id)),
}
OperationIdToAwaitedAction(Cow::Borrowed(self.0.as_ref()))
}
}
impl SchedulerStoreKeyProvider for OperationIdToAwaitedAction<'_> {
Expand Down
3 changes: 1 addition & 2 deletions nativelink-store/src/compression_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ struct UploadState {
impl UploadState {
pub fn new(store: &CompressionStore, upload_size: UploadSizeInfo) -> Result<Self, Error> {
let input_max_size = match upload_size {
UploadSizeInfo::ExactSize(sz) => sz,
UploadSizeInfo::MaxSize(sz) => sz,
UploadSizeInfo::MaxSize(sz) | UploadSizeInfo::ExactSize(sz) => sz,
};

let max_index_count = (input_max_size / u64::from(store.config.block_size)) + 1;
Expand Down
9 changes: 3 additions & 6 deletions nativelink-util/src/action_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,21 @@ impl ActionUniqueQualifier {
/// Get the instance_name of the action.
pub const fn instance_name(&self) -> &String {
match self {
Self::Cachable(action) => &action.instance_name,
Self::Uncachable(action) => &action.instance_name,
Self::Cachable(action) | Self::Uncachable(action) => &action.instance_name,
}
}

/// Get the digest function of the action.
pub const fn digest_function(&self) -> DigestHasherFunc {
match self {
Self::Cachable(action) => action.digest_function,
Self::Uncachable(action) => action.digest_function,
Self::Cachable(action) | Self::Uncachable(action) => action.digest_function,
}
}

/// Get the digest of the action.
pub const fn digest(&self) -> DigestInfo {
match self {
Self::Cachable(action) => action.digest,
Self::Uncachable(action) => action.digest,
Self::Cachable(action) | Self::Uncachable(action) => action.digest,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions nativelink-util/src/platform_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ impl PlatformPropertyValue {

pub fn as_str(&self) -> Cow<str> {
match self {
Self::Exact(value) => Cow::Borrowed(value),
Self::Exact(value) | Self::Priority(value) | Self::Unknown(value) => {
Cow::Borrowed(value)
}
Self::Minimum(value) => Cow::Owned(value.to_string()),
Self::Priority(value) => Cow::Borrowed(value),
Self::Unknown(value) => Cow::Borrowed(value),
}
}
}
Expand Down
35 changes: 18 additions & 17 deletions nativelink-util/src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pub struct Retrier {
fn to_error_code(code: Code) -> ErrorCode {
match code {
Code::Cancelled => ErrorCode::Cancelled,
Code::Unknown => ErrorCode::Unknown,
Code::InvalidArgument => ErrorCode::InvalidArgument,
Code::DeadlineExceeded => ErrorCode::DeadlineExceeded,
Code::NotFound => ErrorCode::NotFound,
Expand Down Expand Up @@ -99,22 +98,24 @@ impl Retrier {
retry_codes.contains(&to_error_code(code))
} else {
match code {
Code::InvalidArgument => false,
Code::FailedPrecondition => false,
Code::OutOfRange => false,
Code::Unimplemented => false,
Code::NotFound => false,
Code::AlreadyExists => false,
Code::PermissionDenied => false,
Code::Unauthenticated => false,
Code::Cancelled => true,
Code::Unknown => true,
Code::DeadlineExceeded => true,
Code::ResourceExhausted => true,
Code::Aborted => true,
Code::Internal => true,
Code::Unavailable => true,
Code::DataLoss => true,
// TODO(SchahinRohani): Handle all cases properly so there is no need for a wildcard match
// All cases where a retry should happen are commented out here and replaced with a wildcard match.
Code::InvalidArgument
| Code::FailedPrecondition
| Code::OutOfRange
| Code::Unimplemented
| Code::NotFound
| Code::AlreadyExists
| Code::PermissionDenied
| Code::Unauthenticated => false,
// Code::Cancelled
// | Code::Unknown
// | Code::DeadlineExceeded
// | Code::ResourceExhausted
// | Code::Aborted
// | Code::Internal
// | Code::Unavailable
// | Code::DataLoss => true,
_ => true,
}
}
Expand Down

0 comments on commit 51a2fd4

Please sign in to comment.