mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-22 11:53:44 +00:00
rustc_serialize: have read_raw_bytes take MaybeUninit<u8> slice
This commit is contained in:
parent
a4daa63a90
commit
7c6274d464
@ -4,7 +4,7 @@ use rustc_serialize::{
|
||||
Decodable, Encodable,
|
||||
};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::mem;
|
||||
use std::mem::{self, MaybeUninit};
|
||||
|
||||
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Copy)]
|
||||
pub struct Fingerprint(u64, u64);
|
||||
@ -61,7 +61,7 @@ impl Fingerprint {
|
||||
}
|
||||
|
||||
pub fn decode_opaque(decoder: &mut opaque::Decoder<'_>) -> Result<Fingerprint, String> {
|
||||
let mut bytes = [0; 16];
|
||||
let mut bytes: [MaybeUninit<u8>; 16] = MaybeUninit::uninit_array();
|
||||
|
||||
decoder.read_raw_bytes(&mut bytes)?;
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
use crate::leb128::{self, read_signed_leb128, write_signed_leb128};
|
||||
use crate::serialize;
|
||||
use std::borrow::Cow;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::ptr;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Encoder
|
||||
@ -179,11 +181,19 @@ impl<'a> Decoder<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn read_raw_bytes(&mut self, s: &mut [u8]) -> Result<(), String> {
|
||||
pub fn read_raw_bytes(&mut self, s: &mut [MaybeUninit<u8>]) -> Result<(), String> {
|
||||
let start = self.position;
|
||||
let end = start + s.len();
|
||||
assert!(end <= self.data.len());
|
||||
|
||||
s.copy_from_slice(&self.data[start..end]);
|
||||
// SAFETY: Both `src` and `dst` point to at least `s.len()` elements:
|
||||
// `src` points to at least `s.len()` elements by above assert, and
|
||||
// `dst` points to `s.len()` elements by derivation from `s`.
|
||||
unsafe {
|
||||
let src = self.data.as_ptr().add(start);
|
||||
let dst = s.as_mut_ptr() as *mut u8;
|
||||
ptr::copy_nonoverlapping(src, dst, s.len());
|
||||
}
|
||||
|
||||
self.position = end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user