Skip to content

Commit 864f2dc

Browse files
Refactor byteorder to std in rustc_middle
Use std::io::{Read, Write} and {to, from}_{le, be}_bytes methods in order to remove byteorder from librustc_middle's dependency graph.
1 parent 36b0d7e commit 864f2dc

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3726,7 +3726,6 @@ name = "rustc_middle"
37263726
version = "0.0.0"
37273727
dependencies = [
37283728
"bitflags",
3729-
"byteorder",
37303729
"chalk-ir",
37313730
"measureme",
37323731
"polonius-engine",

compiler/rustc_middle/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ rustc_index = { path = "../rustc_index" }
2626
rustc_serialize = { path = "../rustc_serialize" }
2727
rustc_ast = { path = "../rustc_ast" }
2828
rustc_span = { path = "../rustc_span" }
29-
byteorder = { version = "1.3" }
3029
chalk-ir = "0.14.0"
3130
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
3231
measureme = "0.7.1"

compiler/rustc_middle/src/mir/interpret/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ mod value;
9898
use std::convert::TryFrom;
9999
use std::fmt;
100100
use std::io;
101+
use std::io::{Read, Write};
101102
use std::num::NonZeroU32;
102103
use std::sync::atomic::{AtomicU32, Ordering};
103104

104-
use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt};
105105
use rustc_ast::LitKind;
106106
use rustc_data_structures::fx::FxHashMap;
107107
use rustc_data_structures::sync::{HashMapExt, Lock};
@@ -560,18 +560,20 @@ pub fn write_target_uint(
560560
mut target: &mut [u8],
561561
data: u128,
562562
) -> Result<(), io::Error> {
563-
let len = target.len();
564563
match endianness {
565-
Endian::Little => target.write_uint128::<LittleEndian>(data, len),
566-
Endian::Big => target.write_uint128::<BigEndian>(data, len),
567-
}
564+
Endian::Little => target.write(&data.to_le_bytes())?,
565+
Endian::Big => target.write(&data.to_be_bytes())?,
566+
};
567+
Ok(())
568568
}
569569

570570
#[inline]
571571
pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result<u128, io::Error> {
572+
let mut buf = [0; 16];
573+
source.read(&mut buf)?;
572574
match endianness {
573-
Endian::Little => source.read_uint128::<LittleEndian>(source.len()),
574-
Endian::Big => source.read_uint128::<BigEndian>(source.len()),
575+
Endian::Little => Ok(u128::from_le_bytes(buf)),
576+
Endian::Big => Ok(u128::from_be_bytes(buf)),
575577
}
576578
}
577579

0 commit comments

Comments
 (0)