Manually implement Encodable
for ProvenanceMap to avoid serializing an always-none option
This commit is contained in:
parent
b04166ff35
commit
03b2598924
1 changed files with 16 additions and 1 deletions
|
@ -7,9 +7,10 @@ use rustc_data_structures::sorted_map::SortedMap;
|
||||||
use rustc_target::abi::{HasDataLayout, Size};
|
use rustc_target::abi::{HasDataLayout, Size};
|
||||||
|
|
||||||
use super::{alloc_range, AllocError, AllocId, AllocRange, AllocResult, Provenance};
|
use super::{alloc_range, AllocError, AllocId, AllocRange, AllocResult, Provenance};
|
||||||
|
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||||
|
|
||||||
/// Stores the provenance information of pointers stored in memory.
|
/// Stores the provenance information of pointers stored in memory.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
#[derive(HashStable)]
|
#[derive(HashStable)]
|
||||||
pub struct ProvenanceMap<Prov = AllocId> {
|
pub struct ProvenanceMap<Prov = AllocId> {
|
||||||
/// Provenance in this map applies from the given offset for an entire pointer-size worth of
|
/// Provenance in this map applies from the given offset for an entire pointer-size worth of
|
||||||
|
@ -21,6 +22,20 @@ pub struct ProvenanceMap<Prov = AllocId> {
|
||||||
bytes: Option<Box<SortedMap<Size, Prov>>>,
|
bytes: Option<Box<SortedMap<Size, Prov>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<D: Decoder, Prov: Decodable<D>> Decodable<D> for ProvenanceMap<Prov> {
|
||||||
|
fn decode(d: &mut D) -> Self {
|
||||||
|
Self { ptrs: Decodable::decode(d), bytes: None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: Encoder, Prov: Encodable<S>> Encodable<S> for ProvenanceMap<Prov> {
|
||||||
|
fn encode(&self, s: &mut S) {
|
||||||
|
let Self { ptrs, bytes } = self;
|
||||||
|
debug_assert!(bytes.is_none());
|
||||||
|
ptrs.encode(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<Prov> ProvenanceMap<Prov> {
|
impl<Prov> ProvenanceMap<Prov> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
ProvenanceMap { ptrs: SortedMap::new(), bytes: None }
|
ProvenanceMap { ptrs: SortedMap::new(), bytes: None }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue