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
Can't use impl Fn to return a closure that returns another closure #62223
While trying to write some currying code using stable (1.35.0), writing a fn that returns impl Fn(T1) -> impl Fn(T2) -> T3 results in a compile error. E.g.
I'm affected by this as well. The function is a combinator that returns a closure returning a Future, so I need the closure to return an impl Future. I worked around with a Box but it's a bit annoying to have to pay for a Box price when it's actually not really required.
EDIT: It looks like it's possible to avoid the Box in nightly, but the pattern can become cumbersome very quickly for complicated types (e.g. impl Foo<T> with constraints on T. The constraints will need to be copy pasted, possibly multiple times over if you have "impl nesting", e.g. one layer for an Fn() and another for a impl Future returned by the Fn()) https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d092d001154d56789a9ba77155401885
Activity
Centril commentedon Jun 29, 2019
This is currently by design but it is a restriction we could sensibly lift imo.
dcormier commentedon Jul 22, 2021
I'm being bit by this as well. It would be nice to see this changed.
douglas-raillard-arm commentedon Aug 9, 2022
I'm affected by this as well. The function is a combinator that returns a closure returning a Future, so I need the closure to return an
impl Future. I worked around with a Box but it's a bit annoying to have to pay for a Box price when it's actually not really required.EDIT: It looks like it's possible to avoid the Box in nightly, but the pattern can become cumbersome very quickly for complicated types (e.g.
impl Foo<T>with constraints on T. The constraints will need to be copy pasted, possibly multiple times over if you have "impl nesting", e.g. one layer for an Fn() and another for a impl Future returned by the Fn())https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d092d001154d56789a9ba77155401885