rust-lang / rust-lang/rust-clippy
Detect identical functions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Writing the same function or method twice is often a sign that some refactoring is in order.
I'd like to suggest a lint which tries to detect functions or methods that are functionally identical and suggests to merge them if possible. I know this is non-trivial, computationally intensive, and probably not possible to do across crate boundaries. The primary challenge will be to find a way to compare function bodies without too many false negatives.
Comparing the MIR representations (or their hashes) of functions and methods might be a good start as MIR rewrites bindings and control structures in an appropriate way for our purposes (I read up on and hope I'm understanding it correctly); but it is probably limited in its usefulness without knowing that certain equivalent structures will be represented the same. (Also, this actively depends on the development of MIR.)
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
The issue names no files, tests, or entry points. Start by investigating Clippy's existing lint architecture and whether MIR representations or hashes can be compared reliably; done would mean detecting functionally identical functions or methods while avoiding excessive false negatives and reporting when they can be merged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100