< 返回版块

hzqd 发表于 2023-01-10 21:23

我用 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 页