Skip to content

Commit 80a3ebb

Browse files
committed
[feed type of assoc const binding]
1 parent 675dae4 commit 80a3ebb

File tree

4 files changed

+22
-30
lines changed

4 files changed

+22
-30
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,16 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
424424
// FIXME(fmease): Explain that we are indeed constructing an alias "type" for
425425
// associated constants with feature `associated_const_equality` and that we
426426
// call them "const projections".
427-
ty::AliasTy::new(tcx, assoc_item.def_id, args_trait_ref_and_assoc_item)
427+
let alias_ty =
428+
ty::AliasTy::new(tcx, assoc_item.def_id, args_trait_ref_and_assoc_item);
429+
430+
if let ty::AssocKind::Const = assoc_kind {
431+
// FIXME(fmease): We're completely ignoring bound vars here!
432+
let ty = tcx.type_of(alias_ty.def_id).instantiate(tcx, alias_ty.args);
433+
tcx.feed_type_of_assoc_const_binding(binding.hir_id, ty);
434+
}
435+
436+
alias_ty
428437
})
429438
};
430439

compiler/rustc_hir_analysis/src/collect/type_of.rs

+2-29
Original file line numberDiff line numberDiff line change
@@ -66,35 +66,8 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
6666
.expect("const parameter types cannot be generic");
6767
}
6868

69-
Node::TypeBinding(binding @ &TypeBinding { hir_id: binding_id, .. })
70-
if let Node::TraitRef(trait_ref) = tcx.hir_node(tcx.hir().parent_id(binding_id)) =>
71-
{
72-
let Some(trait_def_id) = trait_ref.trait_def_id() else {
73-
return Ty::new_error_with_message(
74-
tcx,
75-
tcx.def_span(def_id),
76-
"Could not find trait",
77-
);
78-
};
79-
let assoc_items = tcx.associated_items(trait_def_id);
80-
let assoc_item = assoc_items.find_by_name_and_kind(
81-
tcx,
82-
binding.ident,
83-
ty::AssocKind::Const,
84-
def_id.to_def_id(),
85-
);
86-
return if let Some(assoc_item) = assoc_item {
87-
tcx.type_of(assoc_item.def_id)
88-
.no_bound_vars()
89-
.expect("const parameter types cannot be generic")
90-
} else {
91-
// FIXME(associated_const_equality): add a useful error message here.
92-
Ty::new_error_with_message(
93-
tcx,
94-
tcx.def_span(def_id),
95-
"Could not find associated const on trait",
96-
)
97-
};
69+
Node::TypeBinding(&TypeBinding { hir_id, .. }) => {
70+
return tcx.type_of_assoc_const_binding(hir_id);
9871
}
9972

10073
// This match arm is for when the def_id appears in a GAT whose

compiler/rustc_middle/src/query/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ rustc_queries! {
255255
cycle_stash
256256
}
257257

258+
// FIXME(fmease): docs
259+
query type_of_assoc_const_binding(key: hir::HirId) -> Ty<'tcx> {
260+
desc { |tcx| "computing type of associated constant binding `{key:?}`" }
261+
feedable
262+
}
263+
258264
query type_alias_is_lazy(key: DefId) -> bool {
259265
desc { |tcx|
260266
"computing whether `{path}` is a lazy type alias",

compiler/rustc_middle/src/ty/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ impl<'tcx> TyCtxt<'tcx> {
533533
debug_assert_eq!(self.def_kind(key), DefKind::AnonConst);
534534
TyCtxtFeed { tcx: self, key }.type_of(value)
535535
}
536+
537+
pub fn feed_type_of_assoc_const_binding(self, key: hir::HirId, value: Ty<'tcx>) {
538+
TyCtxtFeed { tcx: self, key }.type_of_assoc_const_binding(value)
539+
}
536540
}
537541

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

0 commit comments

Comments
 (0)