Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update async_send_sync test #3943

Merged
merged 2 commits into from Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions tokio/src/task/task_local.rs
Expand Up @@ -2,6 +2,7 @@ use pin_project_lite::pin_project;
use std::cell::RefCell;
use std::error::Error;
use std::future::Future;
use std::marker::PhantomPinned;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{fmt, thread};
Expand Down Expand Up @@ -123,6 +124,7 @@ impl<T: 'static> LocalKey<T> {
local: &self,
slot: Some(value),
future: f,
_pinned: PhantomPinned,
}
}

Expand All @@ -147,12 +149,14 @@ impl<T: 'static> LocalKey<T> {
where
F: FnOnce() -> R,
{
let mut scope = TaskLocalFuture {
let scope = TaskLocalFuture {
local: &self,
slot: Some(value),
future: (),
_pinned: PhantomPinned,
};
Pin::new(&mut scope).with_task(|_| f())
crate::pin!(scope);
scope.with_task(|_| f())
}

/// Accesses the current task-local and runs the provided closure.
Expand Down Expand Up @@ -234,6 +238,8 @@ pin_project! {
slot: Option<T>,
#[pin]
future: F,
#[pin]
_pinned: PhantomPinned,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't do this, then #3273 changes whether TaskLocal::scope returns an Unpin future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch 👍

}
}

Expand Down