diff options
| author | bors <bors@rust-lang.org> | 2022-08-26 03:23:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-08-26 03:23:54 +0000 |
| commit | 13a6aaffdf6bd6f1bce000b09aa390e93d6aca77 (patch) | |
| tree | 76d60e3604e38838c1f2203a916df062c3522e78 /compiler/rustc_serialize/src | |
| parent | 76f3b891a0c48e128c5a43ef57e70d86735e1cf2 (diff) | |
| parent | b4d5f48e43f2f7d53ac058877e663229f1407e86 (diff) | |
| download | rust-13a6aaffdf6bd6f1bce000b09aa390e93d6aca77.tar.gz rust-13a6aaffdf6bd6f1bce000b09aa390e93d6aca77.zip | |
Auto merge of #101017 - JohnTitor:rollup-73f2fhb, r=JohnTitor
Rollup of 8 pull requests
Successful merges:
- #99064 (distinguish the method and associated function diagnostic information)
- #99920 (Custom allocator support in `rustc_serialize`)
- #100034 ( Elaborate all box dereferences in `ElaborateBoxDerefs`)
- #100076 (make slice::{split_at,split_at_unchecked} const functions)
- #100604 (Remove unstable Result::into_ok_or_err)
- #100933 (Reduce code size of `assert_matches_failed`)
- #100978 (Handle `Err` in `ast::LitKind::to_token_lit`.)
- #101010 (rustdoc: remove unused CSS for `.multi-column`)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_serialize/src')
| -rw-r--r-- | compiler/rustc_serialize/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_serialize/src/serialize.rs | 26 |
2 files changed, 16 insertions, 11 deletions
diff --git a/compiler/rustc_serialize/src/lib.rs b/compiler/rustc_serialize/src/lib.rs index 079d44bac68..91f4cfaf5ac 100644 --- a/compiler/rustc_serialize/src/lib.rs +++ b/compiler/rustc_serialize/src/lib.rs @@ -16,6 +16,7 @@ Core encoding and decoding interfaces. #![feature(maybe_uninit_slice)] #![feature(let_else)] #![feature(new_uninit)] +#![feature(allocator_api)] #![cfg_attr(test, feature(test))] #![allow(rustc::internal)] #![deny(rustc::untranslatable_diagnostic)] diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index 9bd5550038f..751b209f11a 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -4,6 +4,7 @@ Core encoding and decoding interfaces. */ +use std::alloc::Allocator; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::marker::PhantomData; @@ -229,9 +230,9 @@ impl<D: Decoder, T> Decodable<D> for PhantomData<T> { } } -impl<D: Decoder, T: Decodable<D>> Decodable<D> for Box<[T]> { - fn decode(d: &mut D) -> Box<[T]> { - let v: Vec<T> = Decodable::decode(d); +impl<D: Decoder, A: Allocator + Default, T: Decodable<D>> Decodable<D> for Box<[T], A> { + fn decode(d: &mut D) -> Box<[T], A> { + let v: Vec<T, A> = Decodable::decode(d); v.into_boxed_slice() } } @@ -264,12 +265,13 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for Vec<T> { } } -impl<D: Decoder, T: Decodable<D>> Decodable<D> for Vec<T> { - default fn decode(d: &mut D) -> Vec<T> { +impl<D: Decoder, T: Decodable<D>, A: Allocator + Default> Decodable<D> for Vec<T, A> { + default fn decode(d: &mut D) -> Vec<T, A> { 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(len); + let mut vec = Vec::with_capacity_in(len, allocator); unsafe { let ptr: *mut T = vec.as_mut_ptr(); for i in 0..len { @@ -457,13 +459,15 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<T> { } } -impl<S: Encoder, T: ?Sized + Encodable<S>> Encodable<S> for Box<T> { +impl<S: Encoder, T: ?Sized + Encodable<S>, A: Allocator + Default> Encodable<S> for Box<T, A> { fn encode(&self, s: &mut S) { - (**self).encode(s); + (**self).encode(s) } } -impl<D: Decoder, T: Decodable<D>> Decodable<D> for Box<T> { - fn decode(d: &mut D) -> Box<T> { - Box::new(Decodable::decode(d)) + +impl<D: Decoder, A: Allocator + Default, T: Decodable<D>> Decodable<D> for Box<T, A> { + fn decode(d: &mut D) -> Box<T, A> { + let allocator = A::default(); + Box::new_in(Decodable::decode(d), allocator) } } |
