mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Avoid specialization for AttrId deserialization
This commit is contained in:
parent
8d598b0d58
commit
47936b4813
@ -20,6 +20,7 @@
|
||||
|
||||
pub use crate::format::*;
|
||||
pub use crate::util::parser::ExprPrecedence;
|
||||
pub use rustc_span::AttrId;
|
||||
pub use GenericArgs::*;
|
||||
pub use UnsafeSource::*;
|
||||
|
||||
@ -30,7 +31,6 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||
use rustc_span::source_map::{respan, Spanned};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
|
||||
@ -2682,22 +2682,6 @@ pub enum AttrStyle {
|
||||
Inner,
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[orderable]
|
||||
#[debug_format = "AttrId({})"]
|
||||
pub struct AttrId {}
|
||||
}
|
||||
|
||||
impl<S: Encoder> Encodable<S> for AttrId {
|
||||
fn encode(&self, _s: &mut S) {}
|
||||
}
|
||||
|
||||
impl<D: Decoder> Decodable<D> for AttrId {
|
||||
default fn decode(_: &mut D) -> AttrId {
|
||||
panic!("cannot decode `AttrId` with `{}`", std::any::type_name::<D>());
|
||||
}
|
||||
}
|
||||
|
||||
/// A list of attributes.
|
||||
pub type AttrVec = ThinVec<Attribute>;
|
||||
|
||||
|
@ -416,15 +416,12 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ast::AttrId {
|
||||
#[inline]
|
||||
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> ast::AttrId {
|
||||
let sess = d.sess.expect("can't decode AttrId without Session");
|
||||
impl<'a, 'tcx> SpanDecoder for DecodeContext<'a, 'tcx> {
|
||||
fn decode_attr_id(&mut self) -> rustc_span::AttrId {
|
||||
let sess = self.sess.expect("can't decode AttrId without Session");
|
||||
sess.parse_sess.attr_id_generator.mk_attr_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> SpanDecoder for DecodeContext<'a, 'tcx> {
|
||||
fn decode_crate_num(&mut self) -> CrateNum {
|
||||
let cnum = CrateNum::from_u32(self.read_u32());
|
||||
self.map_encoded_cnum_to_current(cnum)
|
||||
|
@ -741,6 +741,10 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> {
|
||||
panic!("Failed to convert DefPathHash {def_path_hash:?}")
|
||||
})
|
||||
}
|
||||
|
||||
fn decode_attr_id(&mut self) -> rustc_span::AttrId {
|
||||
panic!("cannot decode `AttrId` with `CacheDecoder`");
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx UnordSet<LocalDefId> {
|
||||
|
@ -1019,6 +1019,12 @@ impl Default for Span {
|
||||
}
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[orderable]
|
||||
#[debug_format = "AttrId({})"]
|
||||
pub struct AttrId {}
|
||||
}
|
||||
|
||||
pub trait SpanEncoder: Encoder {
|
||||
fn encode_span(&mut self, span: Span);
|
||||
fn encode_symbol(&mut self, symbol: Symbol);
|
||||
@ -1106,6 +1112,11 @@ impl<E: SpanEncoder> Encodable<E> for DefId {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: SpanEncoder> Encodable<E> for AttrId {
|
||||
fn encode(&self, _s: &mut E) {
|
||||
// A fresh id will be generated when decoding
|
||||
}
|
||||
}
|
||||
pub trait SpanDecoder: Decoder {
|
||||
fn decode_span(&mut self) -> Span;
|
||||
fn decode_symbol(&mut self) -> Symbol;
|
||||
@ -1114,6 +1125,7 @@ pub trait SpanDecoder: Decoder {
|
||||
fn decode_crate_num(&mut self) -> CrateNum;
|
||||
fn decode_def_index(&mut self) -> DefIndex;
|
||||
fn decode_def_id(&mut self) -> DefId;
|
||||
fn decode_attr_id(&mut self) -> AttrId;
|
||||
}
|
||||
|
||||
impl SpanDecoder for MemDecoder<'_> {
|
||||
@ -1147,6 +1159,10 @@ impl SpanDecoder for MemDecoder<'_> {
|
||||
fn decode_def_id(&mut self) -> DefId {
|
||||
DefId { krate: Decodable::decode(self), index: Decodable::decode(self) }
|
||||
}
|
||||
|
||||
fn decode_attr_id(&mut self) -> AttrId {
|
||||
panic!("cannot decode `AttrId` with `MemDecoder`");
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: SpanDecoder> Decodable<D> for Span {
|
||||
@ -1191,6 +1207,12 @@ impl<D: SpanDecoder> Decodable<D> for DefId {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: SpanDecoder> Decodable<D> for AttrId {
|
||||
fn decode(s: &mut D) -> AttrId {
|
||||
s.decode_attr_id()
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert `source_map` into the session globals for the duration of the
|
||||
/// closure's execution.
|
||||
pub fn set_source_map<T, F: FnOnce() -> T>(source_map: Lrc<SourceMap>, f: F) -> T {
|
||||
|
Loading…
Reference in New Issue
Block a user