Skip to content

Commit b97d413

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 c336478 commit b97d413

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
@@ -3722,7 +3722,6 @@ name = "rustc_middle"
37223722
version = "0.0.0"
37233723
dependencies = [
37243724
"bitflags",
3725-
"byteorder",
37263725
"chalk-ir",
37273726
"measureme",
37283727
"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.21.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};
@@ -561,18 +561,20 @@ pub fn write_target_uint(
561561
mut target: &mut [u8],
562562
data: u128,
563563
) -> Result<(), io::Error> {
564-
let len = target.len();
565564
match endianness {
566-
Endian::Little => target.write_uint128::<LittleEndian>(data, len),
567-
Endian::Big => target.write_uint128::<BigEndian>(data, len),
568-
}
565+
Endian::Little => target.write(&data.to_le_bytes())?,
566+
Endian::Big => target.write(&data.to_be_bytes())?,
567+
};
568+
Ok(())
569569
}
570570

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

0 commit comments

Comments
 (0)