@@ -372,12 +372,14 @@ impl Serialize for CompCtx<'_, '_> {
372372 S : Serializer ,
373373 {
374374 use ser:: * ;
375- #[ allow( clippy:: unnecessary_cast) ]
376375 SERIALIZATION_CONTEXT . with ( |c| {
377- if let Some ( ptr) = c. replace ( Some ( ContextPointer :: new (
378- self as * const CompCtx < ' _ , ' _ > as * const CompCtx < ' static , ' static > , // this intermediate cast is necessary
379- ) ) ) {
380- if * ptr != ( self as * const CompCtx < ' _ , ' _ > as * const CompCtx < ' static , ' static > ) {
376+ let p = unsafe {
377+ std:: mem:: transmute :: < * const CompCtx < ' _ , ' _ > , * const CompCtx < ' static , ' static > > (
378+ self as _ ,
379+ )
380+ } ;
381+ if let Some ( ptr) = c. replace ( Some ( ContextPointer :: new ( p) ) ) {
382+ if * ptr != p {
381383 panic ! ( "serialization context is already in use with an address of {ptr:#?}" ) ;
382384 }
383385 }
@@ -409,12 +411,14 @@ impl<'de> DeserializeSeed<'de> for &CompCtx<'_, '_> {
409411 D : Deserializer < ' de > ,
410412 {
411413 use de:: * ;
412- #[ allow( clippy:: unnecessary_cast) ]
413414 SERIALIZATION_CONTEXT . with ( |c| {
414- if let Some ( ptr) = c. replace ( Some ( ContextPointer :: new (
415- self as * const CompCtx < ' _ , ' _ > as * const CompCtx < ' static , ' static > , // this intermediate cast is necessary
416- ) ) ) {
417- if * ptr != ( self as * const CompCtx < ' _ , ' _ > as * const CompCtx < ' static , ' static > ) {
415+ let p = unsafe {
416+ std:: mem:: transmute :: < * const CompCtx < ' _ , ' _ > , * const CompCtx < ' static , ' static > > (
417+ self as _ ,
418+ )
419+ } ;
420+ if let Some ( ptr) = c. replace ( Some ( ContextPointer :: new ( p) ) ) {
421+ if * ptr != p {
418422 panic ! ( "serialization context is already in use with an address of {ptr:#?}" ) ;
419423 }
420424 }
0 commit comments