Skip to content

Commit 002436b

Browse files
Junha Yangmajecty
authored andcommitted
Fix the new clippy error match_like_matches_macro
1 parent e21e4dd commit 002436b

File tree

6 files changed

+23
-58
lines changed

6 files changed

+23
-58
lines changed

core/src/consensus/tendermint/types.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ impl TendermintState {
7575
}
7676

7777
pub fn is_propose_wait_empty_block_timer(&self) -> bool {
78-
match self {
79-
TendermintState::ProposeWaitEmptyBlockTimer {
80-
..
81-
} => true,
82-
_ => false,
83-
}
78+
matches!(self,
79+
TendermintState::ProposeWaitEmptyBlockTimer {
80+
..
81+
})
8482
}
8583

8684
pub fn is_commit(&self) -> bool {
@@ -96,12 +94,10 @@ impl TendermintState {
9694
}
9795

9896
pub fn is_commit_timedout(&self) -> bool {
99-
match self {
100-
TendermintState::CommitTimedout {
101-
..
102-
} => true,
103-
_ => false,
104-
}
97+
matches! (self,
98+
TendermintState::CommitTimedout {
99+
..
100+
})
105101
}
106102

107103
pub fn committed(&self) -> Option<(View, BlockHash)> {
@@ -330,9 +326,6 @@ impl Proposal {
330326
}
331327

332328
pub fn is_none(&self) -> bool {
333-
match self {
334-
Proposal::None => true,
335-
_ => false,
336-
}
329+
matches!(self, Proposal::None)
337330
}
338331
}

core/src/consensus/tendermint/vote_regression_checker.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ impl VoteRegressionChecker {
1414

1515
pub fn check(&mut self, vote_on: &VoteOn) -> bool {
1616
assert!(
17-
match vote_on.step.step {
18-
Step::Propose | Step::Prevote | Step::Precommit => true,
19-
_ => false,
20-
},
17+
matches!(vote_on.step.step, Step::Propose | Step::Prevote | Step::Precommit),
2118
"We don't vote on Commit. Check your code"
2219
);
2320

informer/src/informer_service/informer_service_handler.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ impl InformerService {
129129
}
130130

131131
fn compare_event_types(tag: &EventTags, event: &Events) -> bool {
132-
match (tag, event) {
133-
(EventTags::PeerAdded, Events::PeerAdded(..)) => true,
134-
_ => false,
135-
}
132+
matches!((tag, event), (EventTags::PeerAdded, Events::PeerAdded(..)))
136133
}
137134

138135
pub fn notify_client(&self, popup_event: Events) {

network/src/routing_table.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ impl RoutingTable {
136136

137137
pub fn is_banned(&self, target: &SocketAddr) -> bool {
138138
let entries = self.entries.read();
139-
match entries.get(target) {
140-
Some(State::Banned) => true,
141-
_ => false,
142-
}
139+
matches!(entries.get(target), Some(State::Banned))
143140
}
144141

145142
pub fn is_establishing_or_established(&self, target: &SocketAddr) -> bool {
@@ -160,14 +157,12 @@ impl RoutingTable {
160157

161158
pub fn is_established(&self, target: &SocketAddr) -> bool {
162159
let entries = self.entries.read();
163-
if let Some(State::Established {
164-
..
165-
}) = entries.get(target)
166-
{
167-
true
168-
} else {
169-
false
170-
}
160+
matches!(
161+
entries.get(target),
162+
Some(State::Established {
163+
..
164+
})
165+
)
171166
}
172167

173168
pub fn is_establishing(&self, target: &SocketAddr) -> bool {
@@ -589,14 +584,7 @@ impl RoutingTable {
589584
let entry = entries.entry(target).or_default();
590585
let mut new_state = State::Banned;
591586
std::mem::swap(&mut new_state, entry);
592-
if let State::Established {
593-
..
594-
} = new_state
595-
{
596-
true
597-
} else {
598-
false
599-
}
587+
matches!(new_state, State::Established {..})
600588
}
601589

602590
pub fn unban(&self, target: SocketAddr) -> bool {

sync/src/block/extension.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,7 @@ impl Extension {
350350

351351
self.check_sync_variable();
352352
if let Some(requests) = self.requests.get_mut(id) {
353-
let have_body_request = {
354-
requests.iter().any(|r| match r {
355-
(_, RequestMessage::Bodies(..)) => true,
356-
_ => false,
357-
})
358-
};
353+
let have_body_request = { requests.iter().any(|r| matches!(r, (_, RequestMessage::Bodies(..)))) };
359354
if have_body_request {
360355
cdebug!(SYNC, "Wait body response");
361356
return
@@ -382,10 +377,8 @@ impl Extension {
382377
}
383378

384379
fn send_chunk_request(&mut self, block: &BlockHash, root: &H256) {
385-
let have_chunk_request = self.requests.values().flatten().any(|r| match r {
386-
(_, RequestMessage::StateChunk(..)) => true,
387-
_ => false,
388-
});
380+
let have_chunk_request =
381+
self.requests.values().flatten().any(|r| matches!(r, (_, RequestMessage::StateChunk(..))));
389382

390383
if !have_chunk_request {
391384
let mut peer_ids: Vec<_> = self.header_downloaders.keys().cloned().collect();

util/timer/src/timer.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,7 @@ impl ScheduleStateControl {
503503

504504
fn is_cancelled(&self) -> bool {
505505
let state = self.state.read();
506-
match *state {
507-
ScheduleState::Cancelled => true,
508-
_ => false,
509-
}
506+
matches!(*state, ScheduleState::Cancelled)
510507
}
511508

512509
fn within_lock<F, T>(&self, mut callback: F) -> T

0 commit comments

Comments
 (0)