]> git.lizzy.rs Git - rust.git/commitdiff
Simplify macro
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Fri, 10 Apr 2020 20:44:15 +0000 (13:44 -0700)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Sat, 11 Apr 2020 22:18:51 +0000 (15:18 -0700)
src/librustc_middle/ty/query/plumbing.rs

index 612507711fdb87f52f201e438bde5c19e3ab1f42..f3a49438f5b2fc5db5aa31faf5abe273eb80fc70 100644 (file)
@@ -242,59 +242,9 @@ macro_rules! define_queries {
     }
 }
 
-macro_rules! define_query_helper {
-    (TyCtxtAt<$tcx:tt>, $(#[$attr:meta])* $name:ident(DefId) -> $V:ty) => {
-        $(#[$attr])*
-        #[inline(always)]
-        pub fn $name(self, key: impl Into<DefId>) -> $V {
-            fn mono(this: TyCtxtAt<$tcx>, key: DefId) -> $V {
-                get_query::<queries::$name<'_>, _>(this.tcx, this.span, key)
-            }
-
-            mono(self, key.into())
-        }
-    };
-    (TyCtxtAt<$tcx:tt>, $(#[$attr:meta])* $name:ident($K:ty) -> $V:ty) => {
-        $(#[$attr])*
-        #[inline(always)]
-        pub fn $name(self, key: $K) -> $V {
-            get_query::<queries::$name<'_>, _>(self.tcx, self.span, key)
-        }
-    };
-
-    (TyCtxt<$tcx:tt>, $(#[$attr:meta])* $name:ident(DefId) -> $V:ty) => {
-        $(#[$attr])*
-        #[inline(always)]
-        pub fn $name(self, key: impl Into<DefId>) -> $V {
-            self.at(DUMMY_SP).$name(key)
-        }
-    };
-    (TyCtxt<$tcx:tt>, $(#[$attr:meta])* $name:ident($K:ty) -> $V:ty) => {
-        $(#[$attr])*
-        #[inline(always)]
-        pub fn $name(self, key: $K) -> $V {
-            self.at(DUMMY_SP).$name(key)
-        }
-    };
-
-    (TyCtxtEnsure<$tcx:tt>, $(#[$attr:meta])* $name:ident(DefId) -> $V:ty) => {
-        $(#[$attr])*
-        #[inline(always)]
-        pub fn $name(self, key: impl Into<DefId>) {
-            fn mono(this: TyCtxtEnsure<$tcx>, key: DefId) {
-                ensure_query::<queries::$name<'_>, _>(this.tcx, key)
-            }
-
-            mono(self, key.into())
-        }
-    };
-    (TyCtxtEnsure<$tcx:tt>, $(#[$attr:meta])* $name:ident($K:ty) -> $V:ty) => {
-        $(#[$attr])*
-        #[inline(always)]
-        pub fn $name(self, key: $K) {
-            ensure_query::<queries::$name<'_>, _>(self.tcx, key)
-        }
-    };
+macro_rules! query_helper_param_ty {
+    (DefId) => { impl Into<DefId> };
+    ($K:ty) => { $K };
 }
 
 macro_rules! define_queries_inner {
@@ -432,8 +382,12 @@ pub struct TyCtxtEnsure<'tcx> {
             pub tcx: TyCtxt<'tcx>,
         }
 
-        impl TyCtxtEnsure<'tcx> {
-            $( define_query_helper!(TyCtxtEnsure<'tcx>, $(#[$attr])* $name($($K)*) -> $V); )*
+        impl TyCtxtEnsure<$tcx> {
+            $($(#[$attr])*
+            #[inline(always)]
+            pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
+                ensure_query::<queries::$name<'_>, _>(self.tcx, key.into())
+            })*
         }
 
         #[derive(Copy, Clone)]
@@ -470,7 +424,11 @@ pub fn at(self, span: Span) -> TyCtxtAt<$tcx> {
                 }
             }
 
-            $( define_query_helper!(TyCtxt<$tcx>, $(#[$attr])* $name($($K)*) -> $V); )*
+            $($(#[$attr])*
+            #[inline(always)]
+            pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V {
+                self.at(DUMMY_SP).$name(key)
+            })*
 
             /// All self-profiling events generated by the query engine use
             /// virtual `StringId`s for their `event_id`. This method makes all
@@ -503,7 +461,11 @@ pub fn alloc_self_profile_query_strings(self) {
         }
 
         impl TyCtxtAt<$tcx> {
-            $( define_query_helper!(TyCtxtAt<$tcx>, $(#[$attr])* $name($($K)*) -> $V); )*
+            $($(#[$attr])*
+            #[inline(always)]
+            pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V {
+                get_query::<queries::$name<'_>, _>(self.tcx, self.span, key.into())
+            })*
         }
 
         define_provider_struct! {