Skip to content

Commit

Permalink
clippy: add manual_is_variant_and clippy lint (#10556)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Aug 27, 2024
1 parent 763e961 commit 69e5a85
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ zero_sized_map_values = "warn"
implicit_clone = "warn"
cloned_instead_of_copied = "warn"
option_as_ref_cloned = "warn"
manual_is_variant_and = "warn"

# These are nursery lints which have findings. Allow them for now. Some are not
# quite mature enough for use in our codebase and some we don't really want.
Expand Down
3 changes: 1 addition & 2 deletions crates/consensus/beacon/src/engine/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ where
///
/// Note: this is mainly for debugging purposes.
pub(crate) fn has_reached_max_block(&self, progress: BlockNumber) -> bool {
let has_reached_max_block =
self.max_block.map(|target| progress >= target).unwrap_or_default();
let has_reached_max_block = self.max_block.is_some_and(|target| progress >= target);
if has_reached_max_block {
trace!(
target: "consensus::engine::sync",
Expand Down
4 changes: 1 addition & 3 deletions crates/net/downloaders/src/bodies/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ where
let nothing_to_request = self.download_range.is_empty() ||
// or all blocks have already been requested.
self.in_progress_queue
.last_requested_block_number
.map(|last| last == *self.download_range.end())
.unwrap_or_default();
.last_requested_block_number.is_some_and(|last| last == *self.download_range.end());

nothing_to_request &&
self.in_progress_queue.is_empty() &&
Expand Down
2 changes: 1 addition & 1 deletion crates/net/downloaders/src/bodies/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ where
}

// Buffer any empty headers
while this.pending_headers.front().map(|h| h.is_empty()).unwrap_or_default() {
while this.pending_headers.front().is_some_and(|h| h.is_empty()) {
let header = this.pending_headers.pop_front().unwrap();
this.buffer.push(BlockResponse::Empty(header));
}
Expand Down
7 changes: 1 addition & 6 deletions crates/net/downloaders/src/headers/reverse_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,7 @@ where
{
fn update_local_head(&mut self, head: SealedHeader) {
// ensure we're only yielding headers that are in range and follow the current local head.
while self
.queued_validated_headers
.last()
.map(|last| last.number <= head.number)
.unwrap_or_default()
{
while self.queued_validated_headers.last().is_some_and(|last| last.number <= head.number) {
// headers are sorted high to low
self.queued_validated_headers.pop();
}
Expand Down
6 changes: 2 additions & 4 deletions crates/net/network/src/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,8 @@ impl StateFetcher {

let resp = self.inflight_headers_requests.remove(&peer_id);

let is_likely_bad_response = resp
.as_ref()
.map(|r| res.is_likely_bad_headers_response(&r.request))
.unwrap_or_default();
let is_likely_bad_response =
resp.as_ref().is_some_and(|r| res.is_likely_bad_headers_response(&r.request));

if let Some(resp) = resp {
// delegate the response
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl NetworkState {
match response.poll(cx) {
Poll::Ready(res) => {
// check if the error is due to a closed channel to the session
if res.err().map(|err| err.is_channel_closed()).unwrap_or_default() {
if res.err().is_some_and(|err| err.is_channel_closed()) {
debug!(
target: "net",
?id,
Expand Down
7 changes: 3 additions & 4 deletions crates/net/p2p/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ impl EthResponseValidator for RequestResult<Vec<Header>> {
}

match request.start {
BlockHashOrNumber::Number(block_number) => headers
.first()
.map(|header| block_number != header.number)
.unwrap_or_default(),
BlockHashOrNumber::Number(block_number) => {
headers.first().is_some_and(|header| block_number != header.number)
}
BlockHashOrNumber::Hash(_) => {
// we don't want to hash the header
false
Expand Down
2 changes: 1 addition & 1 deletion crates/stages/stages/src/stages/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ mod tests {
let storage_entry = storage_cursor
.seek_by_key_subkey(hashed_address, hashed_slot)
.unwrap();
if storage_entry.map(|v| v.key == hashed_slot).unwrap_or_default() {
if storage_entry.is_some_and(|v| v.key == hashed_slot) {
storage_cursor.delete_current().unwrap();
}

Expand Down

0 comments on commit 69e5a85

Please sign in to comment.