Lint against impl in block expressions when could be outside of block expression #2124
Labels
A-lint
Area: New lints
E-medium
Call for participation: Medium difficulty level problem and requires some initial experience.
L-style
Lint: Belongs in the style lint group
L-unnecessary
Lint: Warn about unnecessary code
T-middle
Type: Probably requires verifiying types
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.
The text was updated successfully, but these errors were encountered: