about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2018-03-22 14:38:37 +0100
committerMichael Woerister <michaelwoerister@posteo>2018-03-22 14:40:15 +0100
commita1a3bf2b31af680ffbbed4270efc0a2cda80ca87 (patch)
tree45a2044a74d9fb81cd51e4bd5c98c9b891b32420 /src
parentb176285ba775f86301040fc624acb96b4499f562 (diff)
downloadrust-a1a3bf2b31af680ffbbed4270efc0a2cda80ca87.tar.gz
rust-a1a3bf2b31af680ffbbed4270efc0a2cda80ca87.zip
Fix DefKey lookup for proc-macro crates.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_metadata/decoder.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index b0c945fbf2a..1ea009a4e91 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -14,7 +14,8 @@ use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary};
 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};
@@ -1115,7 +1116,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`.