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

Change comparsion for checking if number is negative to include 128 #15105

Merged
merged 2 commits into from Jun 22, 2023

Conversation

dfireBird
Copy link
Contributor

The last byte in Little-Endian representation of negative integers start at 128 (Ox80) till 255 (OxFF). The comparison before the fix didn't check for 128 which made is_negative variable as false.

Potentially fixes #15096

Reason: The last byte in Little Endian representation of negative
integers start at 128 (Ox80) till 255 (OxFF). The comparison before
the fix didn't check for 128 which made is_negative variable as false.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 22, 2023
@dfireBird
Copy link
Contributor Author

dfireBird commented Jun 22, 2023

++ @HKalbasi I created a PR for the fix.

@HKalbasi
Copy link
Member

Can you also add some tests in hir_ty::const_eval::tests to make sure that it won't regress in future?

@dfireBird
Copy link
Contributor Author

Should I create a new test function or should I add the tests in hir_ty::const_eval::tests::consts test function?

@HKalbasi
Copy link
Member

Both would work, do it as you see fit.

@dfireBird
Copy link
Contributor Author

dfireBird commented Jun 22, 2023

I added the tests and it passed with fix. I temporarily reverted the see if the test fails or not but the test passed.
Then I checked the implementation of the check_number and saw it doesn't use the pad16 function where the bug was present.

Should I change my tests to test the HirDisplay trait instead of using check_number? Can you help me on this?

@HKalbasi
Copy link
Member

I think using as casts like the original example in #15096 and comparing large positive and negative numbers with themself and with zero would trigger the bug.

For checking the HirDisplay you can also add a test in ide::hover::tests, but keep the as cast and compare tests in hir-ty.

@dfireBird
Copy link
Contributor Author

dfireBird commented Jun 22, 2023

I wrote more tests in hir_ty::const_eval::tests::consts and using as cast like in original example triggered the bug and made the test fail. I also added some tests to the ide::hover::tests module as well.

P.S: Should I amend the two test commits into one, so they are organized and reduce the commit clutter?

@HKalbasi
Copy link
Member

P.S: Should I amend the two test commits into one, so they are organized and reduce the commit clutter?

Yes please, and then we can merge this I think.

Added a test near positive extermes and two test near negative
extermes as well one for 0.
Added a test using the `as` cast and one with comparison with 0.
@HKalbasi
Copy link
Member

Thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Jun 22, 2023

📌 Commit 410ede9 has been approved by HKalbasi

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jun 22, 2023

⌛ Testing commit 410ede9 with merge 6c73f67...

@bors
Copy link
Collaborator

bors commented Jun 22, 2023

☀️ Test successful - checks-actions
Approved by: HKalbasi
Pushing 6c73f67 to master...

@bors bors merged commit 6c73f67 into rust-lang:master Jun 22, 2023
10 checks passed
@dfireBird dfireBird deleted the fix-15096 branch December 5, 2023 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrong negative integer constant preview (on hover)
4 participants