-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add unneeded_try_convert
lint
#4759
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
☔ The latest upstream changes (presumably #4788) made this pull request unmergeable. Please resolve the merge conflicts. |
cf2fbb0
to
84c49ca
Compare
☔ The latest upstream changes (presumably #4697) made this pull request unmergeable. Please resolve the merge conflicts. |
84c49ca
to
15720ae
Compare
☔ The latest upstream changes (presumably #4801) made this pull request unmergeable. Please resolve the merge conflicts. |
15720ae
to
8254abb
Compare
☔ The latest upstream changes (presumably #4839) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for having to wait so long for a review. I think this generally looks very good and I just found some small things to change.
if let ExprKind::MethodCall(call_path, _, call_args) = &expr.kind; | ||
if call_path.ident.as_str() == "ok_or_else"; | ||
if let [receiver, closure_expr] = &**call_args; | ||
if match_type(cx, cx.tables.expr_ty(receiver), &paths::OPTION); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if match_type(cx, cx.tables.expr_ty(receiver), &paths::OPTION); | |
if is_type_diagnostic_item(cx, cx.tables.expr_ty(receiver), sym!(option_type)); |
if call_path.ident.as_str() == "map_err"; | ||
if let [receiver, mapper_expr] = &**call_args; | ||
let receiver_ty = cx.tables.expr_ty(receiver); | ||
if match_type(cx, receiver_ty, &paths::RESULT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if match_type(cx, receiver_ty, &paths::RESULT); | |
if is_type_diagnostic_item(cx, receiver_ty, sym!(result_type)); |
let option = Some(3); | ||
option.ok_or_else(|| String::from("foo"))?; | ||
option.ok_or_else(|| String::from(complex_computation()))?; | ||
// type arg not fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a leftover todo?
Thanks for contributing to Clippy! Sadly this PR was not updated in quite some time. If you waited on input from a reviewer, we're sorry that this fell under the radar. If you want to continue to work on this, just reopen the PR and/or ping a reviewer. |
changelog: New lint:
unneeded_try_convert
checks for things likeoption.unwrap_or_else(|| <..>::from(..))?
as thefrom
is unneeded becase?
will do it for you.Closes #4676
Some notes:
clippy::redundant_closure
catchesresult.map_err(|x| String::from(x))?
and suggestsresult.map_err(String::from)?
, which this then catches and suggestsresult?
, but this also catchesresult.map_err(|x| String::from(x))?
but instead suggestsresult.map_err(|x| x)?
. I'm not sure whether we should add a special case specifically for that in this lint or maybe have another lint for uselessmap
or if it's fine to just leave that as-is.