rust-analyzer
rust-analyzer copied to clipboard
Code action to transform between `foo_or` and `foo_or_else`
The standard library has a bunch of functions with two variants such as unwrap_or and unwrap_or_else, ok_or and ok_or_else.
The code action would transform for example:
a.unwrap_or(calculate(x)) -> a.unwrap_or_else(|| calculate(x))
a.unwrap_or(calculate()) -> a.unwrap_or_else(calculate)
and back
a.unwrap_or_else(|| 5) -> a.unwrap_or(5)
same for the other functions with or and or_else variants.
clippy currently has lints that warn against these, and suggests fixes, but it would be nice to have a code action for it :) clippy::or_fun_call clippy::unnecessary_lazy_evaluations