From 92419974f39a7e1f79f5a87cf448c502d193c8d4 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sat, 16 Mar 2024 14:56:03 +0300 Subject: [PATCH] fix review notes Signed-off-by: onur-ozkan --- compiler/rustc_metadata/src/rmeta/encoder.rs | 4 +--- compiler/rustc_middle/src/mir/interpret/mod.rs | 4 ++-- compiler/stable_mir/src/mir/alloc.rs | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index ced294a7af56f..6e05b89a303be 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2200,12 +2200,10 @@ impl Decodable for EncodedMetadata { let len = d.read_usize(); let mmap = if len > 0 { let mut mmap = MmapMut::map_anon(len).unwrap(); - let mut num_bytes = 0; for _ in 0..len { - num_bytes += (&mut mmap[..]).write(&[d.read_u8()]).unwrap(); + (&mut mmap[..]).write_all(&[d.read_u8()]).unwrap(); } mmap.flush().unwrap(); - debug_assert!(len == num_bytes); Some(mmap.make_read_only().unwrap()) } else { None diff --git a/compiler/rustc_middle/src/mir/interpret/mod.rs b/compiler/rustc_middle/src/mir/interpret/mod.rs index 6cdaa65604409..ad11d3c4d6164 100644 --- a/compiler/rustc_middle/src/mir/interpret/mod.rs +++ b/compiler/rustc_middle/src/mir/interpret/mod.rs @@ -671,11 +671,11 @@ pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result { - let _ = source.read(&mut buf)?; + source.read_exact(&mut buf)?; Ok(u128::from_le_bytes(buf)) } Endian::Big => { - let _ = source.read(&mut buf[16 - source.len()..])?; + source.read_exact(&mut buf[16 - source.len()..])?; Ok(u128::from_be_bytes(buf)) } }; diff --git a/compiler/stable_mir/src/mir/alloc.rs b/compiler/stable_mir/src/mir/alloc.rs index 6866da4284459..b2f296387a66b 100644 --- a/compiler/stable_mir/src/mir/alloc.rs +++ b/compiler/stable_mir/src/mir/alloc.rs @@ -57,11 +57,11 @@ pub(crate) fn read_target_uint(mut bytes: &[u8]) -> Result { let mut buf = [0u8; std::mem::size_of::()]; match MachineInfo::target_endianess() { Endian::Little => { - let _ = bytes.read(&mut buf)?; + bytes.read_exact(&mut buf)?; Ok(u128::from_le_bytes(buf)) } Endian::Big => { - let _ = bytes.read(&mut buf[16 - bytes.len()..])?; + bytes.read_exact(&mut buf[16 - bytes.len()..])?; Ok(u128::from_be_bytes(buf)) } } @@ -72,11 +72,11 @@ pub(crate) fn read_target_int(mut bytes: &[u8]) -> Result { let mut buf = [0u8; std::mem::size_of::()]; match MachineInfo::target_endianess() { Endian::Little => { - let _ = bytes.read(&mut buf)?; + bytes.read_exact(&mut buf)?; Ok(i128::from_le_bytes(buf)) } Endian::Big => { - let _ = bytes.read(&mut buf[16 - bytes.len()..])?; + bytes.read_exact(&mut buf[16 - bytes.len()..])?; Ok(i128::from_be_bytes(buf)) } }