Skip to content

Fix cast_sign_loss false positive for float to uint casts #15382

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

krikera
Copy link
Contributor

@krikera krikera commented Jul 31, 2025

Fixes #15286

The cast_sign_loss lint was incorrectly triggering on float to unsigned integer casts. Since floats don't have the same sign semantics as signed integers, these casts cannot actually lose sign information.

Changes:

  • Modified should_lint function in cast_sign_loss.rs to exclude float→uint casts
  • Updated test expectations to reflect the new behavior

Testing:

  • All UI tests pass (1650 tests)
  • Verified with cargo test and cargo check
  • Code formatted with cargo dev fmt

changelog: [cast_sign_loss]: Fix false positive for float to unsigned integer casts

@rustbot
Copy link
Collaborator

rustbot commented Jul 31, 2025

r? @samueltardieu

rustbot has assigned @samueltardieu.
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 Jul 31, 2025
Copy link

github-actions bot commented Jul 31, 2025

Lintcheck changes for 834c413

Lint Added Removed Changed
clippy::cast_sign_loss 0 61 2

This comment will be updated if you push new changes

The cast_sign_loss lint was incorrectly triggering on float to unsigned
integer casts, which cannot actually lose sign information since floats
don't have the same sign semantics as signed integers.

This change modifies the should_lint function to exclude float to uint
casts from the cast_sign_loss lint.

changelog: Fix [] false positive for float to unsigned integer casts

fixed tests
@krikera krikera force-pushed the fix-cast-sign-loss-docs branch from a73e5c3 to 834c413 Compare July 31, 2025 14:57
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.

Documentation of cast_sign_loss does not cover floating point
3 participants