diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2023-12-31 20:27:35 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2023-12-31 20:42:17 +0000 |
| commit | 8d598b0d581872c5222399f500dd5f9f3f3aa1c3 (patch) | |
| tree | d08bda5c6bf32ca4729485ace7944597fbe46607 /compiler/rustc_span/src/def_id.rs | |
| parent | 6ed37bdc4260bdf64acf0cb2c728d6724c94ac3d (diff) | |
| download | rust-8d598b0d581872c5222399f500dd5f9f3f3aa1c3.tar.gz rust-8d598b0d581872c5222399f500dd5f9f3f3aa1c3.zip | |
Remove almost all uses of specialization from the metadata encoding code
Diffstat (limited to 'compiler/rustc_span/src/def_id.rs')
| -rw-r--r-- | compiler/rustc_span/src/def_id.rs | 47 |
1 files changed, 4 insertions, 43 deletions
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index e397fab5459..b498202dc92 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -1,11 +1,11 @@ -use crate::{HashStableContext, Symbol}; +use crate::{HashStableContext, SpanDecoder, SpanEncoder, Symbol}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher, ToStableHashKey}; use rustc_data_structures::unhash::Unhasher; use rustc_data_structures::AtomicRef; use rustc_index::Idx; use rustc_macros::HashStable_Generic; -use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; +use rustc_serialize::{Decodable, Encodable}; use std::fmt; use std::hash::{BuildHasherDefault, Hash, Hasher}; @@ -46,20 +46,6 @@ impl fmt::Display for CrateNum { } } -/// As a local identifier, a `CrateNum` is only meaningful within its context, e.g. within a tcx. -/// Therefore, make sure to include the context when encode a `CrateNum`. -impl<E: Encoder> Encodable<E> for CrateNum { - default fn encode(&self, s: &mut E) { - s.emit_u32(self.as_u32()); - } -} - -impl<D: Decoder> Decodable<D> for CrateNum { - default fn decode(d: &mut D) -> CrateNum { - CrateNum::from_u32(d.read_u32()) - } -} - /// A `DefPathHash` is a fixed-size representation of a `DefPath` that is /// stable across crate and compilation session boundaries. It consists of two /// separate 64-bit hashes. The first uniquely identifies the crate this @@ -220,18 +206,6 @@ rustc_index::newtype_index! { } } -impl<E: Encoder> Encodable<E> for DefIndex { - default fn encode(&self, _: &mut E) { - panic!("cannot encode `DefIndex` with `{}`", std::any::type_name::<E>()); - } -} - -impl<D: Decoder> Decodable<D> for DefIndex { - default fn decode(_: &mut D) -> DefIndex { - panic!("cannot decode `DefIndex` with `{}`", std::any::type_name::<D>()); - } -} - /// A `DefId` identifies a particular *definition*, by combining a crate /// index and a def index. /// @@ -347,19 +321,6 @@ impl From<LocalDefId> for DefId { } } -impl<E: Encoder> Encodable<E> for DefId { - default fn encode(&self, s: &mut E) { - self.krate.encode(s); - self.index.encode(s); - } -} - -impl<D: Decoder> Decodable<D> for DefId { - default fn decode(d: &mut D) -> DefId { - DefId { krate: Decodable::decode(d), index: Decodable::decode(d) } - } -} - pub fn default_def_id_debug(def_id: DefId, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("DefId").field("krate", &def_id.krate).field("index", &def_id.index).finish() } @@ -423,13 +384,13 @@ impl fmt::Debug for LocalDefId { } } -impl<E: Encoder> Encodable<E> for LocalDefId { +impl<E: SpanEncoder> Encodable<E> for LocalDefId { fn encode(&self, s: &mut E) { self.to_def_id().encode(s); } } -impl<D: Decoder> Decodable<D> for LocalDefId { +impl<D: SpanDecoder> Decodable<D> for LocalDefId { fn decode(d: &mut D) -> LocalDefId { DefId::decode(d).expect_local() } |
