-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Description
I have this code:
let mut size: usize = 0;
let mut page: u64 = 1;
if let Some(pagination) = pagination {
size = pagination.size().try_into().unwrap();
page = pagination.page();
}
and clippy is saying:
warning: `if _ { .. } else { .. }` is an expression
239 | / let mut page: u64 = 1;
240 | |
241 | | if let Some(pagination) = pagination {
242 | | size = pagination.size().try_into().unwrap();
243 | | page = pagination.page();
244 | | }
| |_____^ help: it is more idiomatic to write: `let <mut> page = if let Some(pagination) = pagination { ..; pagination.page() } else { 1 };`
|
= note: you might not need `mut` at all
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_let_if_seq
= note: `-W clippy::useless-let-if-seq` implied by `-W clippy::nursery`
= help: to override `-W clippy::nursery` add `#[allow(clippy::useless_let_if_seq)]`
So I think I should change it to:
let size = input
.pagination
.as_ref()
.map_or(0, |pagination| pagination.size().try_into().unwrap());
let page = input.pagination.as_ref().map_or(1, Input::page);
Am I right?
Isn't the check on the .map_or()
duplicated now? Is this a performance regression?
Metadata
Metadata
Assignees
Labels
No labels