Skip to content

Commit

Permalink
Rollup merge of rust-lang#49273 - michaelwoerister:fix-extern-proc-ma…
Browse files Browse the repository at this point in the history
…cro-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
  • Loading branch information
alexcrichton committed Mar 23, 2018
2 parents 8a1731a + a1a3bf2 commit cd9fb22
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule};
use schema::*;

use rustc_data_structures::sync::{Lrc, ReadGuard};
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash,
DisambiguatedDefPathData};
use rustc::hir;
use rustc::middle::cstore::{LinkagePreference, ExternConstBody,
ExternBodyNestedBodies};
Expand Down Expand Up @@ -1125,7 +1126,23 @@ impl<'a, 'tcx> CrateMetadata {

#[inline]
pub fn def_key(&self, index: DefIndex) -> DefKey {
self.def_path_table.def_key(index)
if !self.is_proc_macro(index) {
self.def_path_table.def_key(index)
} else {
// FIXME(#49271) - It would be better if the DefIds were consistent
// with the DefPathTable, but for proc-macro crates
// they aren't.
let name = self.proc_macros
.as_ref()
.unwrap()[index.to_proc_macro_index()].0;
DefKey {
parent: Some(CRATE_DEF_INDEX),
disambiguated_data: DisambiguatedDefPathData {
data: DefPathData::MacroDef(name.as_str()),
disambiguator: 0,
}
}
}
}

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

0 comments on commit cd9fb22

Please sign in to comment.