mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
Use existing query feeding workarounds
This commit is contained in:
parent
8bb49e22b5
commit
b94498a378
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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<ty::Binder<'tcx, Ty<'tcx>>> {
|
||||
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,
|
||||
|
@ -193,10 +193,6 @@ impl<T: EraseType> EraseType for ty::EarlyBinder<T> {
|
||||
type Result = T::Result;
|
||||
}
|
||||
|
||||
impl EraseType for ty::Binder<'_, Ty<'_>> {
|
||||
type Result = [u8; size_of::<ty::Binder<'static, Ty<'static>>>()];
|
||||
}
|
||||
|
||||
impl EraseType for ty::Binder<'_, ty::FnSig<'_>> {
|
||||
type Result = [u8; size_of::<ty::Binder<'static, ty::FnSig<'static>>>()];
|
||||
}
|
||||
|
@ -248,11 +248,6 @@ rustc_queries! {
|
||||
cycle_stash
|
||||
}
|
||||
|
||||
query type_of_assoc_const_binding(key: hir::HirId) -> ty::EarlyBinder<ty::Binder<'tcx, Ty<'tcx>>> {
|
||||
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",
|
||||
|
@ -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<ty::Binder<'tcx, Ty<'tcx>>>,
|
||||
) {
|
||||
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> {
|
||||
|
Loading…
Reference in New Issue
Block a user