@@ -964,7 +964,22 @@ impl<'ctx> MirLowerCtx<'ctx> {
964
964
self . push_assignment ( current, place, r, expr_id. into ( ) ) ;
965
965
Ok ( Some ( current) )
966
966
}
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
+ } ,
968
983
} ,
969
984
Expr :: Literal ( l) => {
970
985
let ty = self . expr_ty ( expr_id) ;
@@ -1433,7 +1448,12 @@ impl<'ctx> MirLowerCtx<'ctx> {
1433
1448
fn binding_local ( & self , b : BindingId ) -> Result < LocalId > {
1434
1449
match self . result . binding_locals . get ( b) {
1435
1450
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
+ }
1437
1457
}
1438
1458
}
1439
1459
}
@@ -1588,14 +1608,23 @@ pub fn lower_to_mir(
1588
1608
}
1589
1609
} ;
1590
1610
// 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
+ }
1599
1628
ctx. lower_params_and_bindings ( [ ] . into_iter ( ) , binding_picker) ?
1600
1629
} ;
1601
1630
if let Some ( b) = ctx. lower_expr_to_place ( root_expr, return_slot ( ) . into ( ) , current) ? {
0 commit comments