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

Add FnOnce trait, and provide impl for Function type #494

Merged
merged 14 commits into from
Jun 9, 2020

Conversation

Aaron1011
Copy link
Member

@Aaron1011 Aaron1011 commented Jun 5, 2020

Works towards #363

I've followed the approach taken by rustc, where FnOnce has single
generic argument: the tupled function parameters
(e.g. fn(u8, bool): FnOnce<(u8, bool)>).

I also extended the grammar to allow functions to take more than one
argument.

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like #475, this doesn't handle Output? I'm mostly okay with waiting until later to add FnMut and FnOnce, but I feel like it would be simple enough to add here.

@jackh726
Copy link
Member

jackh726 commented Jun 6, 2020

Btw I do have this and the output type implemented locally. But it's based on my closures branch, so I would have to split it out.

@Aaron1011 Aaron1011 force-pushed the feature/fn-once branch 2 times, most recently from fa10f9b to 8ba097c Compare June 7, 2020 07:35
Aaron1011 added 4 commits June 7, 2020 17:14
Works towards rust-lang#363

I've followed the approach taken by rustc, where `FnOnce` has single
generic argument: the tupled function parameters
(e.g. `fn(u8, bool): FnOnce<(u8, bool)>`).

I also extended the grammar to allow functions to take more than one
argument.

I've left `Fn` and `FnMut` for a separate PR - without a representation
of closures in Chalk, they are not very useful.
@Aaron1011
Copy link
Member Author

@jackh726: I've added FnMut and Fn, as well as handling for FnOnce::Output

chalk-solve/src/clauses/builtin_traits.rs Outdated Show resolved Hide resolved
chalk-solve/src/clauses/builtin_traits.rs Outdated Show resolved Hide resolved
chalk-solve/src/clauses/builtin_traits/fn_.rs Outdated Show resolved Hide resolved
chalk-solve/src/clauses/builtin_traits/fn_.rs Outdated Show resolved Hide resolved
chalk-solve/src/clauses/builtin_traits/fn_.rs Outdated Show resolved Hide resolved
chalk-solve/src/clauses/builtin_traits/fn_.rs Outdated Show resolved Hide resolved
chalk-solve/src/clauses/builtin_traits/fn_.rs Outdated Show resolved Hide resolved
tests/test/functions.rs Show resolved Hide resolved
tests/test/functions.rs Show resolved Hide resolved
book/src/clauses/well_known_traits.md Outdated Show resolved Hide resolved
Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple small things. And I want @nikomatsakis to take a quick look. But looks pretty good to me.

chalk-solve/src/clauses/builtin_traits.rs Outdated Show resolved Hide resolved
chalk-solve/src/clauses/builtin_traits/fn_family.rs Outdated Show resolved Hide resolved
chalk-solve/src/clauses/builtin_traits/fn_family.rs Outdated Show resolved Hide resolved
chalk-solve/src/clauses/builtin_traits/fn_family.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! One comment.

chalk-solve/src/clauses/builtin_traits/fn_family.rs Outdated Show resolved Hide resolved
@Aaron1011
Copy link
Member Author

@nikomatsakis: I've added a Flounder error when we encounter an inference variable or type alias.

@nikomatsakis nikomatsakis merged commit 13aa9d3 into rust-lang:master Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants