From f6313f4382145a365dfd94a352a53f805a2f14ef Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Mon, 15 May 2023 17:55:52 +0200 Subject: [PATCH] task: fix stacked borrows issue in `JoinSet` (#5693) --- tokio/src/util/idle_notified_set.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tokio/src/util/idle_notified_set.rs b/tokio/src/util/idle_notified_set.rs index ce8ff9e9a..85a5292bf 100644 --- a/tokio/src/util/idle_notified_set.rs +++ b/tokio/src/util/idle_notified_set.rs @@ -421,7 +421,7 @@ impl Wake for ListEntry { // 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 linked_list::Link for ListEntry { 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(); + } +}