if foo.is_some() {
use(foo.unwrap());
}
should be
if let Some(foo) = foo {
use(foo);
}
It needs to check for the existence of && or ||. I have written things like
if something && foo.is_some() {
use(foo.unwrap());
}
The other alternative in my case is to have first the if let then another if something nested within. Which for some cases is over kill.
This seems to be a duplicate of #1770?
I was also surprised that Clippy doesn't catch it already. It looks like it's implemented and in "nursery":
https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap
Are there known problems preventing this from being on by default?
Known problems says "Limitations of the borrow checker might make unwrap() necessary sometimes?".
The only thing I could find, why this is in nursery is: https://github.com/rust-lang/rust-clippy/pull/2811#discussion_r193715852. Since the tests look good I would suggest to move this to complexity and see if someone complains?
NLL shipped since that comment was written, so maybe it's fine? I can't think of any borrow that would break it. .unwrap() moves, so there can't be any outstanding borrows when it runs.
Yeah I also can't think of a case that would break this with NLL. Let's move it to complexity.
Most helpful comment
Yeah I also can't think of a case that would break this with NLL. Let's move it to complexity.