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

Fix float_cmp false positive when comparing signum #4275

Merged
merged 2 commits into from
Jul 16, 2019

Conversation

jayhardee9
Copy link
Contributor

fixes #4248

changelog: Fix float_cmp false positive when comparing signum

Jerry Hardee added 2 commits July 15, 2019 12:46
f1.signum() == f2.signum()
f1.signum() != f2.signum()
should not trigger a warning.
@@ -493,6 +499,25 @@ fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool {
}
}

// Return true if `expr` is the result of `signum()` invoked on a float value.
fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
// The negation of a signum is still a signum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, good catch!

Lint idea (for another PR):

// for
f1.signum() == -f2.signum()
// suggest
f1.signum() != f2.signum()

Same goes for -sig==+sig and -sig==-sig and the != variants.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm not sure that's the best way to simplify f1.signum() == -f2.signum(), since if both f1 and f2 are 0, then also f1.signum() == f2.signum() == 0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh your right, in this case we can't really lint this. Never mind then :D

@flip1995
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Jul 16, 2019

📌 Commit 8a8eedf has been approved by flip1995

@bors
Copy link
Contributor

bors commented Jul 16, 2019

⌛ Testing commit 8a8eedf with merge 164310d...

bors added a commit that referenced this pull request Jul 16, 2019
Fix float_cmp false positive when comparing signum

fixes #4248

changelog: Fix float_cmp false positive when comparing signum
@bors
Copy link
Contributor

bors commented Jul 16, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: flip1995
Pushing 164310d to master...

@bors bors merged commit 8a8eedf into rust-lang:master Jul 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

float_cmp should not apply to results of signum()
3 participants