Skip to content

Fix an incorrect error message regarding the size of usize and isize in cast_precision_loss. #14966

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SLUCHABLUB
Copy link
Contributor

When trying to cast a usize or isize using as to a type of potentially smaller size the cast_precision_loss would claim that the size of usize is "32 or 64 bits". It is now corrected to "16, 32, or 64 bits".

changelog: [cast_precision_loss]: fix the error messages claim regarding the size of usize and isize.

@rustbot
Copy link
Collaborator

rustbot commented Jun 4, 2025

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 4, 2025
@samueltardieu
Copy link
Contributor

Shouldn't we give a better error message? (and use "may cause" since on 16 bit usize platforms this is fine)

For example:

casting `usize` to `f32` may cause a loss of precision (`usize` can be as large as 64 bits wide depending of the target architecture, but `f32`'s mantissa is only 23 bits wide)

@SLUCHABLUB
Copy link
Contributor Author

Yes, something like that would be even better. I will look over it.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 4, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 4, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants