rust-lang / rust-lang/rust-clippy
Restriction lint for unsealed traits
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
A pattern in Rust is "sealing" traits: making them unimplementable to other users. It's typically done by doing something like:
pub trait PublicTrait: private::Sealed {
// items
}
mod private {
pub trait Sealed {} // empty
}
This allows one to declare that a trait is only used with internal types and should not be implemented by external users.
This has some benefits for keeping semver compatability. Codebases (like ICU4X) may wish to make this the default, just like you can already opt in to clippy::exhaustive_structs and clippy::exhaustive_enums to avoid committing to too much semver wise with public structs/enums. In a codebase with this lint enabled, every public non-sealed trait would have an allow ideally with justification.
The idea would be a lint clippy::unsealed_trait, which lints on traits which are:
- Public
- Reachable
- Do not depend (transitively) on any trait named
Sealed(we could also ignore the naming) that are not reachable from other crates - (perhaps) do not have a blanket impl for
T
Transitivity might be tricky to do in a performant way.
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
Start by comparing the proposed lint with the existing clippy::exhaustive_structs and clippy::exhaustive_enums behavior. Work through the stated criteria for public, reachable traits and transitive dependence on an inaccessible Sealed trait, including the possible blanket-impl exception. Done means the lint design and its handling of these cases are settled and implementable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100