22
33use super :: * ;
44
5+ use std:: marker:: PhantomData ;
6+
57macro_rules! define_handles {
68 (
79 ' owned: $( $oty: ident, ) *
@@ -45,20 +47,25 @@ macro_rules! define_handles {
4547
4648 $(
4749 #[ 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+ }
5155
5256 // Forward `Drop::drop` to the inherent `drop` method.
5357 impl Drop for $oty {
5458 fn drop( & mut self ) {
55- $oty( self . 0 ) . drop( ) ;
59+ $oty {
60+ handle: self . handle,
61+ _marker: PhantomData ,
62+ } . drop( ) ;
5663 }
5764 }
5865
5966 impl <S > Encode <S > for $oty {
6067 fn encode( self , w: & mut Writer , s: & mut S ) {
61- let handle = self . 0 ;
68+ let handle = self . handle ;
6269 mem:: forget( self ) ;
6370 handle. encode( w, s) ;
6471 }
@@ -74,7 +81,7 @@ macro_rules! define_handles {
7481
7582 impl <S > Encode <S > for & $oty {
7683 fn encode( self , w: & mut Writer , s: & mut S ) {
77- self . 0 . encode( w, s) ;
84+ self . handle . encode( w, s) ;
7885 }
7986 }
8087
@@ -88,7 +95,7 @@ macro_rules! define_handles {
8895
8996 impl <S > Encode <S > for & mut $oty {
9097 fn encode( self , w: & mut Writer , s: & mut S ) {
91- self . 0 . encode( w, s) ;
98+ self . handle . encode( w, s) ;
9299 }
93100 }
94101
@@ -113,21 +120,26 @@ macro_rules! define_handles {
113120
114121 impl <S > DecodeMut <' _, ' _, S > for $oty {
115122 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+ }
117127 }
118128 }
119129 ) *
120130
121131 $(
122132 #[ repr( C ) ]
123133 #[ 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+ }
127139
128140 impl <S > Encode <S > for $ity {
129141 fn encode( self , w: & mut Writer , s: & mut S ) {
130- self . 0 . encode( w, s) ;
142+ self . handle . encode( w, s) ;
131143 }
132144 }
133145
@@ -149,7 +161,10 @@ macro_rules! define_handles {
149161
150162 impl <S > DecodeMut <' _, ' _, S > for $ity {
151163 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+ }
153168 }
154169 }
155170 ) *
@@ -310,15 +325,16 @@ impl Bridge<'_> {
310325 // NB. the server can't do this because it may use a different libstd.
311326 static HIDE_PANICS_DURING_EXPANSION : Once = Once :: new ( ) ;
312327 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| {
314330 let show = BridgeState :: with ( |state| match state {
315331 BridgeState :: NotConnected => true ,
316332 BridgeState :: Connected ( _) | BridgeState :: InUse => force_show_panics,
317333 } ) ;
318334 if show {
319335 prev ( info)
320336 }
321- } ) ;
337+ } ) ) ;
322338 } ) ;
323339
324340 BRIDGE_STATE . with ( |state| state. set ( BridgeState :: Connected ( self ) , f) )
0 commit comments