Skip to content

Commit

Permalink
Decode AttrId via mk_attr_id
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Jul 31, 2019
1 parent d4227f6 commit c146344
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
9 changes: 1 addition & 8 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)]
Expand Down

0 comments on commit c146344

Please sign in to comment.