fix kvstore Clippy warning: `if _ { .. } else { .. }` is an expression
Categories
(Toolkit :: Storage, enhancement)
Tracking
()
Tracking | Status | |
---|---|---|
firefox69 | --- | fixed |
People
(Reporter: myk, Assigned: nanj)
Details
Attachments
(1 file)
It's tricky to run Clippy on Rust crates in mozilla-central, but it's possible to do so for some of them via a specific sequence of cargo invocations; and when I do that for kvstore:
cargo clean && cargo check -p kvstore && touch toolkit/components/kvstore/src/lib.rs && cargo clippy -p kvstore
Then Clippy reports this warning:
warning: `if _ { .. } else { .. }` is an expression
--> toolkit/components/kvstore/src/task.rs:135:5
|
135 | / let size;
136 | |
137 | | if current_size < INCREMENTAL_RESIZE_THRESHOLD {
138 | | size = current_size << 1;
139 | | } else {
140 | | size = current_size + INCREMENTAL_RESIZE_STEP;
141 | | }
| |_____^ help: it is more idiomatic to write: `let size = if current_size < INCREMENTAL_RESIZE_THRESHOLD { current_size << 1 } else { current_size + INCREMENTAL_RESIZE_STEP };`
|
= note: #[warn(clippy::useless_let_if_seq)] on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_let_if_seq
Assignee | ||
Comment 1•5 years ago
|
||
Assignee | ||
Comment 2•5 years ago
|
||
Nice tip! Thanks!
Hmm, looks like I have to set some environment variables to run that command, it yelled at me with environment variable 'MOZ_TOPOBJDIR' not defined
.
Assignee | ||
Updated•5 years ago
|
Reporter | ||
Comment 3•5 years ago
|
||
(In reply to Nan Jiang [:nanj] from comment #2)
Hmm, looks like I have to set some environment variables to run that command, it yelled at me with
environment variable 'MOZ_TOPOBJDIR' not defined
.
Ah, right, I forgot that I have that set by default in my environment. (Some other crates that depend on servo have additional requirements that I haven't been able to figure out how to satisfy yet.)
Comment 4•5 years ago
|
||
Nifty! I've used env MOZ_TOPOBJDIR=$HOME/Code/gecko/obj-fx-debug cargo fmt
locally, too, it's nice that Clippy works now!
Pushed by najiang@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a30adf37aef0 Clippy fix for kvstore r=myk
Comment 6•5 years ago
|
||
bugherder |
Description
•