From 737e473a795544261b2be2ec1bdb34d47d334ee6 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Fri, 1 Mar 2024 15:01:18 +0900 Subject: [PATCH] Ensure reinitialize() is maintained for new fields --- unified-scheduler-logic/src/lib.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/unified-scheduler-logic/src/lib.rs b/unified-scheduler-logic/src/lib.rs index 82b7bbfe524dda..9010410f47c347 100644 --- a/unified-scheduler-logic/src/lib.rs +++ b/unified-scheduler-logic/src/lib.rs @@ -738,11 +738,23 @@ impl SchedulingStateMachine { pub fn reinitialize(&mut self) { assert!(self.has_no_active_task()); assert_eq!(self.unblocked_task_queue.len(), 0); - self.last_task_index = None; - self.active_task_count.reset_to_zero(); - self.handled_task_count.reset_to_zero(); - self.unblocked_task_count.reset_to_zero(); - self.total_task_count.reset_to_zero(); + // nice trick to ensure all fields are handled here if new one is added. + let Self { + last_task_index, + unblocked_task_queue: _, + active_task_count, + handled_task_count, + unblocked_task_count, + total_task_count, + count_token: _, + usage_queue_token: _, + // don't add ".." here + } = self; + *last_task_index = None; + active_task_count.reset_to_zero(); + handled_task_count.reset_to_zero(); + unblocked_task_count.reset_to_zero(); + total_task_count.reset_to_zero(); } /// Creates a new instance of [`SchedulingStateMachine`] with its `unsafe` fields created as