about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2017-04-28 09:40:48 -0400
committerNiko Matsakis <niko@alum.mit.edu>2017-05-02 14:01:35 -0400
commitecc8ff9199118b88e98c903c9117fa2f0cddf8ab (patch)
tree31a0bebadd0e657b2ca931ab34228800dbca1e16
parent29263fdb541fe5d59ef116ebf3666cd573d077ab (diff)
downloadrust-ecc8ff9199118b88e98c903c9117fa2f0cddf8ab.tar.gz
rust-ecc8ff9199118b88e98c903c9117fa2f0cddf8ab.zip
rework macro to prepare for more modifiers than just `[pub]`
-rw-r--r--src/librustc/ty/maps.rs45
1 files changed, 40 insertions, 5 deletions
diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs
index 09bdca4915a..e653392e3fb 100644
--- a/src/librustc/ty/maps.rs
+++ b/src/librustc/ty/maps.rs
@@ -353,11 +353,11 @@ impl<'tcx> QueryDescription for queries::mir_pass<'tcx> {
 macro_rules! define_maps {
     (<$tcx:tt>
      $($(#[$attr:meta])*
-       [$($pub:tt)*] $name:ident: $node:ident($K:ty) -> $V:ty,)*) => {
-        pub struct Maps<$tcx> {
-            providers: IndexVec<CrateNum, Providers<$tcx>>,
-            query_stack: RefCell<Vec<(Span, Query<$tcx>)>>,
-            $($(#[$attr])* $($pub)* $name: RefCell<DepTrackingMap<queries::$name<$tcx>>>),*
+       [$($modifiers:tt)*] $name:ident: $node:ident($K:ty) -> $V:ty,)*) => {
+        define_map_struct! {
+            tcx: $tcx,
+            input: ($(([$($attr)*] [$($modifiers)*] $name))*),
+            output: ()
         }
 
         impl<$tcx> Maps<$tcx> {
@@ -519,6 +519,41 @@ macro_rules! define_maps {
     }
 }
 
+macro_rules! define_map_struct {
+    (tcx: $tcx:tt,
+     input: (),
+     output: ($($output:tt)*)) => {
+        pub struct Maps<$tcx> {
+            providers: IndexVec<CrateNum, Providers<$tcx>>,
+            query_stack: RefCell<Vec<(Span, Query<$tcx>)>>,
+            $($output)*
+        }
+    };
+
+    // Detect things with the `pub` modifier
+    (tcx: $tcx:tt,
+     input: (([$($attr:meta)*] [pub] $name:ident) $($input:tt)*),
+     output: ($($output:tt)*)) => {
+        define_map_struct! {
+            tcx: $tcx,
+            input: ($($input)*),
+            output: ($($output)*
+                     $(#[$attr])* pub $name: RefCell<DepTrackingMap<queries::$name<$tcx>>>,)
+        }
+    };
+
+    (tcx: $tcx:tt,
+     input: (([$($attr:meta)*] [$($modifiers:tt)*] $name:ident) $($input:tt)*),
+     output: ($($output:tt)*)) => {
+        define_map_struct! {
+            tcx: $tcx,
+            input: ($($input)*),
+            output: ($($output)*
+                     $(#[$attr])* $name: RefCell<DepTrackingMap<queries::$name<$tcx>>>,)
+        }
+    };
+}
+
 // Each of these maps also corresponds to a method on a
 // `Provider` trait for requesting a value of that type,
 // and a method on `Maps` itself for doing that in a