rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.49k stars 1.55k forks source link

Lint suggestion - elide pointless match #3208

Open olson-dan opened 6 years ago

olson-dan commented 6 years ago

I noticed some code like this that I had written not long ago:

        let meta = if let Some(meta) = data_store.get_meta(reference.key) {
            Some(meta)
        } else {
            None
        };

This can of course be simplified to

        let meta = data_store.get_meta(reference.key);

There may be value in a clippy lint to catch cases like this, as it already warns on a lot of redundant code.

clarfonthey commented 6 years ago

I vote to call this re-structuring. Destructuring only to construct the thing you just destructured.