Skip to content

Commit 03b2598

Browse files
committed
Manually implement Encodable for ProvenanceMap to avoid serializing an always-none option
1 parent b04166f commit 03b2598

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

compiler/rustc_middle/src/mir/interpret/allocation/provenance_map.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use rustc_data_structures::sorted_map::SortedMap;
77
use rustc_target::abi::{HasDataLayout, Size};
88

99
use super::{alloc_range, AllocError, AllocId, AllocRange, AllocResult, Provenance};
10+
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
1011

1112
/// Stores the provenance information of pointers stored in memory.
12-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
13+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1314
#[derive(HashStable)]
1415
pub struct ProvenanceMap<Prov = AllocId> {
1516
/// 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> {
2122
bytes: Option<Box<SortedMap<Size, Prov>>>,
2223
}
2324

25+
impl<D: Decoder, Prov: Decodable<D>> Decodable<D> for ProvenanceMap<Prov> {
26+
fn decode(d: &mut D) -> Self {
27+
Self { ptrs: Decodable::decode(d), bytes: None }
28+
}
29+
}
30+
31+
impl<S: Encoder, Prov: Encodable<S>> Encodable<S> for ProvenanceMap<Prov> {
32+
fn encode(&self, s: &mut S) {
33+
let Self { ptrs, bytes } = self;
34+
debug_assert!(bytes.is_none());
35+
ptrs.encode(s)
36+
}
37+
}
38+
2439
impl<Prov> ProvenanceMap<Prov> {
2540
pub fn new() -> Self {
2641
ProvenanceMap { ptrs: SortedMap::new(), bytes: None }

0 commit comments

Comments
 (0)