rust-lang / rust-lang/rust-clippy
lint functions returning only either positive dynamic values or negative constants
Open
Nobody has claimed this yet.
A-lint
E-hard
E-medium
L-style
T-middle
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
These functions should probably return a Result and not represent their error cases by returning negative values.
Example:
fn foo(v: &[&'static str]) -> isize {
if v.iter().any(|s| s.is_empty()) {
return -1;
}
if v.iter().any(|s| s[0] == "_") {
return -2;
}
v.len() as isize
}
There are probably harder cases that can be automatically detected but require some form of dataflow analysis.
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
No file, test, or entry point is named; start by studying the example and defining which functions returning dynamic positive values and negative constants the lint should detect. Done should include a clear scope for harder dataflow cases and tests demonstrating the supported patterns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100