Skip to content

Conversation

@ab22593k
Copy link

@ab22593k ab22593k commented Dec 18, 2025

Introduce a new restriction lint to identify casts between pointer-sized integer types (usize, isize) and fixed-size integer types.

Encourage the use of TryFrom or TryInto over direct as casts to make potential platform-specific truncation or zero-extension explicit and handled.

Also Provide machine-applicable suggestions to replace risky casts with fallible conversions while excluding constant contexts where such traits are not yet stable.

Closes: #9231

changelog: add cast_ptr_sized_int lint

Introduce a new restriction lint to identify casts between pointer-sized
integer types (`usize`, `isize`) and fixed-size integer types.

Encourage the use of `TryFrom` or `TryInto` over direct `as` casts to make
potential platform-specific truncation or zero-extension explicit and handled.

Also Provide machine-applicable suggestions to replace risky casts with fallible
conversions while excluding constant contexts where such traits are not yet stable.

Closes: rust-lang#9231
@rustbot rustbot added needs-fcp S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Dec 18, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 18, 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
Copy link
Collaborator

rustbot commented Dec 18, 2025

⚠️ 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.

@github-actions
Copy link

Lintcheck changes for 014b80c

Lint Added Removed Changed
clippy::cast_ptr_sized_int 2233 0 0

This comment will be updated if you push new changes

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

Labels

needs-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.

Have a lint against usize-to-u64 casts (or, against *all* integer casts)

3 participants