@@ -199,6 +199,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
199199 ident,
200200 generics,
201201 ty,
202+ body_id,
202203 expr,
203204 define_opaque,
204205 ..
@@ -211,7 +212,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
211212 |this| {
212213 let ty = this
213214 . lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
214- ( ty, this. lower_const_item ( span, expr. as_deref ( ) ) )
215+ ( ty, this. lower_const_item ( span, body_id . zip ( expr. as_deref ( ) ) ) )
215216 } ,
216217 ) ;
217218 self . lower_define_opaque ( hir_id, & define_opaque) ;
@@ -498,15 +499,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
498499 fn lower_const_item (
499500 & mut self ,
500501 span : Span ,
501- body : Option < & Expr > ,
502+ body : Option < ( NodeId , & Expr ) > ,
502503 ) -> ( hir:: BodyId , Option < & ' hir hir:: ConstArg < ' hir > > ) {
503504 let mgca = self . tcx . features ( ) . min_generic_const_args ( ) ;
504- let ct_arg =
505- if mgca && let Some ( expr) = body { self . try_lower_as_const_path ( expr) } else { None } ;
505+ let ct_arg = if mgca && let Some ( ( _, expr) ) = body {
506+ self . try_lower_as_const_path ( expr)
507+ } else {
508+ None
509+ } ;
506510 let body_id = if mgca && ct_arg. is_none ( ) {
507511 self . lower_const_body_with_const_block ( span, body)
508512 } else {
509- self . lower_const_body ( span, body)
513+ self . lower_const_body ( span, body. map ( | ( _ , e ) | e ) )
510514 } ;
511515 ( body_id, ct_arg)
512516 }
@@ -809,6 +813,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
809813 ident,
810814 generics,
811815 ty,
816+ body_id,
812817 expr,
813818 define_opaque,
814819 ..
@@ -820,7 +825,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
820825 |this| {
821826 let ty = this
822827 . lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
823- match expr. as_deref ( ) . map ( |e| this. lower_const_item ( i. span , Some ( e) ) ) {
828+ let lowered_body = expr
829+ . as_deref ( )
830+ . map ( |e| this. lower_const_item ( i. span , Some ( ( body_id. unwrap ( ) , e) ) ) ) ;
831+ match lowered_body {
824832 Some ( ( body, ct_arg) ) => {
825833 hir:: TraitItemKind :: Const ( ty, Some ( body) , ct_arg)
826834 }
@@ -1004,6 +1012,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10041012 ident,
10051013 generics,
10061014 ty,
1015+ body_id,
10071016 expr,
10081017 define_opaque,
10091018 ..
@@ -1017,7 +1026,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
10171026 let ty = this
10181027 . lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
10191028 this. lower_define_opaque ( hir_id, & define_opaque) ;
1020- let ( body, ct_arg) = this. lower_const_item ( i. span , expr. as_deref ( ) ) ;
1029+ let ( body, ct_arg) =
1030+ this. lower_const_item ( i. span , body_id. zip ( expr. as_deref ( ) ) ) ;
10211031 hir:: ImplItemKind :: Const ( ty, body, ct_arg)
10221032 } ,
10231033 ) ,
@@ -1293,23 +1303,20 @@ impl<'hir> LoweringContext<'_, 'hir> {
12931303 pub ( super ) fn lower_const_body_with_const_block (
12941304 & mut self ,
12951305 span : Span ,
1296- expr : Option < & Expr > ,
1306+ body : Option < ( NodeId , & Expr ) > ,
12971307 ) -> hir:: BodyId {
12981308 self . lower_body ( |this| {
12991309 (
13001310 & [ ] ,
1301- match expr {
1302- Some ( expr) => {
1303- let def_id = this. local_def_id ( expr. id ) ;
1304- // TODO: somehow avoid reusing the same nodeid for the const block and the body expr
1305- let hir_id = this. lower_node_id ( expr. id ) ;
1311+ match body {
1312+ Some ( ( body_id, expr) ) => {
13061313 let block = hir:: ConstBlock {
1307- def_id,
1308- hir_id,
1314+ def_id : this . local_def_id ( body_id ) ,
1315+ hir_id : this . lower_node_id ( body_id ) ,
13091316 body : this. lower_const_body ( expr. span , Some ( expr) ) ,
13101317 } ;
13111318 hir:: Expr {
1312- hir_id,
1319+ hir_id : this . next_id ( ) ,
13131320 span : this. lower_span ( expr. span ) ,
13141321 kind : hir:: ExprKind :: ConstBlock ( block) ,
13151322 }
0 commit comments