@@ -1986,8 +1986,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19861986 let ( name, kind) = self . lower_generic_param_kind ( param, source) ;
19871987
19881988 let hir_id = self . lower_node_id ( param. id ) ;
1989- self . lower_attrs ( hir_id, & param. attrs , param. span ( ) , Target :: Param ) ;
1990- hir:: GenericParam {
1989+ let param_attrs = & param. attrs ;
1990+ let param_span = param. span ( ) ;
1991+ let param = hir:: GenericParam {
19911992 hir_id,
19921993 def_id : self . local_def_id ( param. id ) ,
19931994 name,
@@ -1996,7 +1997,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19961997 kind,
19971998 colon_span : param. colon_span . map ( |s| self . lower_span ( s) ) ,
19981999 source,
1999- }
2000+ } ;
2001+ self . lower_attrs ( hir_id, param_attrs, param_span, Target :: from_generic_param ( & param) ) ;
2002+ param
20002003 }
20012004
20022005 fn lower_generic_param_kind (
@@ -2285,8 +2288,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22852288 // `ExprKind::Paren(ExprKind::Underscore)` and should also be lowered to `GenericArg::Infer`
22862289 match c. value . peel_parens ( ) . kind {
22872290 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 } )
2291+ let ct_kind = hir:: ConstArgKind :: Infer ( ( ) ) ;
2292+ self . arena . alloc ( hir:: ConstArg {
2293+ hir_id : self . lower_node_id ( c. id ) ,
2294+ kind : ct_kind,
2295+ span : self . lower_span ( c. value . span ) ,
2296+ } )
22902297 }
22912298 _ => self . lower_anon_const_to_const_arg_and_alloc ( c) ,
22922299 }
@@ -2356,7 +2363,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23562363 hir:: ConstArgKind :: Anon ( ct)
23572364 } ;
23582365
2359- self . arena . alloc ( hir:: ConstArg { hir_id : self . next_id ( ) , kind : ct_kind } )
2366+ self . arena . alloc ( hir:: ConstArg {
2367+ hir_id : self . next_id ( ) ,
2368+ kind : ct_kind,
2369+ span : self . lower_span ( span) ,
2370+ } )
23602371 }
23612372
23622373 fn lower_const_item_rhs (
@@ -2373,9 +2384,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23732384 let const_arg = ConstArg {
23742385 hir_id : self . next_id ( ) ,
23752386 kind : hir:: ConstArgKind :: Error (
2376- DUMMY_SP ,
23772387 self . dcx ( ) . span_delayed_bug ( DUMMY_SP , "no block" ) ,
23782388 ) ,
2389+ span : DUMMY_SP ,
23792390 } ;
23802391 hir:: ConstItemRhs :: TypeConst ( self . arena . alloc ( const_arg) )
23812392 }
@@ -2388,13 +2399,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23882399
23892400 #[ instrument( level = "debug" , skip( self ) , ret) ]
23902401 fn lower_expr_to_const_arg_direct ( & mut self , expr : & Expr ) -> hir:: ConstArg < ' hir > {
2402+ let span = self . lower_span ( expr. span ) ;
2403+
23912404 let overly_complex_const = |this : & mut Self | {
23922405 let e = this. dcx ( ) . struct_span_err (
23932406 expr. span ,
23942407 "complex const arguments must be placed inside of a `const` block" ,
23952408 ) ;
23962409
2397- ConstArg { hir_id : this. next_id ( ) , kind : hir:: ConstArgKind :: Error ( expr . span , e. emit ( ) ) }
2410+ ConstArg { hir_id : this. next_id ( ) , kind : hir:: ConstArgKind :: Error ( e. emit ( ) ) , span }
23982411 } ;
23992412
24002413 match & expr. kind {
@@ -2425,8 +2438,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24252438 ConstArg {
24262439 hir_id : self . next_id ( ) ,
24272440 kind : hir:: ConstArgKind :: TupleCall ( qpath, lowered_args) ,
2441+ span,
24282442 }
24292443 }
2444+ ExprKind :: Tup ( exprs) => {
2445+ let exprs = self . arena . alloc_from_iter ( exprs. iter ( ) . map ( |expr| {
2446+ let expr = if let ExprKind :: ConstBlock ( anon_const) = & expr. kind {
2447+ let def_id = self . local_def_id ( anon_const. id ) ;
2448+ let def_kind = self . tcx . def_kind ( def_id) ;
2449+ assert_eq ! ( DefKind :: AnonConst , def_kind) ;
2450+
2451+ self . lower_anon_const_to_const_arg ( anon_const)
2452+ } else {
2453+ self . lower_expr_to_const_arg_direct ( & expr)
2454+ } ;
2455+
2456+ & * self . arena . alloc ( expr)
2457+ } ) ) ;
2458+
2459+ ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Tup ( exprs) , span }
2460+ }
24302461 ExprKind :: Path ( qself, path) => {
24312462 let qpath = self . lower_qpath (
24322463 expr. id ,
@@ -2439,7 +2470,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24392470 None ,
24402471 ) ;
24412472
2442- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Path ( qpath) }
2473+ ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Path ( qpath) , span }
24432474 }
24442475 ExprKind :: Struct ( se) => {
24452476 let path = self . lower_qpath (
@@ -2480,11 +2511,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24802511 } )
24812512 } ) ) ;
24822513
2483- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Struct ( path, fields) }
2514+ ConstArg {
2515+ hir_id : self . next_id ( ) ,
2516+ kind : hir:: ConstArgKind :: Struct ( path, fields) ,
2517+ span,
2518+ }
24842519 }
24852520 ExprKind :: Underscore => ConstArg {
24862521 hir_id : self . lower_node_id ( expr. id ) ,
2487- kind : hir:: ConstArgKind :: Infer ( expr. span , ( ) ) ,
2522+ kind : hir:: ConstArgKind :: Infer ( ( ) ) ,
2523+ span,
24882524 } ,
24892525 ExprKind :: Block ( block, _) => {
24902526 if let [ stmt] = block. stmts . as_slice ( )
@@ -2495,13 +2531,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24952531 | ExprKind :: Path ( ..)
24962532 | ExprKind :: Struct ( ..)
24972533 | ExprKind :: Call ( ..)
2534+ | ExprKind :: Tup ( ..)
24982535 )
24992536 {
25002537 return self . lower_expr_to_const_arg_direct ( expr) ;
25012538 }
25022539
25032540 overly_complex_const ( self )
25042541 }
2542+ ExprKind :: Lit ( literal) => {
2543+ let span = expr. span ;
2544+ let literal = self . lower_lit ( literal, span) ;
2545+
2546+ ConstArg {
2547+ hir_id : self . lower_node_id ( expr. id ) ,
2548+ kind : hir:: ConstArgKind :: Literal ( literal. node ) ,
2549+ span,
2550+ }
2551+ }
25052552 _ => overly_complex_const ( self ) ,
25062553 }
25072554 }
@@ -2528,7 +2575,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25282575 return match anon. mgca_disambiguation {
25292576 MgcaDisambiguation :: AnonConst => {
25302577 let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2531- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Anon ( lowered_anon) }
2578+ ConstArg {
2579+ hir_id : self . next_id ( ) ,
2580+ kind : hir:: ConstArgKind :: Anon ( lowered_anon) ,
2581+ span : lowered_anon. span ,
2582+ }
25322583 }
25332584 MgcaDisambiguation :: Direct => self . lower_expr_to_const_arg_direct ( & anon. value ) ,
25342585 } ;
@@ -2565,11 +2616,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25652616 return ConstArg {
25662617 hir_id : self . lower_node_id ( anon. id ) ,
25672618 kind : hir:: ConstArgKind :: Path ( qpath) ,
2619+ span : self . lower_span ( expr. span ) ,
25682620 } ;
25692621 }
25702622
25712623 let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2572- ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Anon ( lowered_anon) }
2624+ ConstArg {
2625+ hir_id : self . next_id ( ) ,
2626+ kind : hir:: ConstArgKind :: Anon ( lowered_anon) ,
2627+ span : self . lower_span ( expr. span ) ,
2628+ }
25732629 }
25742630
25752631 /// See [`hir::ConstArg`] for when to use this function vs
0 commit comments