rust-lang / rust-lang/rust-clippy
Lint against impl in block expressions when could be outside of block expression
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Implementations exist globally no matter where they are defined. It's possible to define items in block expressions, and is done primarily for scoping where the item is accessible.
Since putting the implementation into a block expression does not actually limit scope, it should not be done unless absolutely required. Implementations in block expressions are only absolutely required when one of the item being implemented, the trait being implemented, or a generic bound (including in where clauses) refers to an item defined in the block expression.
One can also argue that if one has to define implementations in the block expression that you're being needlessly complex since you can always move both the implementation and the item it requires out of the block expression and into the containing module (or a submodule), and thus just disallow all implementations in block expressions.
The lint forbidding it because of complexity is easier to implement than the lint forbidding it only in confusing cases.
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 source files or tests are named. Start by locating Clippy's existing lint registration and test patterns for implementation or block-expression lints, then clarify whether the intended rule covers all implementations in blocks or only cases where moving them is possible. Done means the selected cases are diagnosed consistently with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100