@@ -78,35 +78,10 @@ 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 ( binding @ & TypeBinding { hir_id : binding_id, .. } )
82- if let Node :: TraitRef ( trait_ref) = tcx. parent_hir_node ( binding_id) =>
83- {
84- let Some ( trait_def_id) = trait_ref. trait_def_id ( ) else {
85- return Ty :: new_error_with_message (
86- tcx,
87- tcx. def_span ( def_id) ,
88- "Could not find trait" ,
89- ) ;
90- } ;
91- let assoc_items = tcx. associated_items ( trait_def_id) ;
92- let assoc_item = assoc_items. find_by_name_and_kind (
93- tcx,
94- binding. ident ,
95- ty:: AssocKind :: Const ,
96- def_id. to_def_id ( ) ,
97- ) ;
98- return if let Some ( assoc_item) = assoc_item {
99- tcx. type_of ( assoc_item. def_id )
100- . no_bound_vars ( )
101- . expect ( "const parameter types cannot be generic" )
102- } else {
103- // FIXME(associated_const_equality): add a useful error message here.
104- Ty :: new_error_with_message (
105- tcx,
106- tcx. def_span ( def_id) ,
107- "Could not find associated const on trait" ,
108- )
109- } ;
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 ( ) ;
11085 }
11186
11287 // This match arm is for when the def_id appears in a GAT whose
@@ -315,6 +290,18 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
315290 }
316291}
317292
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+
318305fn get_path_containing_arg_in_pat < ' hir > (
319306 pat : & ' hir hir:: Pat < ' hir > ,
320307 arg_id : HirId ,
0 commit comments