From 03b25989246be62fe1c489db5f381c1ac36a46d5 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 14 Nov 2022 09:49:32 +0000 Subject: [PATCH] Manually implement `Encodable` for ProvenanceMap to avoid serializing an always-none option --- .../mir/interpret/allocation/provenance_map.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation/provenance_map.rs b/compiler/rustc_middle/src/mir/interpret/allocation/provenance_map.rs index ab99cb66114..3c78d642e15 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation/provenance_map.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation/provenance_map.rs @@ -7,9 +7,10 @@ use rustc_data_structures::sorted_map::SortedMap; use rustc_target::abi::{HasDataLayout, Size}; 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. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[derive(HashStable)] pub struct ProvenanceMap { /// Provenance in this map applies from the given offset for an entire pointer-size worth of @@ -21,6 +22,20 @@ pub struct ProvenanceMap { bytes: Option>>, } +impl> Decodable for ProvenanceMap { + fn decode(d: &mut D) -> Self { + Self { ptrs: Decodable::decode(d), bytes: None } + } +} + +impl> Encodable for ProvenanceMap { + fn encode(&self, s: &mut S) { + let Self { ptrs, bytes } = self; + debug_assert!(bytes.is_none()); + ptrs.encode(s) + } +} + impl ProvenanceMap { pub fn new() -> Self { ProvenanceMap { ptrs: SortedMap::new(), bytes: None }