@@ -2283,8 +2283,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22832283 // `ExprKind::Paren(ExprKind::Underscore)` and should also be lowered to `GenericArg::Infer`
22842284 match c. value . peel_parens ( ) . kind {
22852285 ExprKind :: Underscore => {
2286- let ct_kind = hir:: ConstArgKind :: Infer ( self . lower_span ( c. value . span ) , ( ) ) ;
2287- self . arena . alloc ( hir:: ConstArg { hir_id : self . lower_node_id ( c. id ) , kind : ct_kind } )
2286+ let ct_kind = hir:: ConstArgKind :: Infer ( ( ) ) ;
2287+ self . arena . alloc ( hir:: ConstArg {
2288+ hir_id : self . lower_node_id ( c. id ) ,
2289+ kind : ct_kind,
2290+ span : self . lower_span ( c. value . span ) ,
2291+ } )
22882292 }
22892293 _ => self . lower_anon_const_to_const_arg ( c) ,
22902294 }
@@ -2354,7 +2358,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23542358 hir:: ConstArgKind :: Anon ( ct)
23552359 } ;
23562360
2357- self . arena . alloc ( hir:: ConstArg { hir_id : self . next_id ( ) , kind : ct_kind } )
2361+ self . arena . alloc ( hir:: ConstArg {
2362+ hir_id : self . next_id ( ) ,
2363+ kind : ct_kind,
2364+ span : self . lower_span ( span) ,
2365+ } )
23582366 }
23592367
23602368 fn lower_const_item_rhs (
@@ -2371,9 +2379,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23712379 let const_arg = ConstArg {
23722380 hir_id : self . next_id ( ) ,
23732381 kind : hir:: ConstArgKind :: Error (
2374- DUMMY_SP ,
23752382 self . dcx ( ) . span_delayed_bug ( DUMMY_SP , "no block" ) ,
23762383 ) ,
2384+ span : DUMMY_SP ,
23772385 } ;
23782386 hir:: ConstItemRhs :: TypeConst ( self . arena . alloc ( const_arg) )
23792387 }
@@ -2386,13 +2394,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23862394
23872395 #[ instrument( level = "debug" , skip( self ) , ret) ]
23882396 fn lower_expr_to_const_arg_direct ( & mut self , expr : & Expr ) -> hir:: ConstArg < ' hir > {
2397+ let span = self . lower_span ( expr. span ) ;
2398+
23892399 let overly_complex_const = |this : & mut Self | {
23902400 let e = this. dcx ( ) . struct_span_err (
23912401 expr. span ,
23922402 "complex const arguments must be placed inside of a `const` block" ,
23932403 ) ;
23942404
2395- ConstArg { hir_id : this. next_id ( ) , kind : hir:: ConstArgKind :: Error ( expr . span , e. emit ( ) ) }
2405+ ConstArg { hir_id : this. next_id ( ) , kind : hir:: ConstArgKind :: Error ( e. emit ( ) ) , span }
23962406 } ;
23972407
23982408 match & expr. kind {
@@ -2423,6 +2433,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24232433 ConstArg {
24242434 hir_id : self . next_id ( ) ,
24252435 kind : hir:: ConstArgKind :: TupleCall ( qpath, lowered_args) ,
2436+ span,
24262437 }
24272438 }
24282439 ExprKind :: Tup ( exprs) => {
@@ -2440,7 +2451,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24402451 & * self . arena . alloc ( expr)
24412452 } ) ) ;
24422453
2443- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Tup ( expr . span , exprs) }
2454+ ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Tup ( exprs) , span }
24442455 }
24452456 ExprKind :: Path ( qself, path) => {
24462457 let qpath = self . lower_qpath (
@@ -2454,7 +2465,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24542465 None ,
24552466 ) ;
24562467
2457- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Path ( qpath) }
2468+ ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Path ( qpath) , span }
24582469 }
24592470 ExprKind :: Struct ( se) => {
24602471 let path = self . lower_qpath (
@@ -2495,11 +2506,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24952506 } )
24962507 } ) ) ;
24972508
2498- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Struct ( path, fields) }
2509+ ConstArg {
2510+ hir_id : self . next_id ( ) ,
2511+ kind : hir:: ConstArgKind :: Struct ( path, fields) ,
2512+ span,
2513+ }
24992514 }
25002515 ExprKind :: Underscore => ConstArg {
25012516 hir_id : self . lower_node_id ( expr. id ) ,
2502- kind : hir:: ConstArgKind :: Infer ( expr. span , ( ) ) ,
2517+ kind : hir:: ConstArgKind :: Infer ( ( ) ) ,
2518+ span,
25032519 } ,
25042520 ExprKind :: Block ( block, _) => {
25052521 if let [ stmt] = block. stmts . as_slice ( )
@@ -2541,7 +2557,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25412557 return match anon. mgca_disambiguation {
25422558 MgcaDisambiguation :: AnonConst => {
25432559 let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2544- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Anon ( lowered_anon) }
2560+ ConstArg {
2561+ hir_id : self . next_id ( ) ,
2562+ kind : hir:: ConstArgKind :: Anon ( lowered_anon) ,
2563+ span : lowered_anon. span ,
2564+ }
25452565 }
25462566 MgcaDisambiguation :: Direct => self . lower_expr_to_const_arg_direct ( & anon. value ) ,
25472567 } ;
@@ -2578,11 +2598,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25782598 return ConstArg {
25792599 hir_id : self . lower_node_id ( anon. id ) ,
25802600 kind : hir:: ConstArgKind :: Path ( qpath) ,
2601+ span : self . lower_span ( expr. span ) ,
25812602 } ;
25822603 }
25832604
25842605 let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2585- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Anon ( lowered_anon) }
2606+ ConstArg {
2607+ hir_id : self . next_id ( ) ,
2608+ kind : hir:: ConstArgKind :: Anon ( lowered_anon) ,
2609+ span : self . lower_span ( expr. span ) ,
2610+ }
25862611 }
25872612
25882613 /// See [`hir::ConstArg`] for when to use this function vs
0 commit comments