Skip to content

Commit 7bc457d

Browse files
Update library/std/src/thread/spawnhook.rs
Co-authored-by: waffle <[email protected]>
1 parent 6a57559 commit 7bc457d

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

library/std/src/thread/spawnhook.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,9 @@ pub(super) fn run_spawn_hooks(thread: &Thread) -> ChildSpawnHooks {
114114
snapshot
115115
});
116116
// Iterate over the hooks, run them, and collect the results in a vector.
117-
let mut next: &Option<Arc<SpawnHook>> = &hooks.first;
118-
let mut to_run = Vec::new();
119-
while let Some(hook) = next {
120-
to_run.push((hook.hook)(thread));
121-
next = &hook.next;
122-
}
117+
let to_run: Vec<_> = std::iter::successors(hooks.first.as_deref(), |hook| hook.next.as_deref())
118+
.map(|hook| (hook.hook)(thread))
119+
.collect();
123120
// Pass on the snapshot of the hooks and the results to the new thread,
124121
// which will then run SpawnHookResults::run().
125122
ChildSpawnHooks { hooks, to_run }

0 commit comments

Comments
 (0)