rust-lang / rust-lang/rust-clippy
Lint suggesting use of TryFrom for checked integer conversion
Open
Nobody has claimed this yet.
A-lint
L-complexity
L-style
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Checked integer conversion code has historically looked something like this:
if foo <= i32::max_value() as usize {
thing_a
} else {
thing_b
}
But now that TryFrom is stable, it can be done in a more foolproof way like this:
match i32::try_from(foo) {
Ok(foo) => thing_a,
Err(_) => thing_b,
}
It'd be cool if there was a lint guiding users to migrate their code.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the checked integer conversion examples in the issue and inspect Clippy's existing lint implementations and tests to find the appropriate entry point. Define the supported conversion patterns and add coverage showing that the lint recommends TryFrom while preserving the Ok and Err behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100