Skip to content
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

Euclidean operations combined with sign casting cannot result in loss of a sign #4818

Closed
jhpratt opened this issue Nov 14, 2019 · 4 comments · Fixed by #4883
Closed

Euclidean operations combined with sign casting cannot result in loss of a sign #4818

jhpratt opened this issue Nov 14, 2019 · 4 comments · Fixed by #4883
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@jhpratt
Copy link
Member

jhpratt commented Nov 14, 2019

.rem_euclid and .div_euclid always results in a non-negative value, so casting to the same or larger size (except unsigned) should be allowed.

(-1_001).rem_euclid(1_000 as i16) as u16

There are also checked versions of these functions (.checked_rem_euclid and .checked_div_euclid) which should also be handled.

Version: clippy 0.0.212 (c8e3cfb 2019-10-28)

Related: #4605 (.abs), #4743 (.checked_abs)

@JohnTitor JohnTitor added C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Nov 16, 2019
@flip1995 flip1995 added the good-first-issue These issues are a good way to get started with Clippy label Nov 19, 2019
@krishna-veerareddy
Copy link
Contributor

I would like to work on this if nobody else started working on it.

@flip1995
Copy link
Member

flip1995 commented Dec 2, 2019

It's all yours. If you have any questions just ask here or open a WIP PR.

@krishna-veerareddy
Copy link
Contributor

@jhpratt Hey the result of .div_euclid can be non-negative so I am not white-listing it in my PR. Please let me know if I got that wrong and Ill white-list it.

@jhpratt
Copy link
Member Author

jhpratt commented Dec 6, 2019

Ah, apparently I didn't check the docs on that one. You're absolutely right that it can result in a negative number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants