diff --git a/src/job.rs b/src/job.rs index f0acd9f..a43d24c 100644 --- a/src/job.rs +++ b/src/job.rs @@ -264,8 +264,7 @@ impl JobQueue { /// Any `Job` pushed onto the queue should alive at least until it gets /// popped. pub unsafe fn push_back(&mut self, job: &Job) { - let next_tail = unsafe { &*(job as *const Job as *const Job) }; - self.0.push_back(NonNull::from(next_tail).cast()); + self.0.push_back(NonNull::from(job).cast()); } pub fn pop_back(&mut self) { @@ -273,11 +272,12 @@ impl JobQueue { } pub fn pop_front(&mut self) -> Option { - let val = self.0.pop_front()?; // SAFETY: - // `Job` is still alive as per contract in `push_back` - let job = unsafe { val.as_ref() }; - job.fut.set(Some(Box::leak(Box::new(Future::default())).into())); + // `Job` is still alive as per contract in `push_back`. + let job = unsafe { self.0.pop_front()?.as_ref() }; + job.fut + .set(Some(Box::leak(Box::new(Future::default())).into())); + Some(job.clone()) } } diff --git a/src/lib.rs b/src/lib.rs index a576c38..823a9ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -330,10 +330,7 @@ impl<'s> Scope<'s> { let time = lock.time; if let Entry::Vacant(e) = lock.shared_jobs.entry(self.heartbeat_id()) { - // SAFETY: - // Any `Job` previously pushed onto the queue will be waited upon - // and will be alive until that point. - if let Some(job) = unsafe { self.job_queue.pop_front() } { + if let Some(job) = self.job_queue.pop_front() { e.insert((time, job)); lock.time += 1; @@ -384,12 +381,7 @@ impl<'s> Scope<'s> { let rb = b(self); if job.is_waiting() { - // SAFETY: - // `job` is alive until the end of this scope and there has been no - // other pop up to this point. - unsafe { - self.job_queue.pop_back(); - } + self.job_queue.pop_back(); // SAFETY: // Since the `job` was popped from the back of the queue, it cannot