Skip to content

Commit f1923a2

Browse files
committed
remove unneeded lifetimes from drop guards
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
1 parent ff25ad2 commit f1923a2

File tree

4 files changed

+25
-37
lines changed

4 files changed

+25
-37
lines changed

tokio-executor/src/global.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::{Enter, Executor, SpawnError};
33
use futures::{future, Future};
44

55
use std::cell::Cell;
6-
use std::marker::PhantomData;
76

87
/// Executes futures on the default executor for the current execution context.
98
///
@@ -23,8 +22,8 @@ pub struct DefaultExecutor {
2322
/// Ensures that the executor is removed from the thread-local context
2423
/// when leaving the scope. This handles cases that involve panicking.
2524
#[derive(Debug)]
26-
pub struct DefaultGuard<'a> {
27-
_lifetime: PhantomData<&'a ()>,
25+
pub struct DefaultGuard {
26+
_p: (),
2827
}
2928

3029
impl DefaultExecutor {
@@ -183,6 +182,11 @@ where
183182
T: Executor,
184183
F: FnOnce(&mut Enter) -> R,
185184
{
185+
unsafe fn hide_lt<'a>(p: *mut (dyn Executor + 'a)) -> *mut (dyn Executor + 'static) {
186+
use std::mem;
187+
mem::transmute(p)
188+
}
189+
186190
EXECUTOR.with(|cell| {
187191
match cell.get() {
188192
State::Ready(_) | State::Active => {
@@ -224,7 +228,7 @@ where
224228
/// # Panics
225229
///
226230
/// This function panics if there already is a default executor set.
227-
pub fn set_default<'a, T>(executor: T) -> DefaultGuard<'a>
231+
pub fn set_default<T>(executor: T) -> DefaultGuard
228232
where
229233
T: Executor + 'static,
230234
{
@@ -244,17 +248,10 @@ where
244248
cell.set(State::Ready(Box::into_raw(executor)));
245249
});
246250

247-
DefaultGuard {
248-
_lifetime: PhantomData,
249-
}
250-
}
251-
252-
unsafe fn hide_lt<'a>(p: *mut (dyn Executor + 'a)) -> *mut (dyn Executor + 'static) {
253-
use std::mem;
254-
mem::transmute(p)
251+
DefaultGuard { _p: () }
255252
}
256253

257-
impl<'a> Drop for DefaultGuard<'a> {
254+
impl Drop for DefaultGuard {
258255
fn drop(&mut self) {
259256
let _ = EXECUTOR.try_with(|cell| {
260257
if let State::Ready(prev) = cell.replace(State::Empty) {

tokio-reactor/src/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ use tokio_sync::task::AtomicTask;
6868
use std::cell::RefCell;
6969
use std::error::Error;
7070
use std::io;
71-
use std::marker::PhantomData;
7271
use std::mem;
7372
#[cfg(all(unix, not(target_os = "fuchsia")))]
7473
use std::os::unix::io::{AsRawFd, RawFd};
@@ -137,8 +136,8 @@ pub type SetDefaultError = SetFallbackError;
137136
/// Ensure that the default reactor is removed from the thread-local context
138137
/// when leaving the scope. This handles cases that involve panicking.
139138
#[derive(Debug)]
140-
pub struct DefaultGuard<'a> {
141-
_lifetime: PhantomData<&'a ()>,
139+
pub struct DefaultGuard {
140+
_p: (),
142141
}
143142

144143
#[test]
@@ -217,7 +216,7 @@ where
217216
/// # Panics
218217
///
219218
/// This function panics if there already is a default reactor set.
220-
pub fn set_default(handle: &Handle) -> DefaultGuard<'_> {
219+
pub fn set_default(handle: &Handle) -> DefaultGuard {
221220
CURRENT_REACTOR.with(|current| {
222221
let mut current = current.borrow_mut();
223222

@@ -236,9 +235,7 @@ pub fn set_default(handle: &Handle) -> DefaultGuard<'_> {
236235

237236
*current = Some(handle.clone());
238237
});
239-
DefaultGuard {
240-
_lifetime: PhantomData,
241-
}
238+
DefaultGuard { _p: () }
242239
}
243240

244241
impl Reactor {
@@ -746,7 +743,7 @@ impl Direction {
746743
}
747744
}
748745

749-
impl<'a> Drop for DefaultGuard<'a> {
746+
impl Drop for DefaultGuard {
750747
fn drop(&mut self) {
751748
let _ = CURRENT_REACTOR.try_with(|current| {
752749
let mut current = current.borrow_mut();

tokio-timer/src/clock/clock.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use tokio_executor::Enter;
55

66
use std::cell::RefCell;
77
use std::fmt;
8-
use std::marker::PhantomData;
98
use std::sync::Arc;
109
use std::time::Instant;
1110

@@ -23,8 +22,8 @@ pub struct Clock {
2322

2423
/// A guard that resets the current `Clock` to `None` when dropped.
2524
#[derive(Debug)]
26-
pub struct DefaultGuard<'a> {
27-
_lifetime: PhantomData<&'a ()>,
25+
pub struct DefaultGuard {
26+
_p: (),
2827
}
2928

3029
thread_local! {
@@ -131,7 +130,7 @@ where
131130
/// # Panics
132131
///
133132
/// This function panics if there already is a default clock set.
134-
pub fn set_default(clock: &Clock) -> DefaultGuard<'_> {
133+
pub fn set_default(clock: &Clock) -> DefaultGuard {
135134
CLOCK.with(|cell| {
136135
assert!(
137136
cell.borrow().is_none(),
@@ -140,13 +139,11 @@ pub fn set_default(clock: &Clock) -> DefaultGuard<'_> {
140139

141140
*cell.borrow_mut() = Some(clock.clone());
142141

143-
DefaultGuard {
144-
_lifetime: PhantomData,
145-
}
142+
DefaultGuard { _p: () }
146143
})
147144
}
148145

149-
impl<'a> Drop for DefaultGuard<'a> {
146+
impl Drop for DefaultGuard {
150147
fn drop(&mut self) {
151148
let _ = CLOCK.try_with(|cell| cell.borrow_mut().take());
152149
}

tokio-timer/src/timer/handle.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use tokio_executor::Enter;
55

66
use std::cell::RefCell;
77
use std::fmt;
8-
use std::marker::PhantomData;
98
use std::sync::{Arc, Weak};
109
use std::time::{Duration, Instant};
1110

@@ -47,8 +46,8 @@ pub(crate) struct HandlePriv {
4746

4847
/// A guard that resets the current timer to `None` when dropped.
4948
#[derive(Debug)]
50-
pub struct DefaultGuard<'a> {
51-
_lifetime: PhantomData<&'a ()>,
49+
pub struct DefaultGuard {
50+
_p: (),
5251
}
5352

5453
thread_local! {
@@ -80,7 +79,7 @@ where
8079
/// # Panics
8180
///
8281
/// This function panics if there already is a default timer set.
83-
pub fn set_default(handle: &Handle) -> DefaultGuard<'_> {
82+
pub fn set_default(handle: &Handle) -> DefaultGuard {
8483
CURRENT_TIMER.with(|current| {
8584
let mut current = current.borrow_mut();
8685

@@ -96,9 +95,7 @@ pub fn set_default(handle: &Handle) -> DefaultGuard<'_> {
9695

9796
*current = Some(handle.clone());
9897
});
99-
DefaultGuard {
100-
_lifetime: PhantomData,
101-
}
98+
DefaultGuard { _p: () }
10299
}
103100

104101
impl Handle {
@@ -194,7 +191,7 @@ impl fmt::Debug for HandlePriv {
194191
}
195192
}
196193

197-
impl<'a> Drop for DefaultGuard<'a> {
194+
impl Drop for DefaultGuard {
198195
fn drop(&mut self) {
199196
let _ = CURRENT_TIMER.try_with(|current| {
200197
let mut current = current.borrow_mut();

0 commit comments

Comments
 (0)