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

Support impl Trait in a parameter position #4540

Closed
jfecher opened this issue Mar 12, 2024 · 1 comment · Fixed by #4919
Closed

Support impl Trait in a parameter position #4540

jfecher opened this issue Mar 12, 2024 · 1 comment · Fixed by #4919
Assignees
Labels
enhancement New feature or request

Comments

@jfecher
Copy link
Contributor

jfecher commented Mar 12, 2024

Problem

Noir already has limited support for impl Trait in a return type position. It should also support impl Trait in a parameter position for consistency.

Happy Case

impl Trait in a parameter position is added.

This is just sugar for a trait constraint on a generic parameter:

fn foo(x: impl Bar) {}

// same as
fn foo<T>(x: T) where T: Bar {}

Project Impact

None

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@michaeljklein
Copy link
Contributor

Duplicate of #3771

See there for implementation notes

github-merge-queue bot pushed a commit that referenced this issue Apr 29, 2024
# Description

## Problem\*

Resolves #4540

## Summary\*

In the resolver, when `x: impl Trait` is encountered as a function
parameter,
it is desugared to:
```rust
fn function_name<T_impl_trait>(x: T_impl_trait) where T_impl_trait: Trait
```

## Additional Context

In the current iteration of this PR, `T[func_id]_impl_[trait_name]` is
checked for collisions and
incremented (`T[func_id]_impl_[trait_name]_N`) until there's no
collision.

Note that this PR adds a few ~unrelated cases where `TraitAsType` could
have arguments that were previously skipped:

https://github.com/noir-lang/noir/pull/4919/files#diff-52c7ae61478bab09a4d23320128eead3a88cde6a7be16fb8b070b5512d690bbdR1203

## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants