@@ -6,7 +6,7 @@ use rustc_hash::FxHashMap;
6
6
use ra_arena:: { Arena , RawId , impl_arena_id, map:: ArenaMap } ;
7
7
use ra_syntax:: {
8
8
SyntaxNodePtr , AstPtr , AstNode ,
9
- ast:: { self , LoopBodyOwner , ArgListOwner , NameOwner , LiteralKind , TypeAscriptionOwner }
9
+ ast:: { self , LoopBodyOwner , ArgListOwner , NameOwner , LiteralKind , ArrayExprKind , TypeAscriptionOwner }
10
10
} ;
11
11
12
12
use crate :: {
@@ -238,15 +238,17 @@ pub enum Expr {
238
238
Tuple {
239
239
exprs : Vec < ExprId > ,
240
240
} ,
241
- Array {
242
- exprs : Vec < ExprId > ,
243
- repeat : Option < ExprId > ,
244
- } ,
241
+ Array ( Array ) ,
245
242
Literal ( Literal ) ,
246
243
}
247
244
248
245
pub use ra_syntax:: ast:: PrefixOp as UnaryOp ;
249
246
pub use ra_syntax:: ast:: BinOp as BinaryOp ;
247
+ #[ derive( Debug , Clone , Eq , PartialEq ) ]
248
+ pub enum Array {
249
+ ElementList ( Vec < ExprId > ) ,
250
+ Repeat { initializer : ExprId , repeat : ExprId } ,
251
+ }
250
252
251
253
#[ derive( Debug , Clone , Eq , PartialEq ) ]
252
254
pub struct MatchArm {
@@ -354,15 +356,17 @@ impl Expr {
354
356
f ( * expr) ;
355
357
}
356
358
}
357
- Expr :: Array { exprs, repeat } => {
358
- for expr in exprs {
359
- f ( * expr) ;
359
+ Expr :: Array ( a) => match a {
360
+ Array :: ElementList ( exprs) => {
361
+ for expr in exprs {
362
+ f ( * expr) ;
363
+ }
360
364
}
361
-
362
- if let Some ( expr ) = repeat {
363
- f ( * expr )
365
+ Array :: Repeat { initializer , repeat } => {
366
+ f ( * initializer ) ;
367
+ f ( * repeat )
364
368
}
365
- }
369
+ } ,
366
370
Expr :: Literal ( _) => { }
367
371
}
368
372
}
@@ -733,11 +737,26 @@ impl ExprCollector {
733
737
let exprs = e. exprs ( ) . map ( |expr| self . collect_expr ( expr) ) . collect ( ) ;
734
738
self . alloc_expr ( Expr :: Tuple { exprs } , syntax_ptr)
735
739
}
740
+
736
741
ast:: ExprKind :: ArrayExpr ( e) => {
737
- let exprs = e. exprs ( ) . map ( |expr| self . collect_expr ( expr) ) . collect ( ) ;
738
- let repeat = e. repeat ( ) . map ( |e| self . collect_expr ( e) ) ;
739
- self . alloc_expr ( Expr :: Array { exprs, repeat } , syntax_ptr)
742
+ let kind = e. kind ( ) ;
743
+
744
+ match kind {
745
+ ArrayExprKind :: ElementList ( e) => {
746
+ let exprs = e. map ( |expr| self . collect_expr ( expr) ) . collect ( ) ;
747
+ self . alloc_expr ( Expr :: Array ( Array :: ElementList ( exprs) ) , syntax_ptr)
748
+ }
749
+ ArrayExprKind :: Repeat { initializer, repeat } => {
750
+ let initializer = self . collect_expr_opt ( initializer) ;
751
+ let repeat = self . collect_expr_opt ( repeat) ;
752
+ self . alloc_expr (
753
+ Expr :: Array ( Array :: Repeat { initializer, repeat } ) ,
754
+ syntax_ptr,
755
+ )
756
+ }
757
+ }
740
758
}
759
+
741
760
ast:: ExprKind :: Literal ( e) => {
742
761
let lit = match e. kind ( ) {
743
762
LiteralKind :: IntNumber { suffix } => {
0 commit comments