From 438652c2922ce3e9ddbf0ddfaeb37723b6fdb128 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Thu, 1 Sep 2022 16:34:05 +0800 Subject: [PATCH] avoid using `mk_attr_id` when decoding --- compiler/rustc_ast/src/ast.rs | 4 ++-- compiler/rustc_metadata/src/rmeta/decoder.rs | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index fb521073a428d..15cafb52d11c8 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2522,8 +2522,8 @@ impl Encodable for AttrId { } impl Decodable for AttrId { - fn decode(_: &mut D) -> AttrId { - crate::attr::mk_attr_id() + default fn decode(_: &mut D) -> AttrId { + panic!("cannot decode `AttrId` with `{}`", std::any::type_name::()); } } diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index d0e0aa91480c9..29309b45d37f5 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -4,6 +4,7 @@ use crate::creader::{CStore, CrateMetadataRef}; use crate::rmeta::*; use rustc_ast as ast; +use rustc_ast::ast::AttrId; use rustc_ast::ptr::P; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxHashMap; @@ -160,6 +161,7 @@ pub(super) struct DecodeContext<'a, 'tcx> { blob: &'a MetadataBlob, sess: Option<&'tcx Session>, tcx: Option>, + next_id: u32, lazy_state: LazyState, @@ -189,6 +191,7 @@ pub(super) trait Metadata<'a, 'tcx>: Copy { blob: self.blob(), sess: self.sess().or(tcx.map(|tcx| tcx.sess)), tcx, + next_id: 0, lazy_state: LazyState::NoNode, alloc_decoding_session: self .cdata() @@ -452,6 +455,14 @@ impl<'a, 'tcx> Decodable> for ExpnIndex { } } +impl<'a, 'tcx> Decodable> for AttrId { + fn decode(d: &mut DecodeContext<'a, 'tcx>) -> AttrId { + let id = d.next_id; + d.next_id += 1; + AttrId::from_u32(id) + } +} + impl<'a, 'tcx> Decodable> for SyntaxContext { fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> SyntaxContext { let cdata = decoder.cdata();