@@ -199,6 +199,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
199
199
ident,
200
200
generics,
201
201
ty,
202
+ body_id,
202
203
expr,
203
204
define_opaque,
204
205
..
@@ -211,7 +212,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
211
212
|this| {
212
213
let ty = this
213
214
. 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 ( ) ) ) )
215
216
} ,
216
217
) ;
217
218
self . lower_define_opaque ( hir_id, & define_opaque) ;
@@ -498,15 +499,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
498
499
fn lower_const_item (
499
500
& mut self ,
500
501
span : Span ,
501
- body : Option < & Expr > ,
502
+ body : Option < ( NodeId , & Expr ) > ,
502
503
) -> ( hir:: BodyId , Option < & ' hir hir:: ConstArg < ' hir > > ) {
503
504
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
+ } ;
506
510
let body_id = if mgca && ct_arg. is_none ( ) {
507
511
self . lower_const_body_with_const_block ( span, body)
508
512
} else {
509
- self . lower_const_body ( span, body)
513
+ self . lower_const_body ( span, body. map ( | ( _ , e ) | e ) )
510
514
} ;
511
515
( body_id, ct_arg)
512
516
}
@@ -809,6 +813,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
809
813
ident,
810
814
generics,
811
815
ty,
816
+ body_id,
812
817
expr,
813
818
define_opaque,
814
819
..
@@ -820,7 +825,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
820
825
|this| {
821
826
let ty = this
822
827
. 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 {
824
832
Some ( ( body, ct_arg) ) => {
825
833
hir:: TraitItemKind :: Const ( ty, Some ( body) , ct_arg)
826
834
}
@@ -1004,6 +1012,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1004
1012
ident,
1005
1013
generics,
1006
1014
ty,
1015
+ body_id,
1007
1016
expr,
1008
1017
define_opaque,
1009
1018
..
@@ -1017,7 +1026,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
1017
1026
let ty = this
1018
1027
. lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
1019
1028
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 ( ) ) ) ;
1021
1031
hir:: ImplItemKind :: Const ( ty, body, ct_arg)
1022
1032
} ,
1023
1033
) ,
@@ -1293,23 +1303,20 @@ impl<'hir> LoweringContext<'_, 'hir> {
1293
1303
pub ( super ) fn lower_const_body_with_const_block (
1294
1304
& mut self ,
1295
1305
span : Span ,
1296
- expr : Option < & Expr > ,
1306
+ body : Option < ( NodeId , & Expr ) > ,
1297
1307
) -> hir:: BodyId {
1298
1308
self . lower_body ( |this| {
1299
1309
(
1300
1310
& [ ] ,
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) ) => {
1306
1313
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 ) ,
1309
1316
body : this. lower_const_body ( expr. span , Some ( expr) ) ,
1310
1317
} ;
1311
1318
hir:: Expr {
1312
- hir_id,
1319
+ hir_id : this . next_id ( ) ,
1313
1320
span : this. lower_span ( expr. span ) ,
1314
1321
kind : hir:: ExprKind :: ConstBlock ( block) ,
1315
1322
}
0 commit comments