Skip to content

Commit a1a3bf2

Browse files
Fix DefKey lookup for proc-macro crates.
1 parent b176285 commit a1a3bf2

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/librustc_metadata/decoder.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary};
1414
use schema::*;
1515

1616
use rustc_data_structures::sync::{Lrc, ReadGuard};
17-
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
17+
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash,
18+
DisambiguatedDefPathData};
1819
use rustc::hir;
1920
use rustc::middle::cstore::{LinkagePreference, ExternConstBody,
2021
ExternBodyNestedBodies};
@@ -1115,7 +1116,23 @@ impl<'a, 'tcx> CrateMetadata {
11151116

11161117
#[inline]
11171118
pub fn def_key(&self, index: DefIndex) -> DefKey {
1118-
self.def_path_table.def_key(index)
1119+
if !self.is_proc_macro(index) {
1120+
self.def_path_table.def_key(index)
1121+
} else {
1122+
// FIXME(#49271) - It would be better if the DefIds were consistent
1123+
// with the DefPathTable, but for proc-macro crates
1124+
// they aren't.
1125+
let name = self.proc_macros
1126+
.as_ref()
1127+
.unwrap()[index.to_proc_macro_index()].0;
1128+
DefKey {
1129+
parent: Some(CRATE_DEF_INDEX),
1130+
disambiguated_data: DisambiguatedDefPathData {
1131+
data: DefPathData::MacroDef(name.as_str()),
1132+
disambiguator: 0,
1133+
}
1134+
}
1135+
}
11191136
}
11201137

11211138
// Returns the path leading to the thing with this `id`.

0 commit comments

Comments
 (0)