summaryrefslogtreecommitdiffstats
path: root/tokio/tests/tcp_accept.rs
diff options
context:
space:
mode:
authorTaiki Endo <te316e89@gmail.com>2020-06-12 19:49:39 +0900
committerGitHub <noreply@github.com>2020-06-12 19:49:39 +0900
commit6b6e76080afc92450238df69c4edc12ee5f7518d (patch)
tree9ce5f612595a3829778df524c24f51a91f155a0e /tokio/tests/tcp_accept.rs
parent68b4ca9f553bd4c26ea78e1f564e452071cf6474 (diff)
chore: reduce pin related unsafe code (#2613)
Diffstat (limited to 'tokio/tests/tcp_accept.rs')
-rw-r--r--tokio/tests/tcp_accept.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/tokio/tests/tcp_accept.rs b/tokio/tests/tcp_accept.rs
index f7ccd7f4..9f5b4414 100644
--- a/tokio/tests/tcp_accept.rs
+++ b/tokio/tests/tcp_accept.rs
@@ -39,6 +39,7 @@ test_accept! {
(ip_port_tuple, ("127.0.0.1".parse::<IpAddr>().unwrap(), 0)),
}
+use pin_project_lite::pin_project;
use std::pin::Pin;
use std::sync::{
atomic::{AtomicUsize, Ordering::SeqCst},
@@ -47,9 +48,12 @@ use std::sync::{
use std::task::{Context, Poll};
use tokio::stream::{Stream, StreamExt};
-struct TrackPolls<S> {
- npolls: Arc<AtomicUsize>,
- s: S,
+pin_project! {
+ struct TrackPolls<S> {
+ npolls: Arc<AtomicUsize>,
+ #[pin]
+ s: S,
+ }
}
impl<S> Stream for TrackPolls<S>
@@ -58,11 +62,9 @@ where
{
type Item = S::Item;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
- // safety: we do not move s
- let this = unsafe { self.get_unchecked_mut() };
+ let this = self.project();
this.npolls.fetch_add(1, SeqCst);
- // safety: we are pinned, and so is s
- unsafe { Pin::new_unchecked(&mut this.s) }.poll_next(cx)
+ this.s.poll_next(cx)
}
}