Simplify some Option / Result / ? operator patterns (#8653)

* Simplify some Option / Result / ? operator patterns

When those match a combinator exactly.

Tool-aided by [comby-rust](https://github.com/huitseeker/comby-rust).

* adjust after review

* adjust post-review
This commit is contained in:
François Garillot
2021-04-23 09:36:10 -04:00
committed by GitHub
parent 541692c4a8
commit 052be8bbef
37 changed files with 77 additions and 188 deletions
+1 -4
View File
@@ -127,10 +127,7 @@ where
}
let amount = token.calculate_amount(metadata);
let new_value = match self.gas_left.checked_sub(amount) {
None => None,
Some(val) => Some(val),
};
let new_value = self.gas_left.checked_sub(amount);
// We always consume the gas even if there is not enough gas.
self.gas_left = new_value.unwrap_or_else(Zero::zero);
+1 -5
View File
@@ -26,16 +26,12 @@ pub fn migrate<T: Config>() -> Weight {
Some(version) if version == PalletVersion::new(3, 0, 0) => {
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
let _ = <CurrentSchedule<T>>::translate::<u32, _>(|version| {
if let Some(version) = version {
Some(Schedule {
version.map(|version| Schedule {
version: version.saturating_add(1),
// Default limits were not decreased. Therefore it is OK to overwrite
// the schedule with the new defaults.
.. Default::default()
})
} else {
None
}
});
}
_ => (),
+1 -4
View File
@@ -407,10 +407,7 @@ where
);
// Check what happened after enaction of the verdict.
let alive_contract_info = match new_contract_info.map_err(|_| IsTombstone)? {
None => return Err(IsTombstone),
Some(contract) => contract,
};
let alive_contract_info = new_contract_info.map_err(|_| IsTombstone)?.ok_or_else(|| IsTombstone)?;
// Compute how much would the fee per block be with the *updated* balance.
let total_balance = T::Currency::total_balance(account);