diff options
Diffstat (limited to 'compiler/rustc_serialize')
| -rw-r--r-- | compiler/rustc_serialize/Cargo.toml | 3 | ||||
| -rw-r--r-- | compiler/rustc_serialize/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_serialize/src/opaque.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_serialize/src/serialize.rs | 29 |
4 files changed, 34 insertions, 5 deletions
diff --git a/compiler/rustc_serialize/Cargo.toml b/compiler/rustc_serialize/Cargo.toml index 8bf98c16361..948242352e7 100644 --- a/compiler/rustc_serialize/Cargo.toml +++ b/compiler/rustc_serialize/Cargo.toml @@ -1,11 +1,12 @@ [package] name = "rustc_serialize" version = "0.0.0" -edition = "2021" +edition = "2024" [dependencies] # tidy-alphabetical-start indexmap = "2.0.0" +rustc_hashes = { path = "../rustc_hashes" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } thin-vec = "0.2.12" # tidy-alphabetical-end diff --git a/compiler/rustc_serialize/src/lib.rs b/compiler/rustc_serialize/src/lib.rs index 47f72298e22..9e9b78cfdd5 100644 --- a/compiler/rustc_serialize/src/lib.rs +++ b/compiler/rustc_serialize/src/lib.rs @@ -13,7 +13,6 @@ #![feature(core_intrinsics)] #![feature(min_specialization)] #![feature(never_type)] -#![feature(ptr_sub_ptr)] #![feature(rustdoc_internals)] #![warn(unreachable_pub)] // tidy-alphabetical-end diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index 27e9f817894..d4907b69b72 100644 --- a/compiler/rustc_serialize/src/opaque.rs +++ b/compiler/rustc_serialize/src/opaque.rs @@ -280,13 +280,13 @@ impl<'a> MemDecoder<'a> { #[inline] pub fn len(&self) -> usize { // SAFETY: This recovers the length of the original slice, only using members we never modify. - unsafe { self.end.sub_ptr(self.start) } + unsafe { self.end.offset_from_unsigned(self.start) } } #[inline] pub fn remaining(&self) -> usize { // SAFETY: This type guarantees current <= end. - unsafe { self.end.sub_ptr(self.current) } + unsafe { self.end.offset_from_unsigned(self.current) } } #[cold] @@ -400,7 +400,7 @@ impl<'a> Decoder for MemDecoder<'a> { #[inline] fn position(&self) -> usize { // SAFETY: This type guarantees start <= current - unsafe { self.current.sub_ptr(self.start) } + unsafe { self.current.offset_from_unsigned(self.start) } } } diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index db8555edd0f..1eefd76f92b 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -10,6 +10,7 @@ use std::path; use std::rc::Rc; use std::sync::Arc; +use rustc_hashes::{Hash64, Hash128}; use smallvec::{Array, SmallVec}; use thin_vec::ThinVec; @@ -716,3 +717,31 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<[T]> { vec.into() } } + +impl<S: Encoder> Encodable<S> for Hash64 { + #[inline] + fn encode(&self, s: &mut S) { + s.emit_raw_bytes(&self.as_u64().to_le_bytes()); + } +} + +impl<S: Encoder> Encodable<S> for Hash128 { + #[inline] + fn encode(&self, s: &mut S) { + s.emit_raw_bytes(&self.as_u128().to_le_bytes()); + } +} + +impl<D: Decoder> Decodable<D> for Hash64 { + #[inline] + fn decode(d: &mut D) -> Self { + Self::new(u64::from_le_bytes(d.read_raw_bytes(8).try_into().unwrap())) + } +} + +impl<D: Decoder> Decodable<D> for Hash128 { + #[inline] + fn decode(d: &mut D) -> Self { + Self::new(u128::from_le_bytes(d.read_raw_bytes(16).try_into().unwrap())) + } +} |
