Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fixes "for loop over an Option" warnings (#6291)
Browse files Browse the repository at this point in the history
Was seeing these warnings when running `cargo check --all`:

```
warning: for loop over an `Option`. This is more readably written as an `if let` statement
    --> node/core/approval-voting/src/lib.rs:1147:21
     |
1147 |             for activated in update.activated {
     |                              ^^^^^^^^^^^^^^^^
     |
     = note: `#[warn(for_loops_over_fallibles)]` on by default
help: to check pattern in a loop use `while let`
     |
1147 |             while let Some(activated) = update.activated {
     |             ~~~~~~~~~~~~~~~         ~~~
help: consider using `if let` to clear intent
     |
1147 |             if let Some(activated) = update.activated {
     |             ~~~~~~~~~~~~         ~~~
```

My guess is that `activated` used to be a SmallVec or similar, as is
`deactivated`. It was changed to an `Option`, the `for` still compiled (it's
technically correct, just weird), and the compiler didn't catch it until now.
  • Loading branch information
mrcnski authored and ordian committed Nov 15, 2022
1 parent ed143f2 commit 17b7567
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ async fn handle_from_overseer<Context>(
FromOrchestra::Signal(OverseerSignal::ActiveLeaves(update)) => {
let mut actions = Vec::new();

for activated in update.activated {
if let Some(activated) = update.activated {
let head = activated.hash;
match import::handle_new_head(ctx, state, db, head, &*last_finalized_height).await {
Err(e) => return Err(SubsystemError::with_origin("db", e)),
Expand Down
2 changes: 1 addition & 1 deletion node/core/bitfield-signing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async fn run<Context>(
}
}

for leaf in update.activated {
if let Some(leaf) = update.activated {
let sender = ctx.sender().clone();
let leaf_hash = leaf.hash;

Expand Down
2 changes: 1 addition & 1 deletion node/core/chain-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ where
return Ok(())
}
FromOrchestra::Signal(OverseerSignal::ActiveLeaves(update)) => {
for leaf in update.activated {
if let Some(leaf) = update.activated {
let write_ops = handle_active_leaf(
ctx.sender(),
&*backend,
Expand Down
2 changes: 1 addition & 1 deletion node/core/provisioner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn handle_active_leaves_update(
per_relay_parent.remove(deactivated);
}

for leaf in update.activated {
if let Some(leaf) = update.activated {
let delay_fut = Delay::new(PRE_PROPOSE_TIMEOUT).map(move |_| leaf.hash).boxed();
per_relay_parent.insert(leaf.hash, PerRelayParent::new(leaf));
inherent_delays.push(delay_fut);
Expand Down
2 changes: 1 addition & 1 deletion node/network/availability-recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ async fn handle_signal(state: &mut State, signal: OverseerSignal) -> SubsystemRe
OverseerSignal::Conclude => Ok(true),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { activated, .. }) => {
// if activated is non-empty, set state.live_block to the highest block in `activated`
for activated in activated {
if let Some(activated) = activated {
if activated.number > state.live_block.0 {
state.live_block = (activated.number, activated.hash)
}
Expand Down
2 changes: 1 addition & 1 deletion node/network/bitfield-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl BitfieldDistribution {
})) => {
let _timer = self.metrics.time_active_leaves_update();

for activated in activated {
if let Some(activated) = activated {
let relay_parent = activated.hash;

gum::trace!(target: LOG_TARGET, ?relay_parent, "activated");
Expand Down
2 changes: 1 addition & 1 deletion node/network/bridge/src/rx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ where
num_deactivated = %deactivated.len(),
);

for activated in activated {
if let Some(activated) = activated {
let pos = live_heads
.binary_search_by(|probe| probe.number.cmp(&activated.number).reverse())
.unwrap_or_else(|i| i);
Expand Down
2 changes: 1 addition & 1 deletion node/network/statement-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ impl<R: rand::Rng> StatementDistributionSubsystem<R> {
}
}

for activated in activated {
if let Some(activated) = activated {
let relay_parent = activated.hash;
let span = PerLeafSpan::new(activated.span, "statement-distribution");
gum::trace!(
Expand Down

0 comments on commit 17b7567

Please sign in to comment.