Skip to content

RFC: settle rules about visibility of impls #3600

Closed
@nikomatsakis

Description

@nikomatsakis

Right now, I think, an impl of trait T for type X is always visible from within a crate, but to be visible from outside a crate they must be public. I am frankly unsure if these rules are good or bad but I do believe they are to some extent accidental. We should decide when and if impls are visible.

For example, I could imagine any of the following rules:

  • the rule we have now;
  • impls of traits are always visible;
  • impls of traits are subject to the typical visibility rules, meaning that if the impl is public in module A, it can only be used from modules that could import A.

Some related questions:

  • currently coherence is enforced at the crate level. You can implement an impl for trait T and type X if it is T or X is defined in your crate. Module-level visibility has nothing to do with it.
  • if we went with module-level visibility rules, does it interact with coherence at all? I guess it cannot, we still do not want to allow multiple impls of a given trait for a given type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions