rust-lang / rust-lang/rust-clippy
Warn if str.parse if no explicit type specified
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Warn for &str.parse() if the inferred type is i32 without explicit specify.
Lint Name
STR_PARSE_INFER_TO_I32
Category
suspicious
Advantage
Hint developer that the parse actually only process i32, if the value is larger, the code fails.
Drawbacks
None
Example
x.parse().unwrap_or(0)
Could be written as:
x.parse::<i32>().unwrap_or(0)
if "111111111111111111".parse().unwrap_or(0) > 0 {
println!("good");
} else {
println!("bad");
}
if "111111111111111111".parse::<_>().unwrap_or(0) > 0 {
println!("good");
} else {
println!("bad");
}
if "111111111111111111".parse::<i64>().unwrap_or(0) > 0 {
println!("good");
} else {
println!("bad");
}
outputs
bad
bad
good
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 by locating the existing str.parse handling and lint registration in rust-clippy, then inspect how similar suspicious lints express diagnostics and tests. Use the provided i32, inferred, and explicit i64 examples to define the expected warnings and non-warnings; done means the STR_PARSE_INFER_TO_I32 lint is implemented and covered by tests.
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
- 42/100