@@ -7,7 +7,6 @@ use futures_io::{
7
7
use futures_sink:: Sink ;
8
8
use pin_project:: { pin_project, pinned_drop} ;
9
9
use std:: pin:: Pin ;
10
- use std:: ptr;
11
10
use std:: thread:: panicking;
12
11
13
12
/// Combinator that asserts that the underlying type is not moved after being polled.
@@ -24,26 +23,21 @@ use std::thread::panicking;
24
23
pub struct AssertUnmoved < T > {
25
24
#[ pin]
26
25
inner : T ,
27
- this_ptr : * const Self ,
26
+ this_addr : usize ,
28
27
}
29
28
30
- // Safety: having a raw pointer in a struct makes it `!Send`, however the
31
- // pointer is never dereferenced so this is safe.
32
- unsafe impl < T : Send > Send for AssertUnmoved < T > { }
33
- unsafe impl < T : Sync > Sync for AssertUnmoved < T > { }
34
-
35
29
impl < T > AssertUnmoved < T > {
36
30
pub ( crate ) fn new ( inner : T ) -> Self {
37
- Self { inner, this_ptr : ptr :: null ( ) }
31
+ Self { inner, this_addr : 0 }
38
32
}
39
33
40
34
fn poll_with < ' a , U > ( mut self : Pin < & ' a mut Self > , f : impl FnOnce ( Pin < & ' a mut T > ) -> U ) -> U {
41
- let cur_this = & * self as * const Self ;
42
- if self . this_ptr . is_null ( ) {
35
+ let cur_this = & * self as * const Self as usize ;
36
+ if self . this_addr == 0 {
43
37
// First time being polled
44
- * self . as_mut ( ) . project ( ) . this_ptr = cur_this;
38
+ * self . as_mut ( ) . project ( ) . this_addr = cur_this;
45
39
} else {
46
- assert_eq ! ( self . this_ptr , cur_this, "AssertUnmoved moved between poll calls" ) ;
40
+ assert_eq ! ( self . this_addr , cur_this, "AssertUnmoved moved between poll calls" ) ;
47
41
}
48
42
f ( self . project ( ) . inner )
49
43
}
@@ -166,9 +160,9 @@ impl<T> PinnedDrop for AssertUnmoved<T> {
166
160
fn drop ( self : Pin < & mut Self > ) {
167
161
// If the thread is panicking then we can't panic again as that will
168
162
// cause the process to be aborted.
169
- if !panicking ( ) && ! self . this_ptr . is_null ( ) {
170
- let cur_this = & * self as * const Self ;
171
- assert_eq ! ( self . this_ptr , cur_this, "AssertUnmoved moved before drop" ) ;
163
+ if !panicking ( ) && self . this_addr != 0 {
164
+ let cur_this = & * self as * const Self as usize ;
165
+ assert_eq ! ( self . this_addr , cur_this, "AssertUnmoved moved before drop" ) ;
172
166
}
173
167
}
174
168
}
0 commit comments