Closed Bug 1557176 Opened 1 year ago Closed 1 year ago

fix kvstore Clippy warning: `if _ { .. } else { .. }` is an expression

Categories

(Toolkit :: Storage, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla69
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

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: nobody → najiang

(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.)

Nifty! I've used env MOZ_TOPOBJDIR=$HOME/Code/gecko/obj-fx-debug cargo fmt locally, too, it's nice that Clippy works now!

Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla69
You need to log in before you can comment on or make changes to this bug.