Skip to content

Commit fba5e6a

Browse files
committed
Replace mem::uninitialized with MaybeUninit
`mem::uninitialized` is deprecated and for reasons I don't understand causes crash at runtime rust-lang/rust#73573
1 parent 795f027 commit fba5e6a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

protobuf/src/reflect/enums.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ impl EnumDescriptor {
308308

309309
use std::mem;
310310
unsafe {
311-
let mut r = mem::uninitialized();
311+
let mut r = mem::MaybeUninit::<E>::uninit();
312312
self.get_descriptor
313-
.copy_to(value, &mut r as *mut E as *mut ());
314-
Some(r)
313+
.copy_to(value, r.as_mut_ptr() as *mut ());
314+
Some(r.assume_init())
315315
}
316316
}
317317

@@ -337,9 +337,9 @@ impl EnumDescriptor {
337337
debug_assert_eq!(mem::size_of::<E>(), mem::size_of::<i32>());
338338
unsafe {
339339
// This works because `ProtobufEnumOrUnknown<E>` is `#[repr(transparent)]`
340-
let mut r = mem::uninitialized();
341-
ptr::copy(&value, &mut r as *mut E as *mut i32, 1);
342-
Some(r)
340+
let mut r = mem::MaybeUninit::<E>::uninit();
341+
ptr::copy(&value, r.as_mut_ptr() as *mut i32, 1);
342+
Some(r.assume_init())
343343
}
344344
}
345345
}

0 commit comments

Comments
 (0)