Fix wrong calculation of task ID

Pin implements Deref too, so by dereferencing only once we get a `&Box` reference. Since Box also implements Future, the type of `future_ref` was still correct. To avoid this error in the future, we added an assertion to catch duplicate task IDson `pending_tasks.insert()`.
This commit is contained in:
Philipp Oppermann
2020-02-28 19:08:31 +01:00
parent 786a7a6922
commit ea83d905fe

View File

@@ -58,7 +58,9 @@ impl Executor {
Poll::Pending => {
// add task to pending_tasks list and wait for wakeup
let task_id = Self::task_id(&task);
self.pending_tasks.insert(task_id, task);
if self.pending_tasks.insert(task_id, task).is_some() {
panic!("Task with same ID already in pending_tasks queue");
}
}
}
}
@@ -75,7 +77,7 @@ impl Executor {
}
fn task_id(task: &Task) -> TaskId {
let future_ref: &dyn Future<Output = ()> = &*task;
let future_ref: &dyn Future<Output = ()> = &**task;
future_ref as *const _ as *const () as usize
}