Skip to content

Lint against impl in block expressions when could be outside of block expression #2124

Open
@Havvy

Description

@Havvy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-styleLint: Belongs in the style lint groupL-unnecessaryLint: Warn about unnecessary codeT-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions