-
Notifications
You must be signed in to change notification settings - Fork 1.7k
let unnecessary_cast work for trivial non_literal expressions #9576
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
let unnecessary_cast work for trivial non_literal expressions #9576
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @flip1995 (or someone else) soon. Please see the contribution instructions for more information. |
Some other tests were broken, convert to draft :( |
I've added some rules on some test files, but I'm not sure why they doesn't work. |
Those tests need to be blessed (because we also check the code output after You can bless them with |
} else if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) { | ||
span_lint_and_sugg( | ||
cx, | ||
UNNECESSARY_CAST, | ||
expr.span, | ||
&format!("casting to the same type is unnecessary (`{cast_from}` -> `{cast_to}`)"), | ||
"try", | ||
cast_str, | ||
Applicability::MachineApplicable, | ||
); | ||
return true; |
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.
Looks like it should already be caught by
if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) { |
no?
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.
It's under a condition so it will only work for numeric literal.
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.
right, you could refactor it by turning your if else
into a if
and remove the afore mentioned line then I think
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've tried it when I implement it, but the control flow is too complicated to do that. At least, I will try to extract a common function lint_same_type
.
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.
Updated
@kraktus Hi, in fact, I blessed them using I found that if I use the function level |
Sorry, I misunderstood and forget to run |
No worries! |
aeeae48
to
1ca60ac
Compare
@rustbot label +S-waiting-on-author -S-waiting-on-review |
☔ The latest upstream changes (presumably #9577) made this pull request unmergeable. Please resolve the merge conflicts. |
Signed-off-by: TennyZhuang <[email protected]>
Signed-off-by: TennyZhuang <[email protected]>
Signed-off-by: TennyZhuang <[email protected]>
Signed-off-by: TennyZhuang <[email protected]>
bbe0d7e
to
c9b9314
Compare
@rustbot label -S-waiting-on-author +S-waiting-on-review |
Looks good to me. Thank you! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Signed-off-by: TennyZhuang [email protected]
changelog: [
unnecessary_cast
]: fix for trivial non_literal expressionsFixes #9562