2
2
3
3
use super :: * ;
4
4
5
+ use std:: marker:: PhantomData ;
6
+
5
7
macro_rules! define_handles {
6
8
(
7
9
' owned: $( $oty: ident, ) *
@@ -45,20 +47,25 @@ macro_rules! define_handles {
45
47
46
48
$(
47
49
#[ repr( C ) ]
48
- pub ( crate ) struct $oty( handle:: Handle ) ;
49
- impl !Send for $oty { }
50
- impl !Sync for $oty { }
50
+ pub ( crate ) struct $oty {
51
+ handle: handle:: Handle ,
52
+ // Prevent Send and Sync impls
53
+ _marker: PhantomData <* mut ( ) >,
54
+ }
51
55
52
56
// Forward `Drop::drop` to the inherent `drop` method.
53
57
impl Drop for $oty {
54
58
fn drop( & mut self ) {
55
- $oty( self . 0 ) . drop( ) ;
59
+ $oty {
60
+ handle: self . handle,
61
+ _marker: PhantomData ,
62
+ } . drop( ) ;
56
63
}
57
64
}
58
65
59
66
impl <S > Encode <S > for $oty {
60
67
fn encode( self , w: & mut Writer , s: & mut S ) {
61
- let handle = self . 0 ;
68
+ let handle = self . handle ;
62
69
mem:: forget( self ) ;
63
70
handle. encode( w, s) ;
64
71
}
@@ -74,7 +81,7 @@ macro_rules! define_handles {
74
81
75
82
impl <S > Encode <S > for & $oty {
76
83
fn encode( self , w: & mut Writer , s: & mut S ) {
77
- self . 0 . encode( w, s) ;
84
+ self . handle . encode( w, s) ;
78
85
}
79
86
}
80
87
@@ -88,7 +95,7 @@ macro_rules! define_handles {
88
95
89
96
impl <S > Encode <S > for & mut $oty {
90
97
fn encode( self , w: & mut Writer , s: & mut S ) {
91
- self . 0 . encode( w, s) ;
98
+ self . handle . encode( w, s) ;
92
99
}
93
100
}
94
101
@@ -113,21 +120,26 @@ macro_rules! define_handles {
113
120
114
121
impl <S > DecodeMut <' _, ' _, S > for $oty {
115
122
fn decode( r: & mut Reader <' _>, s: & mut S ) -> Self {
116
- $oty( handle:: Handle :: decode( r, s) )
123
+ $oty {
124
+ handle: handle:: Handle :: decode( r, s) ,
125
+ _marker: PhantomData ,
126
+ }
117
127
}
118
128
}
119
129
) *
120
130
121
131
$(
122
132
#[ repr( C ) ]
123
133
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
124
- pub ( crate ) struct $ity( handle:: Handle ) ;
125
- impl !Send for $ity { }
126
- impl !Sync for $ity { }
134
+ pub ( crate ) struct $ity {
135
+ handle: handle:: Handle ,
136
+ // Prevent Send and Sync impls
137
+ _marker: PhantomData <* mut ( ) >,
138
+ }
127
139
128
140
impl <S > Encode <S > for $ity {
129
141
fn encode( self , w: & mut Writer , s: & mut S ) {
130
- self . 0 . encode( w, s) ;
142
+ self . handle . encode( w, s) ;
131
143
}
132
144
}
133
145
@@ -149,7 +161,10 @@ macro_rules! define_handles {
149
161
150
162
impl <S > DecodeMut <' _, ' _, S > for $ity {
151
163
fn decode( r: & mut Reader <' _>, s: & mut S ) -> Self {
152
- $ity( handle:: Handle :: decode( r, s) )
164
+ $ity {
165
+ handle: handle:: Handle :: decode( r, s) ,
166
+ _marker: PhantomData ,
167
+ }
153
168
}
154
169
}
155
170
) *
@@ -310,15 +325,16 @@ impl Bridge<'_> {
310
325
// NB. the server can't do this because it may use a different libstd.
311
326
static HIDE_PANICS_DURING_EXPANSION : Once = Once :: new ( ) ;
312
327
HIDE_PANICS_DURING_EXPANSION . call_once ( || {
313
- panic:: update_hook ( move |prev, info| {
328
+ let prev = panic:: take_hook ( ) ;
329
+ panic:: set_hook ( Box :: new ( move |info| {
314
330
let show = BridgeState :: with ( |state| match state {
315
331
BridgeState :: NotConnected => true ,
316
332
BridgeState :: Connected ( _) | BridgeState :: InUse => force_show_panics,
317
333
} ) ;
318
334
if show {
319
335
prev ( info)
320
336
}
321
- } ) ;
337
+ } ) ) ;
322
338
} ) ;
323
339
324
340
BRIDGE_STATE . with ( |state| state. set ( BridgeState :: Connected ( self ) , f) )
0 commit comments