@@ -964,7 +964,22 @@ impl<'ctx> MirLowerCtx<'ctx> {
964964 self . push_assignment ( current, place, r, expr_id. into ( ) ) ;
965965 Ok ( Some ( current) )
966966 }
967- Array :: Repeat { .. } => not_supported ! ( "array repeat" ) ,
967+ Array :: Repeat { initializer, .. } => {
968+ let Some ( ( init, current) ) = self . lower_expr_to_some_operand ( * initializer, current) ? else {
969+ return Ok ( None ) ;
970+ } ;
971+ let len = match & self . expr_ty ( expr_id) . data ( Interner ) . kind {
972+ TyKind :: Array ( _, len) => len. clone ( ) ,
973+ _ => {
974+ return Err ( MirLowerError :: TypeError (
975+ "Array repeat expression with non array type" ,
976+ ) )
977+ }
978+ } ;
979+ let r = Rvalue :: Repeat ( init, len) ;
980+ self . push_assignment ( current, place, r, expr_id. into ( ) ) ;
981+ Ok ( Some ( current) )
982+ } ,
968983 } ,
969984 Expr :: Literal ( l) => {
970985 let ty = self . expr_ty ( expr_id) ;
@@ -1433,7 +1448,12 @@ impl<'ctx> MirLowerCtx<'ctx> {
14331448 fn binding_local ( & self , b : BindingId ) -> Result < LocalId > {
14341449 match self . result . binding_locals . get ( b) {
14351450 Some ( x) => Ok ( * x) ,
1436- None => Err ( MirLowerError :: UnaccessableLocal ) ,
1451+ None => {
1452+ // FIXME: It should never happens, but currently it will happen in `const_dependent_on_local` test, which
1453+ // is a hir lowering problem IMO.
1454+ // never!("Using unaccessable local for binding is always a bug");
1455+ Err ( MirLowerError :: UnaccessableLocal )
1456+ }
14371457 }
14381458 }
14391459}
@@ -1588,14 +1608,23 @@ pub fn lower_to_mir(
15881608 }
15891609 } ;
15901610 // 1 to param_len is for params
1591- let current = if let DefWithBodyId :: FunctionId ( fid) = owner {
1592- let substs = TyBuilder :: placeholder_subst ( db, fid) ;
1593- let callable_sig = db. callable_item_signature ( fid. into ( ) ) . substitute ( Interner , & substs) ;
1594- ctx. lower_params_and_bindings (
1595- body. params . iter ( ) . zip ( callable_sig. params ( ) . iter ( ) ) . map ( |( x, y) | ( * x, y. clone ( ) ) ) ,
1596- binding_picker,
1597- ) ?
1598- } else {
1611+ // FIXME: replace with let chain once it becomes stable
1612+ let current = ' b: {
1613+ if body. body_expr == root_expr {
1614+ // otherwise it's an inline const, and has no parameter
1615+ if let DefWithBodyId :: FunctionId ( fid) = owner {
1616+ let substs = TyBuilder :: placeholder_subst ( db, fid) ;
1617+ let callable_sig =
1618+ db. callable_item_signature ( fid. into ( ) ) . substitute ( Interner , & substs) ;
1619+ break ' b ctx. lower_params_and_bindings (
1620+ body. params
1621+ . iter ( )
1622+ . zip ( callable_sig. params ( ) . iter ( ) )
1623+ . map ( |( x, y) | ( * x, y. clone ( ) ) ) ,
1624+ binding_picker,
1625+ ) ?;
1626+ }
1627+ }
15991628 ctx. lower_params_and_bindings ( [ ] . into_iter ( ) , binding_picker) ?
16001629 } ;
16011630 if let Some ( b) = ctx. lower_expr_to_place ( root_expr, return_slot ( ) . into ( ) , current) ? {
0 commit comments