-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix FP in lint [needless_match]
#8549
Conversation
r? @giraffate (rust-highfive has picked a reviewer for you, use r? to override) |
r? @llogiq |
I remove the |
remove `ref`/`ref mut` check
[needless_match]
[needless_match]
[needless_match]
[needless_match]
/// Check if the type of the match operand differs with the assigned local or function return type | ||
/// | ||
/// Can also be used to check for the `let_expr` in `IfLet` as well. | ||
fn is_type_differ(cx: &LateContext<'_>, match_expr: &Expr<'_>, expr: &Expr<'_>) -> bool { | ||
if let Some(p_node) = get_parent_node(cx.tcx, expr.hir_id) { |
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.
I'm not so sure about if this is the correct way to check for type coercion, I basically just check for the assigned variable/function return type to see if those are the same as match expression.
Although I saw methods like TypeckResult::is_coercion_cast
or something, but I don't think those work in these case.
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.
We have clippy_utils::is_adjusted(cx, expr)
, which should do the trick more easily.
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.
We have
clippy_utils::is_adjusted(cx, expr)
, which should do the trick more easily.
Well... I later realized that I might still need to keep it this way, because I do need to make sure that the type of match input and output are the same, not just coercion but also as what #8599 suggested. unless there is another util function that I can use to do the check.
[needless_match]
[needless_match]
[needless_match]
[needless_match]
It's kinda harsh seeing my mistakes being addressed multiple times tbh 😭 , so if anyone is not busy at the moment (sorry to bother if you are), please help me reviewing this, thanks~~~ edit: Oh... here are some 'ol little pings @giraffate @llogiq |
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 good, I just have a very small suggestion. r=me when applied.
@@ -171,27 +191,30 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool { | |||
false | |||
} | |||
|
|||
fn has_identical_segments(left_segs: &[PathSegment<'_>], right_segs: &[PathSegment<'_>]) -> bool { | |||
fn same_segments(left_segs: &[PathSegment<'_>], right_segs: &[PathSegment<'_>]) -> bool { |
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.
I think we have an over
function for such things skmewhere in clippy_utils
.
Thank you! @bors r+ |
📌 Commit 85b081b has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes: #8542
fixes: #8551
fixes: #8595
fixes: #8599
changelog: check for more complex custom type, and ignore type coercion in [
needless_match
]