Repository: rust-lang/rust
File: compiler/rustc_middle/src/query/plumbing.rs (Rust)

Code before:
                }
            )*
        }

        impl<'tcx> $crate::query::TyCtxtEnsureDone<'tcx> {
            $(
                $(#[$attr])*
                #[inline(always)]
                pub fn $name(self, key: impl $crate::query::IntoQueryParam<$($K)*>) {
                    crate::query::inner::query_ensure(
                        self.tcx,
                        self.tcx.query_system.fns.engine.$name,
                        &self.tcx.query_system.caches.$name,
                        $crate::query::IntoQueryParam::into_query_param(key),
                        true,
                    );
                }
            )*
        }

        impl<'tcx> TyCtxt<'tcx> {
            $(
                $(#[$attr])*
                #[inline(always)]
                #[must_use]
                pub fn $name(self, key: impl $crate::query::IntoQueryParam<$($K)*>) -> $V {
                    self.at(DUMMY_SP).$name(key)
                }
            )*
        }

        impl<'tcx> $crate::query::TyCtxtAt<'tcx> {
            $(
                $(#[$attr])*
                #[inline(always)]
                pub fn $name(self, key: impl $crate::query::IntoQueryParam<$($K)*>) -> $V {
                    use $crate::query::{erase, inner};

                    erase::restore_val::<$V>(inner::query_get_at(
                        self.tcx,
                        self.tcx.query_system.fns.engine.$name,
                        &self.tcx.query_system.caches.$name,
                        self.span,
                        $crate::query::IntoQueryParam::into_query_param(key),
                    ))
                }
            )*
        }

        /// Holds a `QueryVTable` for each query.
        ///

Review comment (refactor):
In a vacuum I really dislike this, because it clutters the signature of every single query method in a way that adds real friction.

However, being able to simplify `$($K:tt)*` to `$K:ty` is a pretty compelling payoff.

If I continue to feel strongly about this, perhaps I can look into detecting `DefId`/`LocalDefId` in the proc-macro, and emit a synthetic `(into_query_param)` modifier to help simplify the query methods that don't need it.

Code after:
                    )(
                        self.tcx,
                        self.tcx.query_system.fns.engine.$name,
                        &self.tcx.query_system.caches.$name,
                        $crate::query::IntoQueryParam::into_query_param(key),
                        false,
                    )
                }
            )*
        }

        impl<'tcx> $crate::query::TyCtxtEnsureDone<'tcx> {
            $(
                $(#[$attr])*
                #[inline(always)]
                pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
                    crate::query::inner::query_ensure(
                        self.tcx,
                        self.tcx.query_system.fns.engine.$name,
                        &self.tcx.query_system.caches.$name,
                        $crate::query::IntoQueryParam::into_query_param(key),
                        true,
                    );
                }
            )*
        }

        impl<'tcx> TyCtxt<'tcx> {
            $(
                $(#[$attr])*
                #[inline(always)]
                #[must_use]
                pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V {
                    self.at(DUMMY_SP).$name(key)
                }
            )*
        }

        impl<'tcx> $crate::query::TyCtxtAt<'tcx> {
            $(
                $(#[$attr])*
                #[inline(always)]
                pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V {
                    use $crate::query::{erase, inner};

                    erase::restore_val::<$V>(inner::query_get_at(
                        self.tcx,
                        self.tcx.query_system.fns.engine.$name,
                        &self.tcx.query_system.caches.$name,
                        self.span,
                        $crate::query::IntoQueryParam::into_query_param(key),