-
Notifications
You must be signed in to change notification settings - Fork 1.7k
RFC: Trait Implementation Privacy with permits
#3903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| Introduce a new syntax for restricting trait implementations to specific crates: | ||
|
|
||
| ```rust | ||
| trait Test permits mycrate_extra, crate { |
There was a problem hiding this comment.
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
|
|
||
| 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. |
There was a problem hiding this comment.
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.
permits
|
|
||
| crate refers to the defining crate. | ||
|
|
||
| Other identifiers refer to external crates by name. |
There was a problem hiding this comment.
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.
Rendered