Skip to content

Commit 2b2f916

Browse files
authored
Rollup merge of rust-lang#49273 - michaelwoerister:fix-extern-proc-macro-defkey, r=eddyb
Fix DefKey lookup for proc-macro crates. Add a special case for proc-macro crates for `def_key()` in the metadata decoder (like we already have for many other methods in there). In the long run, it would be preferable to get rid of the need for special casing proc-macro crates (see rust-lang#49271). Fixes rust-lang#48739 (though I wasn't able to come up with a regression test, unfortunately) r? @eddyb
2 parents 3bc81f7 + a1a3bf2 commit 2b2f916

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/librustc_metadata/decoder.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule};
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};
@@ -1125,7 +1126,23 @@ impl<'a, 'tcx> CrateMetadata {
11251126

11261127
#[inline]
11271128
pub fn def_key(&self, index: DefIndex) -> DefKey {
1128-
self.def_path_table.def_key(index)
1129+
if !self.is_proc_macro(index) {
1130+
self.def_path_table.def_key(index)
1131+
} else {
1132+
// FIXME(#49271) - It would be better if the DefIds were consistent
1133+
// with the DefPathTable, but for proc-macro crates
1134+
// they aren't.
1135+
let name = self.proc_macros
1136+
.as_ref()
1137+
.unwrap()[index.to_proc_macro_index()].0;
1138+
DefKey {
1139+
parent: Some(CRATE_DEF_INDEX),
1140+
disambiguated_data: DisambiguatedDefPathData {
1141+
data: DefPathData::MacroDef(name.as_str()),
1142+
disambiguator: 0,
1143+
}
1144+
}
1145+
}
11291146
}
11301147

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

0 commit comments

Comments
 (0)