Skip to content

Commit

Permalink
runtime: mem::forget instead of keeping track of dropped state (#2451)
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog authored Apr 29, 2020
1 parent 0f4287a commit 2c53beb
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions tokio/src/runtime/task/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,15 @@ where
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
struct Guard<'a, T: Future, S: Schedule> {
core: &'a Core<T, S>,
polled: bool,
}

impl<T: Future, S: Schedule> Drop for Guard<'_, T, S> {
fn drop(&mut self) {
if !self.polled {
self.core.drop_future_or_output();
}
self.core.drop_future_or_output();
}
}

let mut guard = Guard {
core: self.core(),
polled: false,
};
let guard = Guard { core: self.core() };

// If the task is cancelled, avoid polling it, instead signalling it
// is complete.
Expand All @@ -113,7 +107,7 @@ where
let res = guard.core.poll(self.header());

// prevent the guard from dropping the future
guard.polled = true;
mem::forget(guard);

res.map(Ok)
}
Expand Down

0 comments on commit 2c53beb

Please sign in to comment.