diff --git a/library/std/src/thread/spawnhook.rs b/library/std/src/thread/spawnhook.rs index bc239440c18a..a3fcc078867a 100644 --- a/library/std/src/thread/spawnhook.rs +++ b/library/std/src/thread/spawnhook.rs @@ -114,12 +114,9 @@ pub(super) fn run_spawn_hooks(thread: &Thread) -> ChildSpawnHooks { snapshot }); // Iterate over the hooks, run them, and collect the results in a vector. - let mut next: &Option> = &hooks.first; - let mut to_run = Vec::new(); - while let Some(hook) = next { - to_run.push((hook.hook)(thread)); - next = &hook.next; - } + let to_run: Vec<_> = std::iter::successors(hooks.first.as_deref(), |hook| hook.next.as_deref()) + .map(|hook| (hook.hook)(thread)) + .collect(); // Pass on the snapshot of the hooks and the results to the new thread, // which will then run SpawnHookResults::run(). ChildSpawnHooks { hooks, to_run }