You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unboxed closures: Type inferencer failed to detect closure argument types #17907
#![feature(unboxed_closures)]#![feature(overloaded_calls)]fnaction<T:Send,F:FnOnce(Sender<T>) -> ()>(sender:Sender<T>,cb:F){cb(sender);}pubfnmain(){let(tx, rx) = channel();// Must be uncommented to work vvvaction(tx,move |:tx /* :Sender<&'static str> */| {
tx.send("zomg")});println!("recv: {}", rx.recv());}
Output:
rustc fnonce.rs
fnonce.rs:13:7: 13:22 error: the type of this value must be known in this context
fnonce.rs:13 tx.send("zomg")
^~~~~~~~~~~~~~~
fnonce.rs:12:3: 12:9 error: type mismatch: the type `closure` implements the trait `core::ops::FnOnce<([type error]),[type error]>`, but the trait `core::ops::FnOnce<(sync::comm::Sender<<generic #9>>),()>` is required (expected struct sync::comm::Sender, found type error)
fnonce.rs:12 action(tx, move |:tx /* :Sender<&'static str> */| {
^~~~~~
fnonce.rs:12:3: 12:9 note: the trait `core::ops::FnOnce` must be implemented because it is required by `action`
fnonce.rs:12 action(tx, move |:tx /* :Sender<&'static str> */| {
^~~~~~
error: aborting due to 2 previous errors
I think that we may be able to make this inference work more uniformly using the new trait infrastructure. In principle, trying to match the Fn vs FnMut etc traits against the closure type ought to inform the type of its arguments. There are some challenges here, though.
Another case, I am unsure if it is related or not, but I had code that was working, wrapped the FnOnce argument w/ Option and the type inferencer could not figure it out.
<anon>:6:32: 6:42 error: the type of this value must be known in this context
<anon>:6 doit(0i, |&: x/*: int*/| { x.to_int(); });
^~~~~~~~~~
<anon>:6:5: 6:9 error: type mismatch: the type `closure` implements the trait `core::ops::Fn<([type error]),[type error]>`, but the trait `core::ops::Fn<(int),()>` is required (expected int, found type error)
<anon>:6 doit(0i, |&: x/*: int*/| { x.to_int(); });
^~~~
<anon>:6:5: 6:9 note: the trait `core::ops::Fn` must be implemented because it is required by `doit`
<anon>:6 doit(0i, |&: x/*: int*/| { x.to_int(); });
^~~~
error: aborting due to 2 previous errors
Seems related to the method syntax (and thus maybe AutoDeref).
Activity
nikomatsakis commentedon Oct 10, 2014
cc me.
I think that we may be able to make this inference work more uniformly using the new trait infrastructure. In principle, trying to match the
FnvsFnMutetc traits against the closure type ought to inform the type of its arguments. There are some challenges here, though.nikomatsakis commentedon Oct 10, 2014
cc @pcwalton
jroesch commentedon Oct 10, 2014
I was recently running into a similar issue and chalked it up to what I was working on. cc me.
carllerche commentedon Oct 14, 2014
Another case, I am unsure if it is related or not, but I had code that was working, wrapped the FnOnce argument w/ Option and the type inferencer could not figure it out.
TeXitoi commentedon Oct 22, 2014
An almost minimal test:
error:
Seems related to the method syntax (and thus maybe AutoDeref).
nikomatsakis commentedon Nov 18, 2014
Tackling this next.
TeXitoi commentedon Nov 18, 2014
You can also see tests in https://github.com/TeXitoi/rust-mdo/tree/unboxed-closure
nikomatsakis commentedon Dec 15, 2014
I think this was fixed by PR #19089, at least for the most part. Open if you disagree.
Auto merge of rust-lang#17907 - ChayimFriedman2:no-once_cell, r=Veykril
fix: `double_comparisons` suggestion dropping required parentheses (#…