Skip to content

Commit

Permalink
Ran cargo fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
EkardNT committed Dec 11, 2019
1 parent 16dfa82 commit b35fe53
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use core::cell::Cell;
use core::marker::Unpin;
use core::pin::Pin;
use core::ops::{Deref, Drop, Generator, GeneratorState};
use core::option::Option;
use core::pin::Pin;
use core::ptr::NonNull;
use core::task::{Context, Poll};
use core::ops::{Deref, Drop, Generator, GeneratorState};

#[doc(inline)]
pub use core::future::*;
Expand Down Expand Up @@ -75,12 +75,10 @@ impl Drop for SetOnDrop {
/// Sets the thread-local task context used by async/await futures.
pub fn set_task_context<F, R>(cx: &mut Context<'_>, f: F) -> R
where
F: FnOnce() -> R
F: FnOnce() -> R,
{
// transmute the context's lifetime to 'static so we can store it.
let cx = unsafe {
core::mem::transmute::<&mut Context<'_>, &mut Context<'static>>(cx)
};
let cx = unsafe { core::mem::transmute::<&mut Context<'_>, &mut Context<'static>>(cx) };
let old_cx = TLS_CX.replace(Some(NonNull::from(cx)));
let _reset = SetOnDrop(old_cx);
f()
Expand All @@ -95,7 +93,7 @@ where
/// retrieved by a surrounding call to get_task_context.
pub fn get_task_context<F, R>(f: F) -> R
where
F: FnOnce(&mut Context<'_>) -> R
F: FnOnce(&mut Context<'_>) -> R,
{
// Clear the entry so that nested `get_task_waker` calls
// will fail or set their own value.
Expand All @@ -104,7 +102,8 @@ where

let mut cx_ptr = cx_ptr.expect(
"TLS Context not set. This is a rustc bug. \
Please file an issue on https://github.com/rust-lang/rust.");
Please file an issue on https://github.com/rust-lang/rust.",
);

// Safety: we've ensured exclusive access to the context by
// removing the pointer from TLS, only to be replaced once
Expand All @@ -119,7 +118,7 @@ where
/// Polls a future in the current thread-local task waker.
pub fn poll_with_tls_context<F>(f: Pin<&mut F>) -> Poll<F::Output>
where
F: Future
F: Future,
{
get_task_context(|cx| F::poll(f, cx))
}

0 comments on commit b35fe53

Please sign in to comment.