@@ -354,7 +354,11 @@ fn anon_const_type_of<'tcx>(icx: &ItemCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx
354354 hir_id : arg_hir_id,
355355 kind : ConstArgKind :: Anon ( & AnonConst { hir_id : anon_hir_id, .. } ) ,
356356 ..
357- } ) if anon_hir_id == hir_id => const_arg_anon_type_of ( icx, arg_hir_id, span) ,
357+ } ) if anon_hir_id == hir_id => Ty :: new_error_with_message (
358+ tcx,
359+ span,
360+ "`type_of` called on const argument's anon const before the const argument was lowered" ,
361+ ) ,
358362
359363 Node :: Variant ( Variant { disr_expr : Some ( e) , .. } ) if e. hir_id == hir_id => {
360364 tcx. adt_def ( tcx. hir_get_parent_item ( hir_id) ) . repr ( ) . discr_type ( ) . to_ty ( tcx)
@@ -374,42 +378,6 @@ fn anon_const_type_of<'tcx>(icx: &ItemCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx
374378 }
375379}
376380
377- fn const_arg_anon_type_of < ' tcx > ( icx : & ItemCtxt < ' tcx > , arg_hir_id : HirId , span : Span ) -> Ty < ' tcx > {
378- use hir:: * ;
379- use rustc_middle:: ty:: Ty ;
380-
381- let tcx = icx. tcx ;
382-
383- match tcx. parent_hir_node ( arg_hir_id) {
384- // Array length const arguments do not have `type_of` fed as there is never a corresponding
385- // generic parameter definition.
386- Node :: Ty ( & hir:: Ty { kind : TyKind :: Array ( _, ref constant) , .. } )
387- | Node :: Expr ( & Expr { kind : ExprKind :: Repeat ( _, ref constant) , .. } )
388- if constant. hir_id == arg_hir_id =>
389- {
390- tcx. types . usize
391- }
392-
393- Node :: TyPat ( pat) => {
394- let node = match tcx. parent_hir_node ( pat. hir_id ) {
395- // Or patterns can be nested one level deep
396- Node :: TyPat ( p) => tcx. parent_hir_node ( p. hir_id ) ,
397- other => other,
398- } ;
399- let hir:: TyKind :: Pat ( ty, _) = node. expect_ty ( ) . kind else { bug ! ( ) } ;
400- icx. lower_ty ( ty)
401- }
402-
403- // This is not a `bug!` as const arguments in path segments that did not resolve to anything
404- // will result in `type_of` never being fed.
405- _ => Ty :: new_error_with_message (
406- tcx,
407- span,
408- "`type_of` called on const argument's anon const before the const argument was lowered" ,
409- ) ,
410- }
411- }
412-
413381fn infer_placeholder_type < ' tcx > (
414382 cx : & dyn HirTyLowerer < ' tcx > ,
415383 def_id : LocalDefId ,
0 commit comments