Skip to content

Conversation

@HackingRepo
Copy link

@HackingRepo HackingRepo commented Jan 3, 2026

Introduce a new syntax for restricting trait implementations to specific crates:

```rust
trait Test permits mycrate_extra, crate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does the upstream trait declaration knows the name of the downstream crate name provide the impls? any crate can call themselves mycrate_extra, so this does not prevent "malicious impls" mentioned on line 21 at all

@ehuss ehuss added T-lang Relevant to the language team, which will review and decide on the RFC. T-types Relevant to the types team, which will review and decide on the RFC. labels Jan 3, 2026

Accidental or malicious impls: External crates can implement traits in ways that break invariants.

Audit difficulty: It is hard to know which crates are allowed to implement a trait.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is generally very simple to work out how the Orphan Rule applies. The fundamental types work a little different, but there's only a handful of such types.

@kennytm kennytm changed the title Create 0000-trait-permits.md RFC: Trait Implementation Privacy with permits Jan 4, 2026

crate refers to the defining crate.

Other identifiers refer to external crates by name.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a use for "I want this crate and a specific set of dependent crates named here to be the only crates who can implement this trait" restrictions? I can't think of any Rust code I've read/written where anything between "only this crate can implement" or "the whole world can implement" would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-lang Relevant to the language team, which will review and decide on the RFC. T-types Relevant to the types team, which will review and decide on the RFC.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants