@@ -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) ;
@@ -2586,6 +2555,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25862555 span,
25872556 }
25882557 }
2558+ ExprKind :: ConstBlock ( anon_const) => {
2559+ let def_id = self . local_def_id ( anon_const. id ) ;
2560+ assert_eq ! ( DefKind :: AnonConst , self . tcx. def_kind( def_id) ) ;
2561+ self . lower_anon_const_to_const_arg ( anon_const, span)
2562+ }
25892563 _ => overly_complex_const ( self ) ,
25902564 }
25912565 }
@@ -2596,11 +2570,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25962570 & mut self ,
25972571 anon : & AnonConst ,
25982572 ) -> & ' hir hir:: ConstArg < ' hir > {
2599- self . arena . alloc ( self . lower_anon_const_to_const_arg ( anon) )
2573+ self . arena . alloc ( self . lower_anon_const_to_const_arg ( anon, anon . value . span ) )
26002574 }
26012575
26022576 #[ instrument( level = "debug" , skip( self ) ) ]
2603- fn lower_anon_const_to_const_arg ( & mut self , anon : & AnonConst ) -> hir:: ConstArg < ' hir > {
2577+ fn lower_anon_const_to_const_arg (
2578+ & mut self ,
2579+ anon : & AnonConst ,
2580+ span : Span ,
2581+ ) -> hir:: ConstArg < ' hir > {
26042582 let tcx = self . tcx ;
26052583
26062584 // We cannot change parsing depending on feature gates available,
@@ -2611,7 +2589,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26112589 if tcx. features ( ) . min_generic_const_args ( ) {
26122590 return match anon. mgca_disambiguation {
26132591 MgcaDisambiguation :: AnonConst => {
2614- let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2592+ let lowered_anon = self . lower_anon_const_to_anon_const ( anon, span ) ;
26152593 ConstArg {
26162594 hir_id : self . next_id ( ) ,
26172595 kind : hir:: ConstArgKind :: Anon ( lowered_anon) ,
@@ -2657,7 +2635,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26572635 } ;
26582636 }
26592637
2660- let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2638+ let lowered_anon = self . lower_anon_const_to_anon_const ( anon, anon . value . span ) ;
26612639 ConstArg {
26622640 hir_id : self . next_id ( ) ,
26632641 kind : hir:: ConstArgKind :: Anon ( lowered_anon) ,
@@ -2667,15 +2645,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26672645
26682646 /// See [`hir::ConstArg`] for when to use this function vs
26692647 /// [`Self::lower_anon_const_to_const_arg`].
2670- fn lower_anon_const_to_anon_const ( & mut self , c : & AnonConst ) -> & ' hir hir:: AnonConst {
2648+ fn lower_anon_const_to_anon_const (
2649+ & mut self ,
2650+ c : & AnonConst ,
2651+ span : Span ,
2652+ ) -> & ' hir hir:: AnonConst {
26712653 self . arena . alloc ( self . with_new_scopes ( c. value . span , |this| {
26722654 let def_id = this. local_def_id ( c. id ) ;
26732655 let hir_id = this. lower_node_id ( c. id ) ;
26742656 hir:: AnonConst {
26752657 def_id,
26762658 hir_id,
26772659 body : this. lower_const_body ( c. value . span , Some ( & c. value ) ) ,
2678- span : this. lower_span ( c . value . span ) ,
2660+ span : this. lower_span ( span) ,
26792661 }
26802662 } ) )
26812663 }
0 commit comments