Decode AttrId via mk_attr_id

This commit is contained in:
Mark Rousskov 2019-07-30 13:40:43 -04:00
parent d4227f6e0d
commit c146344e32
2 changed files with 14 additions and 11 deletions

View File

@ -980,14 +980,7 @@ impl<'a, 'tcx> CrateMetadata {
}
fn get_attributes(&self, item: &Entry<'tcx>, sess: &Session) -> Vec<ast::Attribute> {
item.attributes
.decode((self, sess))
.map(|mut attr| {
// Need new unique IDs: old thread-local IDs won't map to new threads.
attr.id = attr::mk_attr_id();
attr
})
.collect()
item.attributes.decode((self, sess)).collect()
}
// Translate a DefId from the current compilation environment to a DefId

View File

@ -2104,9 +2104,7 @@ pub enum AttrStyle {
Inner,
}
#[derive(
Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, PartialOrd, Ord, Copy,
)]
#[derive(Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, Copy)]
pub struct AttrId(pub usize);
impl Idx for AttrId {
@ -2118,6 +2116,18 @@ impl Idx for AttrId {
}
}
impl rustc_serialize::Encodable for AttrId {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_unit()
}
}
impl rustc_serialize::Decodable for AttrId {
fn decode<D: Decoder>(d: &mut D) -> Result<AttrId, D::Error> {
d.read_nil().map(|_| crate::attr::mk_attr_id())
}
}
/// Metadata associated with an item.
/// Doc-comments are promoted to attributes that have `is_sugared_doc = true`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]