Use bool::then instead of then_some with function calls (#6156)
I noticed that hardware benchmarks are being run even though we pass the --no-hardware-benchmarks cli flag. After some debugging, the cause is an incorrect usage of the `then_some` method. From [std docs](https://doc.rust-lang.org/std/primitive.bool.html#method.then_some): > Arguments passed to then_some are eagerly evaluated; if you are passing the result of a function call, it is recommended to use [then](https://doc.rust-lang.org/std/primitive.bool.html#method.then), which is lazily evaluated. ```rust let mut a = 0; let mut function_with_side_effects = || { a += 1; }; true.then_some(function_with_side_effects()); false.then_some(function_with_side_effects()); // `a` is incremented twice because the value passed to `then_some` is // evaluated eagerly. assert_eq!(a, 2); ``` This PR fixes all the similar usages of the `then_some` method across the codebase. polkadot address: 138eUqXvUYT3o4GdbnWQfGRzM8yDWh5Q2eFrFULL7RAXzdWD --------- Signed-off-by:Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by:
Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by:
Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Showing
- cumulus/polkadot-omni-node/lib/src/command.rs 9 additions, 7 deletionscumulus/polkadot-omni-node/lib/src/command.rs
- polkadot/cli/src/command.rs 6 additions, 4 deletionspolkadot/cli/src/command.rs
- polkadot/node/network/collator-protocol/src/collator_side/validators_buffer.rs 1 addition, 1 deletion.../collator-protocol/src/collator_side/validators_buffer.rs
- prdoc/pr_6156.prdoc 23 additions, 0 deletionsprdoc/pr_6156.prdoc
- substrate/bin/node/cli/src/service.rs 6 additions, 4 deletionssubstrate/bin/node/cli/src/service.rs
- substrate/client/network/src/discovery.rs 1 addition, 1 deletionsubstrate/client/network/src/discovery.rs
- substrate/client/network/sync/src/strategy/state.rs 1 addition, 1 deletionsubstrate/client/network/sync/src/strategy/state.rs
- substrate/client/network/sync/src/strategy/warp.rs 1 addition, 1 deletionsubstrate/client/network/sync/src/strategy/warp.rs
- substrate/frame/contracts/proc-macro/src/lib.rs 1 addition, 1 deletionsubstrate/frame/contracts/proc-macro/src/lib.rs
- substrate/frame/support/procedural/src/pallet/expand/pallet_struct.rs 1 addition, 1 deletion...ame/support/procedural/src/pallet/expand/pallet_struct.rs
- substrate/frame/support/src/migrations.rs 2 additions, 2 deletionssubstrate/frame/support/src/migrations.rs
- templates/parachain/node/src/command.rs 9 additions, 7 deletionstemplates/parachain/node/src/command.rs
Please register or sign in to comment