mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 19:31:02 +00:00
Fixes "for loop over an Option" warnings (#6291)
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.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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!(
|
||||
|
||||
Reference in New Issue
Block a user