From ec1f52e1d3ab12308243758d297dedbccac1e262 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 28 Jun 2023 12:23:08 -0700 Subject: [PATCH] io: fix safety of `LinkedList` drain_filter API (#5832) The `drain_filter` method on the internal `LinkedList` type passes a `&mut` reference to the node type. However, the `LinkedList` is intended to be used with nodes that are shared in other ways. For example `task::Header` is accessible concurrently from multiple threads. Currently, the only usage of `drain_filter` is in a case where `&mut` access is safe, so this change is to help prevent future bugs and tighten up the safety of internal utilities. --- tokio/src/util/linked_list.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tokio/src/util/linked_list.rs b/tokio/src/util/linked_list.rs index 412ffc089..1f9bdf4b8 100644 --- a/tokio/src/util/linked_list.rs +++ b/tokio/src/util/linked_list.rs @@ -307,7 +307,7 @@ cfg_io_driver_impl! { impl LinkedList { pub(crate) fn drain_filter(&mut self, filter: F) -> DrainFilter<'_, T, F> where - F: FnMut(&mut T::Target) -> bool, + F: FnMut(&T::Target) -> bool, { let curr = self.head; DrainFilter { @@ -321,7 +321,7 @@ cfg_io_driver_impl! { impl<'a, T, F> Iterator for DrainFilter<'a, T, F> where T: Link, - F: FnMut(&mut T::Target) -> bool, + F: FnMut(&T::Target) -> bool, { type Item = T::Handle;