Skip to content

Implement unnecessary bitmask on cast lint#17188

Open
Francisco-Andre-Martins wants to merge 1 commit into
rust-lang:masterfrom
Francisco-Andre-Martins:feat#16125-needless-bit-mask
Open

Implement unnecessary bitmask on cast lint#17188
Francisco-Andre-Martins wants to merge 1 commit into
rust-lang:masterfrom
Francisco-Andre-Martins:feat#16125-needless-bit-mask

Conversation

@Francisco-Andre-Martins

@Francisco-Andre-Martins Francisco-Andre-Martins commented Jun 8, 2026

Copy link
Copy Markdown

When downcasting from a large integer type (like u_64) to a smaller type (like u_8), the rust compiler
automatically truncates the integer adequately.
Still, some people do decide to perform a bitwise
and before casting, essentially truncating
the input before it is cast.

Closes #16125

changelog: Implement needless bitmask lint

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 8, 2026
@rustbot

rustbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dswij (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@rustbot

This comment has been minimized.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Lintcheck changes for 5a63501

Lint Added Removed Changed
clippy::needless_bitmask_on_cast 15 0 0

This comment will be updated if you push new changes

@Francisco-Andre-Martins Francisco-Andre-Martins force-pushed the feat#16125-needless-bit-mask branch from d589ee9 to 9afc7cd Compare June 8, 2026 18:16
@rustbot

This comment has been minimized.

When downcasting from a large integer type (like u_64)
to a smaller type (like u_8), the rust compiler
automatically truncates the integer adequately.
Still, some people do decide to perform a bitwise
and before casting, essentially truncating
the input before it is cast.

Closes rust-lang#16125
Co-authored-by: Guilherme Silva <guilherme.d.silva@tecnico.ulisboa.pt>
@Francisco-Andre-Martins Francisco-Andre-Martins force-pushed the feat#16125-needless-bit-mask branch from 9afc7cd to 5a63501 Compare June 8, 2026 18:38
@rustbot

rustbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP 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.

Needless bit mask when casting from a larger integer to a smaller integer

3 participants