use*_*932 0 type-inference compiler-errors rust rust-tokio
例如:
use futures::future::Future;
fn main() {
let (stop_tokio, time_to_stop) = tokio::sync::oneshot::channel::<()>();
let handler = std::thread::spawn(|| {
tokio::run(
time_to_stop, // .map_err(|_| ())
);
});
handler.join().expect("join failed");
}
Run Code Online (Sandbox Code Playgroud)
编译器显示错误:
use futures::future::Future;
fn main() {
let (stop_tokio, time_to_stop) = tokio::sync::oneshot::channel::<()>();
let handler = std::thread::spawn(|| {
tokio::run(
time_to_stop, // .map_err(|_| ())
);
});
handler.join().expect("join failed");
}
Run Code Online (Sandbox Code Playgroud)
该代码要求使用()
,RecvError
但改为,但是编译器打印相反的代码。
这是编译器中的错误,还是我错过了什么?
On the surface, tokio::run
expects a Future
with associated Error
type ()
, but the actual Future
impl of Receiver
has associated Error
type RecvError
.
However, Rust's type inference works in both directions, and the expected and actual types can sometimes be seen the other way around. Usually the wording of the message fits your expectations, but there are situations like this one where it feels backwards. Of course, it isn't too difficult to work out what is going on and know where the type mis-match is happening even if it isn't reported in the best way.
在一般情况下,将人为解释为“实际”类型和“预期”类型的代码整理起来可能不是一个容易解决的问题,但是我同意,此错误消息会在您提供的代码中造成混淆。
我找不到与此相关的问题,但是我敢肯定,我之前已经看过几次。如果以前已经报告过,那么再次报告不会有太大危害,所以我就这样做。
归档时间: |
|
查看次数: |
70 次 |
最近记录: |