Suggest replacing .unwrap_or_else(|| panic!("..."))
with .expect("...")
on Option<T: Debug>
#11271
Labels
A-lint
Area: New lints
What it does
Makes this roundabout way of writing
.expect
actually anexpect
call where it's feasible.Advantage
The code is shorter and more straightforward in what it does, and IMHO more idiomatic.
Drawbacks
The parameter to
expect
is evaluated even when it doesn't end up being used.Cf.
unwrap_or
vs.unwrap_or_else
.Not a big deal for literals, but could be significant in rare cases.
Example
This is a straight-up real-world example. I can trim it down upon request.
(https://github.com/ruffle-rs/ruffle/blob/2621dd78eefab17e98dc03fafa25ed421784a712/desktop/src/gui/controller.rs#L213)
Could be written as:
The text was updated successfully, but these errors were encountered: