Skip to content

Commit b94498a

Browse files
committed
Use existing query feeding workarounds
1 parent 8bb49e2 commit b94498a

File tree

6 files changed

+10
-46
lines changed

6 files changed

+10
-46
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,20 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
434434

435435
// Provide the resolved type of the associated constant to `type_of(AnonConst)`.
436436
if !speculative && let ty::AssocKind::Const = assoc_kind {
437+
let hir::TypeBindingKind::Equality { term: hir::Term::Const(anon_const) } =
438+
binding.kind
439+
else {
440+
bug!()
441+
};
437442
let ty = alias_ty.map_bound(|ty| tcx.type_of(ty.def_id).instantiate(tcx, ty.args));
438443
// Since the arguments passed to the alias type above may contain early-bound
439444
// generic parameters, the instantiated type may contain some as well.
440445
// Therefore wrap it in `EarlyBinder`.
441-
tcx.feed_type_of_assoc_const_binding(binding.hir_id, ty::EarlyBinder::bind(ty));
446+
// FIXME(fmease): Reject escaping late-bound vars.
447+
tcx.feed_anon_const_type(
448+
anon_const.def_id,
449+
ty::EarlyBinder::bind(ty.skip_binder()),
450+
);
442451
}
443452

444453
alias_ty

compiler/rustc_hir_analysis/src/collect.rs

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ pub fn provide(providers: &mut Providers) {
6363
*providers = Providers {
6464
type_of: type_of::type_of,
6565
type_of_opaque: type_of::type_of_opaque,
66-
type_of_assoc_const_binding: type_of::type_of_assoc_const_binding,
6766
type_alias_is_lazy: type_of::type_alias_is_lazy,
6867
item_bounds: item_bounds::item_bounds,
6968
explicit_item_bounds: item_bounds::explicit_item_bounds,

compiler/rustc_hir_analysis/src/collect/type_of.rs

-18
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
7878
.expect("const parameter types cannot be generic");
7979
}
8080

81-
Node::TypeBinding(&TypeBinding { hir_id, .. }) => {
82-
// FIXME(fmease): Reject “escaping” early-bound generic parameters.
83-
// FIXME(fmease): Reject escaping late-bound vars.
84-
return tcx.type_of_assoc_const_binding(hir_id).skip_binder().skip_binder();
85-
}
86-
8781
// This match arm is for when the def_id appears in a GAT whose
8882
// path can't be resolved without typechecking e.g.
8983
//
@@ -290,18 +284,6 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
290284
}
291285
}
292286

293-
pub(super) fn type_of_assoc_const_binding<'tcx>(
294-
tcx: TyCtxt<'tcx>,
295-
hir_id: HirId,
296-
) -> ty::EarlyBinder<ty::Binder<'tcx, Ty<'tcx>>> {
297-
let reported = tcx.dcx().delayed_bug(format!(
298-
"attempt to obtain type of assoc const binding `{hir_id}` before \
299-
it was resolved by `add_predicates_for_ast_type_binding`"
300-
));
301-
302-
ty::EarlyBinder::bind(ty::Binder::dummy(Ty::new_error(tcx, reported)))
303-
}
304-
305287
fn get_path_containing_arg_in_pat<'hir>(
306288
pat: &'hir hir::Pat<'hir>,
307289
arg_id: HirId,

compiler/rustc_middle/src/query/erase.rs

-4
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,6 @@ impl<T: EraseType> EraseType for ty::EarlyBinder<T> {
193193
type Result = T::Result;
194194
}
195195

196-
impl EraseType for ty::Binder<'_, Ty<'_>> {
197-
type Result = [u8; size_of::<ty::Binder<'static, Ty<'static>>>()];
198-
}
199-
200196
impl EraseType for ty::Binder<'_, ty::FnSig<'_>> {
201197
type Result = [u8; size_of::<ty::Binder<'static, ty::FnSig<'static>>>()];
202198
}

compiler/rustc_middle/src/query/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,6 @@ rustc_queries! {
248248
cycle_stash
249249
}
250250

251-
query type_of_assoc_const_binding(key: hir::HirId) -> ty::EarlyBinder<ty::Binder<'tcx, Ty<'tcx>>> {
252-
desc { |tcx| "getting type of associated constant binding `{key:?}`" }
253-
feedable
254-
}
255-
256251
query type_alias_is_lazy(key: DefId) -> bool {
257252
desc { |tcx|
258253
"computing whether `{path}` is a lazy type alias",

compiler/rustc_middle/src/ty/context.rs

-17
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ use rustc_type_ir::TyKind::*;
7171
use rustc_type_ir::WithCachedTypeInfo;
7272
use rustc_type_ir::{CollectAndApply, Interner, TypeFlags};
7373

74-
use std::assert_matches::debug_assert_matches;
7574
use std::borrow::Borrow;
7675
use std::cmp::Ordering;
7776
use std::fmt;
@@ -541,22 +540,6 @@ impl<'tcx> TyCtxt<'tcx> {
541540
debug_assert_eq!(self.def_kind(key), DefKind::AnonConst);
542541
TyCtxtFeed { tcx: self, key }.type_of(value)
543542
}
544-
545-
pub fn feed_type_of_assoc_const_binding(
546-
self,
547-
key: hir::HirId,
548-
value: ty::EarlyBinder<ty::Binder<'tcx, Ty<'tcx>>>,
549-
) {
550-
debug_assert_matches!(
551-
self.hir_node(key),
552-
hir::Node::TypeBinding(hir::TypeBinding {
553-
kind: hir::TypeBindingKind::Equality { term: hir::Term::Const(_) },
554-
..
555-
})
556-
);
557-
558-
TyCtxtFeed { tcx: self, key }.type_of_assoc_const_binding(value)
559-
}
560543
}
561544

562545
impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> {

0 commit comments

Comments
 (0)