@@ -500,16 +500,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
500500 span : Span ,
501501 body : Option < & Expr > ,
502502 ) -> ( hir:: BodyId , Option < & ' hir hir:: ConstArg < ' hir > > ) {
503- let ct_arg = if self . tcx . features ( ) . min_generic_const_args ( )
504- && let Some ( expr) = body
505- {
506- self . try_lower_as_const_path ( expr)
507- } else {
508- None
509- } ;
510- let body_id = if body. is_some ( ) && ct_arg. is_none ( ) {
511- // TODO: lower as const block instead
512- self . lower_const_body ( span, body)
503+ 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 } ;
506+ let body_id = if mgca && ct_arg. is_none ( ) {
507+ self . lower_const_body_with_const_block ( span, body)
513508 } else {
514509 self . lower_const_body ( span, body)
515510 } ;
@@ -1292,6 +1287,39 @@ impl<'hir> LoweringContext<'_, 'hir> {
12921287 self . lower_fn_body ( decl, contract, |this| this. lower_block_expr ( body) )
12931288 }
12941289
1290+ /// HACK(mgca): lower the body of the const item as a const block
1291+ /// we need this later to be able to control generics in the body
1292+ /// separately from the const's type, etc.
1293+ pub ( super ) fn lower_const_body_with_const_block (
1294+ & mut self ,
1295+ span : Span ,
1296+ expr : Option < & Expr > ,
1297+ ) -> hir:: BodyId {
1298+ self . lower_body ( |this| {
1299+ (
1300+ & [ ] ,
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 ) ;
1306+ let block = hir:: ConstBlock {
1307+ def_id,
1308+ hir_id,
1309+ body : this. lower_const_body ( expr. span , Some ( expr) ) ,
1310+ } ;
1311+ hir:: Expr {
1312+ hir_id,
1313+ span : this. lower_span ( expr. span ) ,
1314+ kind : hir:: ExprKind :: ConstBlock ( block) ,
1315+ }
1316+ }
1317+ None => this. expr_err ( span, this. dcx ( ) . span_delayed_bug ( span, "no block" ) ) ,
1318+ } ,
1319+ )
1320+ } )
1321+ }
1322+
12951323 pub ( super ) fn lower_const_body ( & mut self , span : Span , expr : Option < & Expr > ) -> hir:: BodyId {
12961324 self . lower_body ( |this| {
12971325 (
0 commit comments