@@ -2285,8 +2285,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22852285 // `ExprKind::Paren(ExprKind::Underscore)` and should also be lowered to `GenericArg::Infer`
22862286 match c. value . peel_parens ( ) . kind {
22872287 ExprKind :: Underscore => {
2288- let ct_kind = hir:: ConstArgKind :: Infer ( self . lower_span ( c. value . span ) , ( ) ) ;
2289- self . arena . alloc ( hir:: ConstArg { hir_id : self . lower_node_id ( c. id ) , kind : ct_kind } )
2288+ let ct_kind = hir:: ConstArgKind :: Infer ( ( ) ) ;
2289+ self . arena . alloc ( hir:: ConstArg {
2290+ hir_id : self . lower_node_id ( c. id ) ,
2291+ kind : ct_kind,
2292+ span : self . lower_span ( c. value . span ) ,
2293+ } )
22902294 }
22912295 _ => self . lower_anon_const_to_const_arg_and_alloc ( c) ,
22922296 }
@@ -2356,7 +2360,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23562360 hir:: ConstArgKind :: Anon ( ct)
23572361 } ;
23582362
2359- self . arena . alloc ( hir:: ConstArg { hir_id : self . next_id ( ) , kind : ct_kind } )
2363+ self . arena . alloc ( hir:: ConstArg {
2364+ hir_id : self . next_id ( ) ,
2365+ kind : ct_kind,
2366+ span : self . lower_span ( span) ,
2367+ } )
23602368 }
23612369
23622370 fn lower_const_item_rhs (
@@ -2373,9 +2381,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23732381 let const_arg = ConstArg {
23742382 hir_id : self . next_id ( ) ,
23752383 kind : hir:: ConstArgKind :: Error (
2376- DUMMY_SP ,
23772384 self . dcx ( ) . span_delayed_bug ( DUMMY_SP , "no block" ) ,
23782385 ) ,
2386+ span : DUMMY_SP ,
23792387 } ;
23802388 hir:: ConstItemRhs :: TypeConst ( self . arena . alloc ( const_arg) )
23812389 }
@@ -2388,13 +2396,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23882396
23892397 #[ instrument( level = "debug" , skip( self ) , ret) ]
23902398 fn lower_expr_to_const_arg_direct ( & mut self , expr : & Expr ) -> hir:: ConstArg < ' hir > {
2399+ let span = self . lower_span ( expr. span ) ;
2400+
23912401 let overly_complex_const = |this : & mut Self | {
23922402 let e = this. dcx ( ) . struct_span_err (
23932403 expr. span ,
23942404 "complex const arguments must be placed inside of a `const` block" ,
23952405 ) ;
23962406
2397- ConstArg { hir_id : this. next_id ( ) , kind : hir:: ConstArgKind :: Error ( expr . span , e. emit ( ) ) }
2407+ ConstArg { hir_id : this. next_id ( ) , kind : hir:: ConstArgKind :: Error ( e. emit ( ) ) , span }
23982408 } ;
23992409
24002410 match & expr. kind {
@@ -2425,8 +2435,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24252435 ConstArg {
24262436 hir_id : self . next_id ( ) ,
24272437 kind : hir:: ConstArgKind :: TupleCall ( qpath, lowered_args) ,
2438+ span,
24282439 }
24292440 }
2441+ ExprKind :: Tup ( exprs) => {
2442+ let exprs = self . arena . alloc_from_iter ( exprs. iter ( ) . map ( |expr| {
2443+ let expr = if let ExprKind :: ConstBlock ( anon_const) = & expr. kind {
2444+ let def_id = self . local_def_id ( anon_const. id ) ;
2445+ let def_kind = self . tcx . def_kind ( def_id) ;
2446+ assert_eq ! ( DefKind :: AnonConst , def_kind) ;
2447+
2448+ self . lower_anon_const_to_const_arg ( anon_const)
2449+ } else {
2450+ self . lower_expr_to_const_arg_direct ( & expr)
2451+ } ;
2452+
2453+ & * self . arena . alloc ( expr)
2454+ } ) ) ;
2455+
2456+ ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Tup ( exprs) , span }
2457+ }
24302458 ExprKind :: Path ( qself, path) => {
24312459 let qpath = self . lower_qpath (
24322460 expr. id ,
@@ -2439,7 +2467,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24392467 None ,
24402468 ) ;
24412469
2442- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Path ( qpath) }
2470+ ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Path ( qpath) , span }
24432471 }
24442472 ExprKind :: Struct ( se) => {
24452473 let path = self . lower_qpath (
@@ -2480,11 +2508,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24802508 } )
24812509 } ) ) ;
24822510
2483- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Struct ( path, fields) }
2511+ ConstArg {
2512+ hir_id : self . next_id ( ) ,
2513+ kind : hir:: ConstArgKind :: Struct ( path, fields) ,
2514+ span,
2515+ }
24842516 }
24852517 ExprKind :: Underscore => ConstArg {
24862518 hir_id : self . lower_node_id ( expr. id ) ,
2487- kind : hir:: ConstArgKind :: Infer ( expr. span , ( ) ) ,
2519+ kind : hir:: ConstArgKind :: Infer ( ( ) ) ,
2520+ span,
24882521 } ,
24892522 ExprKind :: Block ( block, _) => {
24902523 if let [ stmt] = block. stmts . as_slice ( )
@@ -2495,6 +2528,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24952528 | ExprKind :: Path ( ..)
24962529 | ExprKind :: Struct ( ..)
24972530 | ExprKind :: Call ( ..)
2531+ | ExprKind :: Tup ( ..)
24982532 )
24992533 {
25002534 return self . lower_expr_to_const_arg_direct ( expr) ;
@@ -2528,7 +2562,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25282562 return match anon. mgca_disambiguation {
25292563 MgcaDisambiguation :: AnonConst => {
25302564 let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2531- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Anon ( lowered_anon) }
2565+ ConstArg {
2566+ hir_id : self . next_id ( ) ,
2567+ kind : hir:: ConstArgKind :: Anon ( lowered_anon) ,
2568+ span : lowered_anon. span ,
2569+ }
25322570 }
25332571 MgcaDisambiguation :: Direct => self . lower_expr_to_const_arg_direct ( & anon. value ) ,
25342572 } ;
@@ -2565,11 +2603,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25652603 return ConstArg {
25662604 hir_id : self . lower_node_id ( anon. id ) ,
25672605 kind : hir:: ConstArgKind :: Path ( qpath) ,
2606+ span : self . lower_span ( expr. span ) ,
25682607 } ;
25692608 }
25702609
25712610 let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2572- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Anon ( lowered_anon) }
2611+ ConstArg {
2612+ hir_id : self . next_id ( ) ,
2613+ kind : hir:: ConstArgKind :: Anon ( lowered_anon) ,
2614+ span : self . lower_span ( expr. span ) ,
2615+ }
25732616 }
25742617
25752618 /// See [`hir::ConstArg`] for when to use this function vs
0 commit comments