Skip to content
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

Limit trait implementations to traits you own or types you own #15

Open
sezna opened this issue Mar 16, 2021 · 2 comments
Open

Limit trait implementations to traits you own or types you own #15

sezna opened this issue Mar 16, 2021 · 2 comments
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged language feature Core language features visible to end users P: medium

Comments

@sezna
Copy link
Contributor

sezna commented Mar 16, 2021

I am not implementing this in the MVP, but to prevent random pollution of the method namespace of types when you import libraries, Rust prevents you from implementing a trait for a type when you don't own either the trait or the type. We should do this eventually.

@adlerjohn adlerjohn added the compiler General compiler. Should eventually become more specific as the issue is triaged label May 12, 2021
@mohammadfawaz mohammadfawaz added language feature Core language features visible to end users compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Jul 11, 2022
@mohammadfawaz
Copy link
Contributor

@sezna can you elaborate a bit on what exactly this means?

@sezna
Copy link
Contributor Author

sezna commented Jul 12, 2022

Here is a reproduction in Rust..

It is a safety measure to prevent dependencies from overriding traits on imported structs, which would be a big vulnerability. E.g.:

  1. You import serde_json
  2. You import foo
  3. foo overwrites impl Serialize for String with its own implementation which also copies the contents of your home directory and sends them to a super secret black hat hacking organization

in the above scenario, you, the user, had no idea that Serialize was being overridden. That's why crates must introduce their own new wrapper traits, so additional functionality built on top of existing traits can remain opt-in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged language feature Core language features visible to end users P: medium
Projects
Status: Todo
Development

No branches or pull requests

3 participants