diff --git a/src/librustc_middle/ty/query/plumbing.rs b/src/librustc_middle/ty/query/plumbing.rs index 612507711fdb..f3a49438f5b2 100644 --- a/src/librustc_middle/ty/query/plumbing.rs +++ b/src/librustc_middle/ty/query/plumbing.rs @@ -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) -> $V { - fn mono(this: TyCtxtAt<$tcx>, key: DefId) -> $V { - get_query::, _>(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::, _>(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) -> $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) { - fn mono(this: TyCtxtEnsure<$tcx>, key: DefId) { - ensure_query::, _>(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::, _>(self.tcx, key) - } - }; +macro_rules! query_helper_param_ty { + (DefId) => { impl Into }; + ($K:ty) => { $K }; } macro_rules! define_queries_inner { @@ -432,8 +382,12 @@ macro_rules! define_queries_inner { 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::, _>(self.tcx, key.into()) + })* } #[derive(Copy, Clone)] @@ -470,7 +424,11 @@ macro_rules! define_queries_inner { } } - $( 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 @@ macro_rules! define_queries_inner { } 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::, _>(self.tcx, self.span, key.into()) + })* } define_provider_struct! {