Closed
Description
I tried this code:
fn func(s: &str) -> Option<&'static [&'static str]> {
Some(match s {
"a" => &["A"],
_ => return None,
})
}
I expected to see this happen: no warning
Instead, this happened:
unnecessary_wraps
misses return None
and emit warning.
warning: this function's return value is unnecessarily wrapped by `Option`
--> src/lib.rs:1:1
|
1 | / fn func(s: &str) -> Option<&'static [&'static str]> {
2 | | Some(match s {
3 | | "a" => &["A"],
4 | | _ => return None,
5 | | })
6 | | }
| |_^
|
= note: `#[warn(clippy::unnecessary_wraps)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps
help: remove `Option` from the return type...
|
1 | fn func(s: &str) -> &'static [&'static str] {
| ^^^^^^^^^^^^^^^^^^^^^^^
help: ...and change the returning expressions
|
2 | match s {
3 | "a" => &["A"],
4 | _ => return None,
5 | }
|
Meta
cargo clippy -V
: clippy 0.0.212 (1c389ff 2020-11-24)rustc -Vv
:rustc 1.50.0-nightly (1c389ffef 2020-11-24) binary: rustc commit-hash: 1c389ffeff814726dec325f0f2b0c99107df2673 commit-date: 2020-11-24 host: x86_64-apple-darwin release: 1.50.0-nightly
Mentioning @matsujika who implemented this lint in #6070.