@@ -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,6 +2435,7 @@ 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 }
24302441 ExprKind :: Tup ( exprs) => {
@@ -2442,7 +2453,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24422453 & * self . arena . alloc ( expr)
24432454 } ) ) ;
24442455
2445- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Tup ( expr . span , exprs) }
2456+ ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Tup ( exprs) , span }
24462457 }
24472458 ExprKind :: Path ( qself, path) => {
24482459 let qpath = self . lower_qpath (
@@ -2456,7 +2467,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24562467 None ,
24572468 ) ;
24582469
2459- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Path ( qpath) }
2470+ ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Path ( qpath) , span }
24602471 }
24612472 ExprKind :: Struct ( se) => {
24622473 let path = self . lower_qpath (
@@ -2497,11 +2508,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24972508 } )
24982509 } ) ) ;
24992510
2500- 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+ }
25012516 }
25022517 ExprKind :: Underscore => ConstArg {
25032518 hir_id : self . lower_node_id ( expr. id ) ,
2504- kind : hir:: ConstArgKind :: Infer ( expr. span , ( ) ) ,
2519+ kind : hir:: ConstArgKind :: Infer ( ( ) ) ,
2520+ span,
25052521 } ,
25062522 ExprKind :: Block ( block, _) => {
25072523 if let [ stmt] = block. stmts . as_slice ( )
@@ -2546,7 +2562,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25462562 return match anon. mgca_disambiguation {
25472563 MgcaDisambiguation :: AnonConst => {
25482564 let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2549- 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+ }
25502570 }
25512571 MgcaDisambiguation :: Direct => self . lower_expr_to_const_arg_direct ( & anon. value ) ,
25522572 } ;
@@ -2583,11 +2603,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25832603 return ConstArg {
25842604 hir_id : self . lower_node_id ( anon. id ) ,
25852605 kind : hir:: ConstArgKind :: Path ( qpath) ,
2606+ span : self . lower_span ( expr. span ) ,
25862607 } ;
25872608 }
25882609
25892610 let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2590- 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+ }
25912616 }
25922617
25932618 /// See [`hir::ConstArg`] for when to use this function vs
0 commit comments