我用 Nightly Rust 尝试如下代码:
#![feature(impl_trait_in_fn_trait_return)]
fn curry<P1, P2, R>(f: impl FnOnce(P1, P2) -> R) -> impl FnOnce(P1) -> impl FnOnce(P2) -> R {
|p1| |p2| f(p1, p2)
}
编译错误:
error: concrete type differs from previous defining opaque type use
--> src/lib.rs:4:10
|
4 | |p1| |p2| f(p1, p2)
| ^^^^^^^^^^^^^^ expected `impl FnOnce(P2) -> R`, got `[closure@src/lib.rs:4:10: 4:14]`
|
note: previous use here
--> src/lib.rs:4:5
|
4 | |p1| |p2| f(p1, p2)
| ^^^^^^^^^^^^^^^^^^^
error[E0720]: cannot resolve opaque type
--> src/lib.rs:3:72
|
3 | fn curry<P1, P2, R>(f: impl FnOnce(P1, P2) -> R) -> impl FnOnce(P1) -> impl FnOnce(P2) -> R {
| ^^^^^^^^^^^^^^^^^^^^ cannot resolve opaque type
For more information about this error, try `rustc --explain E0720`.
error: could not compile `playground` due to 2 previous errors
当我第一次看到这个功能时,我以为它就是为了干这个。
但是这个编译错误让我不知道它到底是做什么用的了,故来此请教诸位。
1
共 2 条评论, 1 页
评论区
写评论看起来还没做好
Tracking Issue for impl Trait as output type of Fn traits in function return position
这个跟你的一样 Multiple nested impl Trait in trait method does not work
Fn trait doesn't allow impl returns (impl Fn() -> impl Trait), which is inconsistent with all other traits
https://users.rust-lang.org/t/closure-as-argument-parameterization-with-impl-trait/67297