diff options
| author | kennytm <kennytm@gmail.com> | 2018-03-25 01:26:41 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-25 01:26:41 +0800 |
| commit | 2b2f91638f140aa5d5a889aff185aee964f0fe40 (patch) | |
| tree | 01e1a004f94cbaf4d1d17ba39a2b713cf567a77d /src | |
| parent | 3bc81f7f4dbf5cf0d1b87292848efe78c5fac516 (diff) | |
| parent | a1a3bf2b31af680ffbbed4270efc0a2cda80ca87 (diff) | |
| download | rust-2b2f91638f140aa5d5a889aff185aee964f0fe40.tar.gz rust-2b2f91638f140aa5d5a889aff185aee964f0fe40.zip | |
Rollup merge of #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 #49271). Fixes https://github.com/rust-lang/rust/issues/48739 (though I wasn't able to come up with a regression test, unfortunately) r? @eddyb
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_metadata/decoder.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index e72f9ddd82a..e938d5c1a97 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -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}; @@ -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`. |
