diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index c1d82e18a..6d2c1c18a 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs @@ -203,7 +203,7 @@ impl AvailableTask { fn initialize_impl(self, future: impl FnOnce() -> F) -> SpawnToken { unsafe { self.task.raw.poll_fn.set(Some(TaskStorage::::poll)); - self.task.future.write(future()); + self.task.future.write_in_place(future); let task = TaskRef::new(self.task); diff --git a/embassy-executor/src/raw/util.rs b/embassy-executor/src/raw/util.rs index e2e8f4df8..c46085e45 100644 --- a/embassy-executor/src/raw/util.rs +++ b/embassy-executor/src/raw/util.rs @@ -17,8 +17,9 @@ impl UninitCell { &mut *self.as_mut_ptr() } - pub unsafe fn write(&self, val: T) { - ptr::write(self.as_mut_ptr(), val) + #[inline(never)] + pub unsafe fn write_in_place(&self, func: impl FnOnce() -> T) { + ptr::write(self.as_mut_ptr(), func()) } pub unsafe fn drop_in_place(&self) {