Skip to content

Commit 178c650

Browse files
committed
typeck all the tables
1 parent 2e6bf09 commit 178c650

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/librustc_middle/query/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,14 @@ rustc_queries! {
556556
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
557557
cache_on_disk_if { true }
558558
}
559+
query typeck_tables_of_const_arg(
560+
key: ty::WithOptParam<LocalDefId>
561+
) -> &'tcx ty::TypeckTables<'tcx> {
562+
desc {
563+
|tcx| "type-checking the potential const argument `{}`",
564+
tcx.def_path_str(key.did.to_def_id()),
565+
}
566+
}
559567
query diagnostic_only_typeck_tables_of(key: LocalDefId) -> &'tcx ty::TypeckTables<'tcx> {
560568
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
561569
cache_on_disk_if { true }

src/librustc_middle/ty/query/keys.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ impl Key for DefId {
105105
}
106106
}
107107

108+
impl Key for ty::WithOptParam<LocalDefId> {
109+
type CacheSelector = DefaultCacheSelector;
110+
111+
fn query_crate(&self) -> CrateNum {
112+
self.did.query_crate()
113+
}
114+
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
115+
self.did.default_span(tcx)
116+
}
117+
}
118+
108119
impl Key for (DefId, DefId) {
109120
type CacheSelector = DefaultCacheSelector;
110121

src/librustc_typeck/check/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ pub fn provide(providers: &mut Providers) {
764764
method::provide(providers);
765765
*providers = Providers {
766766
typeck_item_bodies,
767+
typeck_tables_of_const_arg,
767768
typeck_tables_of,
768769
diagnostic_only_typeck_tables_of,
769770
has_typeck_tables,
@@ -955,9 +956,25 @@ where
955956
val.fold_with(&mut FixupFolder { tcx })
956957
}
957958

959+
fn typeck_tables_of_const_arg<'tcx>(
960+
tcx: TyCtxt<'tcx>,
961+
def: ty::WithOptParam<LocalDefId>,
962+
) -> &ty::TypeckTables<'tcx> {
963+
if let Some(param_did) = def.param_did {
964+
let fallback = move || tcx.type_of(param_did);
965+
typeck_tables_of_with_fallback(tcx, def.did, fallback)
966+
} else {
967+
tcx.typeck_tables_of(def.did)
968+
}
969+
}
970+
958971
fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckTables<'tcx> {
959-
let fallback = move || tcx.type_of(def_id.to_def_id());
960-
typeck_tables_of_with_fallback(tcx, def_id, fallback)
972+
if let param_did @ Some(_) = tcx.opt_const_param_of(def_id) {
973+
tcx.typeck_tables_of_const_arg(ty::WithOptParam { did: def_id, param_did })
974+
} else {
975+
let fallback = move || tcx.type_of(def_id.to_def_id());
976+
typeck_tables_of_with_fallback(tcx, def_id, fallback)
977+
}
961978
}
962979

963980
/// Used only to get `TypeckTables` for type inference during error recovery.

0 commit comments

Comments
 (0)