rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

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

Open SLUCHABLUB opened this issue 6 months ago • 15 comments

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.

SLUCHABLUB avatar Jun 04 '25 09:06 SLUCHABLUB

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 avatar Jun 04 '25 09:06 rustbot

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)

samueltardieu avatar Jun 04 '25 09:06 samueltardieu

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

@rustbot author

SLUCHABLUB avatar Jun 04 '25 10:06 SLUCHABLUB

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

rustbot avatar Jun 04 '25 10:06 rustbot

Friendly ping from triage: @SLUCHABLUB do you still plan to work on this?

ada4a avatar Oct 11 '25 16:10 ada4a

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

rustbot avatar Oct 12 '25 14:10 rustbot

Lintcheck changes for ff77a3e41197e9ab3fdf1bcb01b049e1e80032b4

Lint Added Removed Changed
clippy::cast_precision_loss 0 0 187

This comment will be updated if you push new changes

github-actions[bot] avatar Oct 12 '25 14:10 github-actions[bot]

Yes, sorry.

@rustbot ready

SLUCHABLUB avatar Oct 12 '25 14:10 SLUCHABLUB

No need to apologize! I try to phrase these in a way that doesn't come off as indicting, but I don't always succeed..

ada4a avatar Oct 12 '25 14:10 ada4a

:umbrella: The latest upstream changes (possibly 92b4b68683249c781c3acad742fc6e57c4140ad9) made this pull request unmergeable. Please resolve the merge conflicts.

rustbot avatar Nov 28 '25 19:11 rustbot

This looks good, just needs a rebase.

@rustbot author

llogiq avatar Nov 30 '25 08:11 llogiq

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

rustbot avatar Dec 05 '25 13:12 rustbot

It seems that the 32-bit tests are failing. Is there a way for me to run (& bless) them on my 64 bit machine?

SLUCHABLUB avatar Dec 05 '25 17:12 SLUCHABLUB

Yes, you could cross compile to x86. But I don't think we actually need to incur that complexity here.

llogiq avatar Dec 05 '25 18:12 llogiq

I think the 32-bit tests should pass now.

@rustbot ready

SLUCHABLUB avatar Dec 06 '25 11:12 SLUCHABLUB