@@ -2425,15 +2425,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24252425 ) ;
24262426
24272427 let lowered_args = self . arena . alloc_from_iter ( args. iter ( ) . map ( |arg| {
2428- let const_arg = if let ExprKind :: ConstBlock ( anon_const) = & arg. kind {
2429- let def_id = self . local_def_id ( anon_const. id ) ;
2430- let def_kind = self . tcx . def_kind ( def_id) ;
2431- assert_eq ! ( DefKind :: AnonConst , def_kind) ;
2432- self . lower_anon_const_to_const_arg ( anon_const)
2433- } else {
2434- self . lower_expr_to_const_arg_direct ( arg)
2435- } ;
2436-
2428+ let const_arg = self . lower_expr_to_const_arg_direct ( arg) ;
24372429 & * self . arena . alloc ( const_arg)
24382430 } ) ) ;
24392431
@@ -2445,16 +2437,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24452437 }
24462438 ExprKind :: Tup ( exprs) => {
24472439 let exprs = self . arena . alloc_from_iter ( exprs. iter ( ) . map ( |expr| {
2448- let expr = if let ExprKind :: ConstBlock ( anon_const) = & expr. kind {
2449- let def_id = self . local_def_id ( anon_const. id ) ;
2450- let def_kind = self . tcx . def_kind ( def_id) ;
2451- assert_eq ! ( DefKind :: AnonConst , def_kind) ;
2452-
2453- self . lower_anon_const_to_const_arg ( anon_const)
2454- } else {
2455- self . lower_expr_to_const_arg_direct ( & expr)
2456- } ;
2457-
2440+ let expr = self . lower_expr_to_const_arg_direct ( & expr) ;
24582441 & * self . arena . alloc ( expr)
24592442 } ) ) ;
24602443
@@ -2494,16 +2477,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24942477 // then go unused as the `Target::ExprField` is not actually
24952478 // corresponding to `Node::ExprField`.
24962479 self . lower_attrs ( hir_id, & f. attrs , f. span , Target :: ExprField ) ;
2497-
2498- let expr = if let ExprKind :: ConstBlock ( anon_const) = & f. expr . kind {
2499- let def_id = self . local_def_id ( anon_const. id ) ;
2500- let def_kind = self . tcx . def_kind ( def_id) ;
2501- assert_eq ! ( DefKind :: AnonConst , def_kind) ;
2502-
2503- self . lower_anon_const_to_const_arg ( anon_const)
2504- } else {
2505- self . lower_expr_to_const_arg_direct ( & f. expr )
2506- } ;
2480+ let expr = self . lower_expr_to_const_arg_direct ( & f. expr ) ;
25072481
25082482 & * self . arena . alloc ( hir:: ConstArgExprField {
25092483 hir_id,
@@ -2521,13 +2495,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25212495 }
25222496 ExprKind :: Array ( elements) => {
25232497 let lowered_elems = self . arena . alloc_from_iter ( elements. iter ( ) . map ( |element| {
2524- let const_arg = if let ExprKind :: ConstBlock ( anon_const) = & element. kind {
2525- let def_id = self . local_def_id ( anon_const. id ) ;
2526- assert_eq ! ( DefKind :: AnonConst , self . tcx. def_kind( def_id) ) ;
2527- self . lower_anon_const_to_const_arg ( anon_const)
2528- } else {
2529- self . lower_expr_to_const_arg_direct ( element)
2530- } ;
2498+ let const_arg = self . lower_expr_to_const_arg_direct ( element) ;
25312499 & * self . arena . alloc ( const_arg)
25322500 } ) ) ;
25332501 let array_expr = self . arena . alloc ( hir:: ConstArgArrayExpr {
@@ -2557,6 +2525,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25572525 | ExprKind :: Call ( ..)
25582526 | ExprKind :: Tup ( ..)
25592527 | ExprKind :: Array ( ..)
2528+ | ExprKind :: ConstBlock ( ..)
25602529 )
25612530 {
25622531 return self . lower_expr_to_const_arg_direct ( expr) ;
@@ -2574,6 +2543,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25742543 span,
25752544 }
25762545 }
2546+ ExprKind :: ConstBlock ( anon_const) => {
2547+ let def_id = self . local_def_id ( anon_const. id ) ;
2548+ assert_eq ! ( DefKind :: AnonConst , self . tcx. def_kind( def_id) ) ;
2549+ self . lower_anon_const_to_const_arg ( anon_const, span)
2550+ }
25772551 _ => overly_complex_const ( self ) ,
25782552 }
25792553 }
@@ -2584,11 +2558,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25842558 & mut self ,
25852559 anon : & AnonConst ,
25862560 ) -> & ' hir hir:: ConstArg < ' hir > {
2587- self . arena . alloc ( self . lower_anon_const_to_const_arg ( anon) )
2561+ self . arena . alloc ( self . lower_anon_const_to_const_arg ( anon, anon . value . span ) )
25882562 }
25892563
25902564 #[ instrument( level = "debug" , skip( self ) ) ]
2591- fn lower_anon_const_to_const_arg ( & mut self , anon : & AnonConst ) -> hir:: ConstArg < ' hir > {
2565+ fn lower_anon_const_to_const_arg (
2566+ & mut self ,
2567+ anon : & AnonConst ,
2568+ span : Span ,
2569+ ) -> hir:: ConstArg < ' hir > {
25922570 let tcx = self . tcx ;
25932571
25942572 // We cannot change parsing depending on feature gates available,
@@ -2599,7 +2577,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25992577 if tcx. features ( ) . min_generic_const_args ( ) {
26002578 return match anon. mgca_disambiguation {
26012579 MgcaDisambiguation :: AnonConst => {
2602- let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2580+ let lowered_anon = self . lower_anon_const_to_anon_const ( anon, span ) ;
26032581 ConstArg {
26042582 hir_id : self . next_id ( ) ,
26052583 kind : hir:: ConstArgKind :: Anon ( lowered_anon) ,
@@ -2645,7 +2623,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26452623 } ;
26462624 }
26472625
2648- let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2626+ let lowered_anon = self . lower_anon_const_to_anon_const ( anon, anon . value . span ) ;
26492627 ConstArg {
26502628 hir_id : self . next_id ( ) ,
26512629 kind : hir:: ConstArgKind :: Anon ( lowered_anon) ,
@@ -2655,15 +2633,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26552633
26562634 /// See [`hir::ConstArg`] for when to use this function vs
26572635 /// [`Self::lower_anon_const_to_const_arg`].
2658- fn lower_anon_const_to_anon_const ( & mut self , c : & AnonConst ) -> & ' hir hir:: AnonConst {
2636+ fn lower_anon_const_to_anon_const (
2637+ & mut self ,
2638+ c : & AnonConst ,
2639+ span : Span ,
2640+ ) -> & ' hir hir:: AnonConst {
26592641 self . arena . alloc ( self . with_new_scopes ( c. value . span , |this| {
26602642 let def_id = this. local_def_id ( c. id ) ;
26612643 let hir_id = this. lower_node_id ( c. id ) ;
26622644 hir:: AnonConst {
26632645 def_id,
26642646 hir_id,
26652647 body : this. lower_const_body ( c. value . span , Some ( & c. value ) ) ,
2666- span : this. lower_span ( c . value . span ) ,
2648+ span : this. lower_span ( span) ,
26672649 }
26682650 } ) )
26692651 }
0 commit comments