-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend option-map-unwrap-or-else to Result #1590
Comments
This was implemented in #2189, so it could be closed, though I'll note that both the OP suggestion and the implementation of the lint are wrong in the general case. |
Why is it wrong?
let intermediate = match res {
Ok(v) => Ok(f(v)),
Err(err) => Err(err),
};
match intermediate {
Ok(v) => v,
Err(err) => g(err),
}
match res {
Ok(v) => f(v),
Err(err) => g(err),
} These look isomorphic to me. @oli-obk Good to close? |
@mathstuf If you were responding to my comment, you should read more closely what I wrote and the lint is suggesting you to use. Notice that it's not suggesting |
Ah, missed the |
Adding the `.ok()` changes the semantics since that assumes that `g` was ignoring its argument. Instead, allow `g` to keep taking its argument and preserve the isomorphism to the original code in the suggestion. Fixes rust-lang#1590
Adding the `.ok()` changes the semantics since that assumes that `g` was ignoring its argument. Instead, allow `g` to keep taking its argument and preserve the isomorphism to the original code in the suggestion. Fixes rust-lang#1590
opt.map(f).unwrap_or_else(g)
is linted to suggestopt.map_or_else(g, f)
, butres.map(f).unwrap_or_else(g)
is not linted even though it could beres.ok().map_or_else(|_| g(), f)
Somewhat ugly suggestion, so should be allow-by-default, maybe we should poke rustc to add
Result::map_or_else
The text was updated successfully, but these errors were encountered: