-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Make the return type of Fn
trait an associated type
#21019
Make the return type of Fn
trait an associated type
#21019
Conversation
560a3c1
to
6d2dd96
Compare
In terms of the sugar, does this limit us to the possibilities of the
which is a little odd, but perhaps not the end of the world! |
Tidy failure https://travis-ci.org/rust-lang/rust/builds/46746709 |
@alexcrichton that is precisely what the desugaring amounts to in this version. The fact that There is however one thing I wasn't crazy about: sometimes you won't want to constrain the output of the function. In that case, the existing desugaring doesn't give you that option, so you have to opt out of the sugar altogether. For example, the struct Map<A,B,I,F>
where I : Iterator<Item=A>, F : FnMut(A) -> B
{
iter: I,
fn: F
}
impl<A,B,I,F> Iterator<B> for Map<I,F>
where I : Iterator<Item=A>, F : FnMut(A) -> B
{ ... } Under this scheme it could be simplified to: struct Map<I,F>
where I : Iterator, F : FnMut<(I::Item,)>
{
iter: I,
fn: F
}
impl<I,F> Iterator<F::Output> for Map<I,F>
where I : Iterator, F : FnMut<(I::Item,)>
{
} I definitely like having fewer type parameters, but the difference between On the other hand, if one preferred, one could never use the non-sugared form, at the cost of more type parameters: struct Map<B,I,F>
where I : Iterator, F : FnMut(I::Item) -> B
... so in some sense it's no worse than today, just gives you the option to do better. |
6d2dd96
to
b7ebdcd
Compare
b7ebdcd
to
e769d61
Compare
Whoa! That is very interesting about the difference between For now we don't even necessarily have to have all the parameters on |
@alexcrichton yes, we could. |
I've decided to open an RFC for this. Better to err on the side of more RFCs, I figure. |
@alexcrichton in fact we cannot remove the parameters on map today, due to the fact that |
880c831
to
9a7150b
Compare
RFC has landed now. Rebased, testing the build now. I had to add a fix for #21664 (which is now at the front of the PR series) because recent changes exposed that problem when combined with this change. |
ae86004
to
6734e63
Compare
r? @nick29581 (@aturon felt he wasn't familiar enough with the code in question) |
@bors: r+ 6734e6305d8abb9f1d51a92fcda1151dafe0fb7f |
☔ Merge conflict |
all parameter environments are normalized. Correspondingly, stop normalizing predicates we extract out of the environment. Fixes rust-lang#21664.
…involves tweaking things in the compiler that assumed two input types to assume two ouputs; we also have to teach `project.rs` to project `Output` from the unboxed closure and fn traits.
…ted types when constructing the vtable-index. Not good.
all relevant information.
…at least right now).
explicit form `Fn<A,B>` and now should use `Fn(A) -> B` or `Fn<A,Output=B>`, but in some cases we get duplicate error reports. This is mildly annoying and arises because of the main error and another error from the projection. Might be worth squashing those, but seems like a separate problem.
6734e63
to
aaf3df3
Compare
⌛ Testing commit aaf3df3 with merge f7f9c38... |
breaking change |
Fixes #20871
r? @aturon (at least until we decide definitively if this is a good idea)