diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index 0a340ac09fb..63bd3457eb9 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -1,7 +1,6 @@ //! Support code for encoding and decoding types. use smallvec::{Array, SmallVec}; -use std::alloc::Allocator; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque}; @@ -277,9 +276,9 @@ fn decode(_: &mut D) -> PhantomData { } } -impl> Decodable for Box<[T], A> { - fn decode(d: &mut D) -> Box<[T], A> { - let v: Vec = Decodable::decode(d); +impl> Decodable for Box<[T]> { + fn decode(d: &mut D) -> Box<[T]> { + let v: Vec = Decodable::decode(d); v.into_boxed_slice() } } @@ -311,21 +310,10 @@ fn encode(&self, s: &mut S) { } } -impl, A: Allocator + Default> Decodable for Vec { - default fn decode(d: &mut D) -> Vec { +impl> Decodable for Vec { + default fn decode(d: &mut D) -> Vec { let len = d.read_usize(); - let allocator = A::default(); - // SAFETY: we set the capacity in advance, only write elements, and - // only set the length at the end once the writing has succeeded. - let mut vec = Vec::with_capacity_in(len, allocator); - unsafe { - let ptr: *mut T = vec.as_mut_ptr(); - for i in 0..len { - std::ptr::write(ptr.add(i), Decodable::decode(d)); - } - vec.set_len(len); - } - vec + (0..len).map(|_| Decodable::decode(d)).collect() } } @@ -499,16 +487,15 @@ fn decode(d: &mut D) -> Arc { } } -impl, A: Allocator + Default> Encodable for Box { +impl> Encodable for Box { fn encode(&self, s: &mut S) { (**self).encode(s) } } -impl> Decodable for Box { - fn decode(d: &mut D) -> Box { - let allocator = A::default(); - Box::new_in(Decodable::decode(d), allocator) +impl> Decodable for Box { + fn decode(d: &mut D) -> Box { + Box::new(Decodable::decode(d)) } }