@@ -154,7 +154,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
154154 ) -> DistributedSlice {
155155 match distributed_slice {
156156 ast:: DistributedSlice :: None => DistributedSlice :: None ,
157- ast:: DistributedSlice :: Declaration ( span) => {
157+ ast:: DistributedSlice :: Declaration ( span, _ ) => {
158158 DistributedSlice :: Declaration ( self . lower_span ( * span) )
159159 }
160160 ast:: DistributedSlice :: Addition { declaration, id } => {
@@ -544,12 +544,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
544544 impl_trait_position : ImplTraitPosition ,
545545 distributed_slice : & ast:: DistributedSlice ,
546546 ) -> ( & ' 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+
547554 let ty = self . lower_ty (
548555 ty,
549556 ImplTraitContext :: Disallowed ( impl_trait_position) ,
550- matches ! ( distributed_slice , ast :: DistributedSlice :: Declaration ( .. ) ) ,
557+ distributed_slice_declaration . is_some ( ) ,
551558 ) ;
552- ( ty, self . lower_const_body ( span, body) )
559+ ( ty, self . lower_const_body ( span, body, distributed_slice_declaration ) )
553560 }
554561
555562 #[ instrument( level = "debug" , skip( self ) ) ]
@@ -866,7 +873,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
866873 ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ,
867874 false ,
868875 ) ;
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 ) ) ;
870878
871879 hir:: TraitItemKind :: Const ( ty, body)
872880 } ,
@@ -1063,7 +1071,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10631071 ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ,
10641072 false ,
10651073 ) ;
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 ) ;
10671075 this. lower_define_opaque ( hir_id, & define_opaque) ;
10681076 hir:: ImplItemKind :: Const ( ty, body)
10691077 } ,
@@ -1342,13 +1350,29 @@ impl<'hir> LoweringContext<'_, 'hir> {
13421350 self . lower_fn_body ( decl, contract, |this| this. lower_block_expr ( body) )
13431351 }
13441352
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 {
13461359 self . lower_body ( |this| {
13471360 (
13481361 & [ ] ,
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+ }
13521376 } ,
13531377 )
13541378 } )
0 commit comments