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

What to do with impl Interface1 as Interface2? #4853

Open
danakj opened this issue Jan 28, 2025 · 1 comment
Open

What to do with impl Interface1 as Interface2? #4853

danakj opened this issue Jan 28, 2025 · 1 comment
Labels
leads question A question for the leads team

Comments

@danakj
Copy link
Contributor

danakj commented Jan 28, 2025

Summary of issue:

Given this code:

interface Eats {}
interface Goat {}

impl Goat as Eats {}

fn F(e: Eats) {}
fn G() { F(Goat); }

The impl Goat as Eats looks a lot like a blanket impl of Eats for Goat types, but it's not. It's an impl on the Goat interface itself.

@zygoloid expressed that maybe this should be a warning. If it's a warning, for many projects it will become an error, essentially banning it from the language. Is this useful to keep? Should it be diagnosed in some way?

Details:

No response

Any other information that you want to share?

No response

@danakj danakj added the leads question A question for the leads team label Jan 28, 2025
@zygoloid
Copy link
Contributor

A potential use case for this kind of impl would be as part of a metaprogramming system to synthesize impls for an interface. Eg:

interface Compare { ... }
impl Compare as Derivable {
  fn Derive(template T:! type) -> Meta.Impl {
    // Generate impl for `Compare` for `T`.
  }
}

class C {
  // Or whatever attribute syntax we use.
  @Derive impl as Compare;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
leads question A question for the leads team
Projects
None yet
Development

No branches or pull requests

2 participants