@@ -154,7 +154,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
154
154
) -> DistributedSlice {
155
155
match distributed_slice {
156
156
ast:: DistributedSlice :: None => DistributedSlice :: None ,
157
- ast:: DistributedSlice :: Declaration ( span) => {
157
+ ast:: DistributedSlice :: Declaration ( span, _ ) => {
158
158
DistributedSlice :: Declaration ( self . lower_span ( * span) )
159
159
}
160
160
ast:: DistributedSlice :: Addition { declaration, id } => {
@@ -544,12 +544,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
544
544
impl_trait_position : ImplTraitPosition ,
545
545
distributed_slice : & ast:: DistributedSlice ,
546
546
) -> ( & ' hir hir:: Ty < ' hir > , hir:: BodyId ) {
547
+ let distributed_slice_declaration =
548
+ if let ast:: DistributedSlice :: Declaration ( _, node_id) = distributed_slice {
549
+ Some ( * node_id)
550
+ } else {
551
+ None
552
+ } ;
553
+
547
554
let ty = self . lower_ty (
548
555
ty,
549
556
ImplTraitContext :: Disallowed ( impl_trait_position) ,
550
- matches ! ( distributed_slice , ast :: DistributedSlice :: Declaration ( .. ) ) ,
557
+ distributed_slice_declaration . is_some ( ) ,
551
558
) ;
552
- ( ty, self . lower_const_body ( span, body) )
559
+ ( ty, self . lower_const_body ( span, body, distributed_slice_declaration ) )
553
560
}
554
561
555
562
#[ instrument( level = "debug" , skip( self ) ) ]
@@ -866,7 +873,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
866
873
ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ,
867
874
false ,
868
875
) ;
869
- let body = expr. as_ref ( ) . map ( |x| this. lower_const_body ( i. span , Some ( x) ) ) ;
876
+ let body =
877
+ expr. as_ref ( ) . map ( |x| this. lower_const_body ( i. span , Some ( x) , None ) ) ;
870
878
871
879
hir:: TraitItemKind :: Const ( ty, body)
872
880
} ,
@@ -1063,7 +1071,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1063
1071
ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ,
1064
1072
false ,
1065
1073
) ;
1066
- let body = this. lower_const_body ( i. span , expr. as_deref ( ) ) ;
1074
+ let body = this. lower_const_body ( i. span , expr. as_deref ( ) , None ) ;
1067
1075
this. lower_define_opaque ( hir_id, & define_opaque) ;
1068
1076
hir:: ImplItemKind :: Const ( ty, body)
1069
1077
} ,
@@ -1342,13 +1350,29 @@ impl<'hir> LoweringContext<'_, 'hir> {
1342
1350
self . lower_fn_body ( decl, contract, |this| this. lower_block_expr ( body) )
1343
1351
}
1344
1352
1345
- pub ( super ) fn lower_const_body ( & mut self , span : Span , expr : Option < & Expr > ) -> hir:: BodyId {
1353
+ pub ( super ) fn lower_const_body (
1354
+ & mut self ,
1355
+ span : Span ,
1356
+ expr : Option < & Expr > ,
1357
+ global_registry_declaration : Option < NodeId > ,
1358
+ ) -> hir:: BodyId {
1346
1359
self . lower_body ( |this| {
1347
1360
(
1348
1361
& [ ] ,
1349
- match expr {
1350
- Some ( expr) => this. lower_expr_mut ( expr) ,
1351
- None => this. expr_err ( span, this. dcx ( ) . span_delayed_bug ( span, "no block" ) ) ,
1362
+ match ( expr, global_registry_declaration) {
1363
+ ( Some ( expr) , None ) => this. lower_expr_mut ( expr) ,
1364
+ ( None , Some ( node_id) ) => {
1365
+ let expr_hir_id = this. lower_node_id ( node_id) ;
1366
+ hir:: Expr {
1367
+ hir_id : expr_hir_id,
1368
+ kind : rustc_hir:: ExprKind :: DistributedSliceDeferredArray ,
1369
+ span : this. lower_span ( span) ,
1370
+ }
1371
+ }
1372
+ ( Some ( expr) , Some ( _) ) => panic ! ( "distributed slice with initializer" ) ,
1373
+ ( None , None ) => {
1374
+ this. expr_err ( span, this. dcx ( ) . span_delayed_bug ( span, "no block" ) )
1375
+ }
1352
1376
} ,
1353
1377
)
1354
1378
} )
0 commit comments