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

Implement support for capital Self in traits and impl blocks #803

Closed
cburgdorf opened this issue Oct 27, 2022 · 1 comment
Closed

Implement support for capital Self in traits and impl blocks #803

cburgdorf opened this issue Oct 27, 2022 · 1 comment
Labels
comp: analyzer Everything that involves the analyzer pass comp: lowering Everything that involves the lowering pass comp: parser prio: P3 important type: feature type: lang-spec type: syntax

Comments

@cburgdorf
Copy link
Collaborator

What is wrong?

We currently do not support Self in traits and impl blocks (See Rust docs).
Implementing support for Self would give us an easy way to unlock certain functionality even before traits are allowed to be fully generic (which is currently still blocked until we get rid of Location in the analyzer).

E.g. here is how min() / max() functions could be supported.

trait Min {
  fn min() -> Self
}

trait Max {
  fn max() -> Self
}

impl Min for i8 {

  fn min() -> i8 {
    return -128
  }
}

impl Max for i8 {

  fn max() -> i8 {
    return 127
  }
}

// Then somewhere else
let x: i8 = i8::min()
let y: i8 = i8::max()

How can it be fixed

  • Add support for Self in parser
  • Add support for Self in analyzer
  • Lower Self to actual type
  • Add tests
@cburgdorf cburgdorf added comp: parser prio: P3 important type: syntax type: feature type: lang-spec comp: analyzer Everything that involves the analyzer pass comp: lowering Everything that involves the lowering pass labels Oct 27, 2022
@cburgdorf
Copy link
Collaborator Author

This landed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: analyzer Everything that involves the analyzer pass comp: lowering Everything that involves the lowering pass comp: parser prio: P3 important type: feature type: lang-spec type: syntax
Projects
None yet
Development

No branches or pull requests

1 participant