Skip to content

Commit f25811e

Browse files
committed
Replace early-bound normalization hack with per-query key/value type aliases.
1 parent 0cd7ff7 commit f25811e

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc_middle::middle::cstore::{CrateSource, CrateStore, EncodedMetadata};
1717
use rustc_middle::middle::exported_symbols::ExportedSymbol;
1818
use rustc_middle::middle::stability::DeprecationEntry;
1919
use rustc_middle::ty::query::Providers;
20-
use rustc_middle::ty::query::QueryConfig;
2120
use rustc_middle::ty::{self, TyCtxt};
2221
use rustc_session::utils::NativeLibKind;
2322
use rustc_session::{CrateDisambiguator, Session};
@@ -32,12 +31,10 @@ macro_rules! provide {
3231
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
3332
$($name:ident => $compute:block)*) => {
3433
pub fn provide_extern<$lt>(providers: &mut Providers<$lt>) {
35-
// HACK(eddyb) `$lt: $lt` forces `$lt` to be early-bound, which
36-
// allows the associated type in the return type to be normalized.
37-
$(fn $name<$lt: $lt, T: IntoArgs>(
34+
$(fn $name<$lt>(
3835
$tcx: TyCtxt<$lt>,
39-
def_id_arg: T,
40-
) -> <ty::queries::$name<$lt> as QueryConfig<TyCtxt<$lt>>>::Value {
36+
def_id_arg: ty::query::query_keys::$name<$lt>,
37+
) -> ty::query::query_values::$name<$lt> {
4138
let _prof_timer =
4239
$tcx.prof.generic_activity("metadata_decode_entry");
4340

src/librustc_middle/ty/query/plumbing.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,34 @@ macro_rules! define_queries_inner {
318318
}
319319
}
320320

321+
#[allow(nonstandard_style)]
321322
pub mod queries {
322323
use std::marker::PhantomData;
323324

324-
$(#[allow(nonstandard_style)]
325-
pub struct $name<$tcx> {
325+
$(pub struct $name<$tcx> {
326326
data: PhantomData<&$tcx ()>
327327
})*
328328
}
329329

330+
// HACK(eddyb) this is like the `impl QueryConfig for queries::$name`
331+
// below, but using type aliases instead of associated types, to bypass
332+
// the limitations around normalizing under HRTB - for example, this:
333+
// `for<'tcx> fn(...) -> <queries::$name<'tcx> as QueryConfig<TyCtxt<'tcx>>>::Value`
334+
// doesn't currently normalize to `for<'tcx> fn(...) -> query_values::$name<'tcx>`.
335+
// This is primarily used by the `provide!` macro in `rustc_metadata`.
336+
#[allow(nonstandard_style, unused_lifetimes)]
337+
pub mod query_keys {
338+
use super::*;
339+
340+
$(pub type $name<$tcx> = $($K)*;)*
341+
}
342+
#[allow(nonstandard_style, unused_lifetimes)]
343+
pub mod query_values {
344+
use super::*;
345+
346+
$(pub type $name<$tcx> = $V;)*
347+
}
348+
330349
$(impl<$tcx> QueryConfig<TyCtxt<$tcx>> for queries::$name<$tcx> {
331350
type Key = $($K)*;
332351
type Value = $V;

0 commit comments

Comments
 (0)