task: fix stacked borrows issue in JoinSet (#5693)

This commit is contained in:
Alice Ryhl
2023-05-15 17:55:52 +02:00
committed by GitHub
parent 70364b7079
commit f6313f4382
+20 -1
View File
@@ -421,7 +421,7 @@ impl<T: 'static> Wake for ListEntry<T> {
// We move ourself to the notified list.
let me = unsafe {
// Safety: We just checked that we are in this particular list.
lock.idle.remove(NonNull::from(&**me)).unwrap()
lock.idle.remove(ListEntry::as_raw(me)).unwrap()
};
lock.notified.push_front(me);
@@ -460,3 +460,22 @@ unsafe impl<T> linked_list::Link for ListEntry<T> {
ListEntry::addr_of_pointers(target)
}
}
#[cfg(test)]
mod tests {
use crate::runtime::Builder;
use crate::task::JoinSet;
// A test that runs under miri.
//
// https://github.com/tokio-rs/tokio/pull/5693
#[test]
fn join_set_test() {
let rt = Builder::new_current_thread().build().unwrap();
let mut set = JoinSet::new();
set.spawn_on(futures::future::ready(()), rt.handle());
rt.block_on(set.join_next()).unwrap().unwrap();
}
}