about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2018-05-20 23:15:07 -0700
committerZack M. Davis <code@zackmdavis.net>2018-05-28 09:20:14 -0700
commit078486b9f653c25b9df010d67d6d3886e61bb114 (patch)
tree3271bf945a84de78d3be208fdc2f059f92f1660f
parent1329605a3d92e2b4a656895d3f00d508b48b4f57 (diff)
downloadrust-078486b9f653c25b9df010d67d6d3886e61bb114.tar.gz
rust-078486b9f653c25b9df010d67d6d3886e61bb114.zip
in which `NodeMap` and friends are macrotized!
-rw-r--r--src/librustc/util/nodemap.rs29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs
index c92aa24b8cf..0dc71af9db6 100644
--- a/src/librustc/util/nodemap.rs
+++ b/src/librustc/util/nodemap.rs
@@ -19,21 +19,16 @@ use syntax::ast;
 pub use rustc_data_structures::fx::FxHashMap;
 pub use rustc_data_structures::fx::FxHashSet;
 
-pub type NodeMap<T> = FxHashMap<ast::NodeId, T>;
-pub type DefIdMap<T> = FxHashMap<DefId, T>;
-pub type HirIdMap<T> = FxHashMap<HirId, T>;
-pub type ItemLocalMap<T> = FxHashMap<ItemLocalId, T>;
+macro_rules! define_id_collections {
+    ($map_name:ident, $set_name:ident, $key:ty) => {
+        pub type $map_name<T> = FxHashMap<$key, T>;
+        pub fn $map_name<T>() -> $map_name<T> { FxHashMap() }
+        pub type $set_name = FxHashSet<$key>;
+        pub fn $set_name() -> $set_name { FxHashSet() }
+    }
+}
 
-pub type NodeSet = FxHashSet<ast::NodeId>;
-pub type DefIdSet = FxHashSet<DefId>;
-pub type HirIdSet = FxHashSet<HirId>;
-pub type ItemLocalSet = FxHashSet<ItemLocalId>;
-
-pub fn NodeMap<T>() -> NodeMap<T> { FxHashMap() }
-pub fn DefIdMap<T>() -> DefIdMap<T> { FxHashMap() }
-pub fn HirIdMap<T>() -> HirIdMap<T> { FxHashMap() }
-pub fn ItemLocalMap<T>() -> ItemLocalMap<T> { FxHashMap() }
-pub fn NodeSet() -> NodeSet { FxHashSet() }
-pub fn DefIdSet() -> DefIdSet { FxHashSet() }
-pub fn HirIdSet() -> HirIdSet { FxHashSet() }
-pub fn ItemLocalSet() -> ItemLocalSet { FxHashSet() }
+define_id_collections!(NodeMap, NodeSet, ast::NodeId);
+define_id_collections!(DefIdMap, DefIdSet, DefId);
+define_id_collections!(HirIdMap, HirIdSet, HirId);
+define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId);