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 impl Trait for function parameters #3771

Closed
jfecher opened this issue Dec 11, 2023 · 2 comments
Closed

Implement impl Trait for function parameters #3771

jfecher opened this issue Dec 11, 2023 · 2 comments
Assignees
Labels
compiler frontend `noirc_frontend` crate enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@jfecher
Copy link
Contributor

jfecher commented Dec 11, 2023

Problem

Using traits can be somewhat cumbersome when it requires extra ceremony just for a single parameter:

fn log<T>(x: T) where T: ToString {
    let string = x.to_string();
    println(f"log: {s}");
}

Happy Case

Adopt rust's impl Trait syntax for parameters as well (Noir already mostly supports this for return types):

fn log(x: impl ToString) {
    let string = x.to_string();
    println(f"log: {s}");
}

Alternatives Considered

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@jfecher jfecher added enhancement New feature or request compiler frontend `noirc_frontend` crate P-LOW labels Dec 11, 2023
@kevaundray kevaundray added this to the 1.0 milestone Jan 15, 2024
@jfecher jfecher added the good first issue Good for newcomers label Jan 17, 2024
@jfecher
Copy link
Contributor Author

jfecher commented Jan 17, 2024

Adding "good first issue" here. Whenever we see impl Trait in a parameter position we can desugar it to an extra generic and constraint on the function. E.g:

fn log(x: impl ToString) {
    let string = x.to_string();
    println(f"log: {s}");
}

Would get desugared directly to:

fn log<T>(x: T) where T: ToString {
    let string = x.to_string();
    println(f"log: {s}");
}

This'd likely be done during name resolution when we can cleanly create fresh type variables that are guaranteed not to be in scope elsewhere.

@michaeljklein
Copy link
Contributor

michaeljklein commented Mar 20, 2024

Newer version of this issue that's part of an Epic: #4540

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler frontend `noirc_frontend` crate enhancement New feature or request good first issue Good for newcomers
Projects
Archived in project
Development

No branches or pull requests

4 participants