@@ -66,35 +66,10 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
66
66
. expect ( "const parameter types cannot be generic" ) ;
67
67
}
68
68
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
+ // FIXME(fmease): Reject “escaping” early-bound generic parameters.
71
+ // FIXME(fmease): Reject escaping late-bound vars.
72
+ return tcx. type_of_assoc_const_binding ( hir_id) . skip_binder ( ) . skip_binder ( ) ;
98
73
}
99
74
100
75
// This match arm is for when the def_id appears in a GAT whose
@@ -303,6 +278,21 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
303
278
}
304
279
}
305
280
281
+ pub ( super ) fn type_of_assoc_const_binding < ' tcx > (
282
+ tcx : TyCtxt < ' tcx > ,
283
+ hir_id : HirId ,
284
+ ) -> ty:: EarlyBinder < ty:: Binder < ' tcx , Ty < ' tcx > > > {
285
+ let guar = tcx. dcx ( ) . span_delayed_bug (
286
+ rustc_span:: DUMMY_SP ,
287
+ format ! (
288
+ "attempt to obtain type of assoc const binding `{hir_id}` before \
289
+ it was resolved by `add_predicates_for_ast_type_binding`"
290
+ ) ,
291
+ ) ;
292
+
293
+ ty:: EarlyBinder :: bind ( ty:: Binder :: dummy ( Ty :: new_error ( tcx, guar) ) )
294
+ }
295
+
306
296
fn get_path_containing_arg_in_pat < ' hir > (
307
297
pat : & ' hir hir:: Pat < ' hir > ,
308
298
arg_id : HirId ,
0 commit comments