diff --git a/compiler/rustc_hir_analysis/src/astconv/bounds.rs b/compiler/rustc_hir_analysis/src/astconv/bounds.rs index a9b4dca08d4..117df5482e6 100644 --- a/compiler/rustc_hir_analysis/src/astconv/bounds.rs +++ b/compiler/rustc_hir_analysis/src/astconv/bounds.rs @@ -434,11 +434,20 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Provide the resolved type of the associated constant to `type_of(AnonConst)`. if !speculative && let ty::AssocKind::Const = assoc_kind { + let hir::TypeBindingKind::Equality { term: hir::Term::Const(anon_const) } = + binding.kind + else { + bug!() + }; let ty = alias_ty.map_bound(|ty| tcx.type_of(ty.def_id).instantiate(tcx, ty.args)); // Since the arguments passed to the alias type above may contain early-bound // generic parameters, the instantiated type may contain some as well. // Therefore wrap it in `EarlyBinder`. - tcx.feed_type_of_assoc_const_binding(binding.hir_id, ty::EarlyBinder::bind(ty)); + // FIXME(fmease): Reject escaping late-bound vars. + tcx.feed_anon_const_type( + anon_const.def_id, + ty::EarlyBinder::bind(ty.skip_binder()), + ); } alias_ty diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index d82d3eccfc6..a5ef1490bce 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -63,7 +63,6 @@ pub fn provide(providers: &mut Providers) { *providers = Providers { type_of: type_of::type_of, type_of_opaque: type_of::type_of_opaque, - type_of_assoc_const_binding: type_of::type_of_assoc_const_binding, type_alias_is_lazy: type_of::type_alias_is_lazy, item_bounds: item_bounds::item_bounds, explicit_item_bounds: item_bounds::explicit_item_bounds, diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 57bcf7602ea..ddb02247d16 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -78,12 +78,6 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> { .expect("const parameter types cannot be generic"); } - Node::TypeBinding(&TypeBinding { hir_id, .. }) => { - // FIXME(fmease): Reject “escaping” early-bound generic parameters. - // FIXME(fmease): Reject escaping late-bound vars. - return tcx.type_of_assoc_const_binding(hir_id).skip_binder().skip_binder(); - } - // This match arm is for when the def_id appears in a GAT whose // path can't be resolved without typechecking e.g. // @@ -290,18 +284,6 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> { } } -pub(super) fn type_of_assoc_const_binding<'tcx>( - tcx: TyCtxt<'tcx>, - hir_id: HirId, -) -> ty::EarlyBinder>> { - let reported = tcx.dcx().delayed_bug(format!( - "attempt to obtain type of assoc const binding `{hir_id}` before \ - it was resolved by `add_predicates_for_ast_type_binding`" - )); - - ty::EarlyBinder::bind(ty::Binder::dummy(Ty::new_error(tcx, reported))) -} - fn get_path_containing_arg_in_pat<'hir>( pat: &'hir hir::Pat<'hir>, arg_id: HirId, diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index 82e0844a85c..2cdcdcb1492 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -193,10 +193,6 @@ impl EraseType for ty::EarlyBinder { type Result = T::Result; } -impl EraseType for ty::Binder<'_, Ty<'_>> { - type Result = [u8; size_of::>>()]; -} - impl EraseType for ty::Binder<'_, ty::FnSig<'_>> { type Result = [u8; size_of::>>()]; } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index ce1e3484d69..5be45c33e11 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -248,11 +248,6 @@ rustc_queries! { cycle_stash } - query type_of_assoc_const_binding(key: hir::HirId) -> ty::EarlyBinder>> { - desc { |tcx| "getting type of associated constant binding `{key:?}`" } - feedable - } - query type_alias_is_lazy(key: DefId) -> bool { desc { |tcx| "computing whether `{path}` is a lazy type alias", diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index acd68a5bd87..cc734e7157f 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -71,7 +71,6 @@ use rustc_type_ir::TyKind::*; use rustc_type_ir::WithCachedTypeInfo; use rustc_type_ir::{CollectAndApply, Interner, TypeFlags}; -use std::assert_matches::debug_assert_matches; use std::borrow::Borrow; use std::cmp::Ordering; use std::fmt; @@ -541,22 +540,6 @@ impl<'tcx> TyCtxt<'tcx> { debug_assert_eq!(self.def_kind(key), DefKind::AnonConst); TyCtxtFeed { tcx: self, key }.type_of(value) } - - pub fn feed_type_of_assoc_const_binding( - self, - key: hir::HirId, - value: ty::EarlyBinder>>, - ) { - debug_assert_matches!( - self.hir_node(key), - hir::Node::TypeBinding(hir::TypeBinding { - kind: hir::TypeBindingKind::Equality { term: hir::Term::Const(_) }, - .. - }) - ); - - TyCtxtFeed { tcx: self, key }.type_of_assoc_const_binding(value) - } } impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> {