diff options
author | oxalica <[email protected]> | 2019-11-29 06:49:12 +0000 |
---|---|---|
committer | oxalica <[email protected]> | 2019-11-29 06:49:12 +0000 |
commit | 2cb684bbce1c487b2efb5a8154afe66e4907ceac (patch) | |
tree | f93ef014cc82793949e8567634cec341ffc58d62 /crates/ra_hir_def | |
parent | 4992d2bf79e9da6db759eb8e1715f90f31ec7eb9 (diff) |
Reduce variants of Expr
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 19 | ||||
-rw-r--r-- | crates/ra_hir_def/src/expr.rs | 38 |
2 files changed, 19 insertions, 38 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index d18964d54..be1eaa523 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -8,7 +8,7 @@ use hir_expand::{ | |||
8 | use ra_arena::Arena; | 8 | use ra_arena::Arena; |
9 | use ra_syntax::{ | 9 | use ra_syntax::{ |
10 | ast::{ | 10 | ast::{ |
11 | self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner, RangeOp, | 11 | self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner, |
12 | TypeAscriptionOwner, | 12 | TypeAscriptionOwner, |
13 | }, | 13 | }, |
14 | AstNode, AstPtr, | 14 | AstNode, AstPtr, |
@@ -432,20 +432,11 @@ where | |||
432 | ast::Expr::RangeExpr(e) => { | 432 | ast::Expr::RangeExpr(e) => { |
433 | let lhs = e.start().map(|lhs| self.collect_expr(lhs)); | 433 | let lhs = e.start().map(|lhs| self.collect_expr(lhs)); |
434 | let rhs = e.end().map(|rhs| self.collect_expr(rhs)); | 434 | let rhs = e.end().map(|rhs| self.collect_expr(rhs)); |
435 | match (lhs, e.op_kind(), rhs) { | 435 | match e.op_kind() { |
436 | (None, _, None) => self.alloc_expr(Expr::RangeFull, syntax_ptr), | 436 | Some(range_type) => { |
437 | (Some(lhs), _, None) => self.alloc_expr(Expr::RangeFrom { lhs }, syntax_ptr), | 437 | self.alloc_expr(Expr::Range { lhs, rhs, range_type }, syntax_ptr) |
438 | (None, Some(RangeOp::Inclusive), Some(rhs)) => { | ||
439 | self.alloc_expr(Expr::RangeToInclusive { rhs }, syntax_ptr) | ||
440 | } | ||
441 | (Some(lhs), Some(RangeOp::Inclusive), Some(rhs)) => { | ||
442 | self.alloc_expr(Expr::RangeInclusive { lhs, rhs }, syntax_ptr) | ||
443 | } | ||
444 | // If RangeOp is missing, fallback to exclusive range. | ||
445 | (None, _, Some(rhs)) => self.alloc_expr(Expr::RangeTo { rhs }, syntax_ptr), | ||
446 | (Some(lhs), _, Some(rhs)) => { | ||
447 | self.alloc_expr(Expr::Range { lhs, rhs }, syntax_ptr) | ||
448 | } | 438 | } |
439 | None => self.alloc_expr(Expr::Missing, syntax_ptr), | ||
449 | } | 440 | } |
450 | } | 441 | } |
451 | 442 | ||
diff --git a/crates/ra_hir_def/src/expr.rs b/crates/ra_hir_def/src/expr.rs index 115090218..6fad80a8d 100644 --- a/crates/ra_hir_def/src/expr.rs +++ b/crates/ra_hir_def/src/expr.rs | |||
@@ -14,6 +14,7 @@ | |||
14 | 14 | ||
15 | use hir_expand::name::Name; | 15 | use hir_expand::name::Name; |
16 | use ra_arena::{impl_arena_id, RawId}; | 16 | use ra_arena::{impl_arena_id, RawId}; |
17 | use ra_syntax::ast::RangeOp; | ||
17 | 18 | ||
18 | use crate::{ | 19 | use crate::{ |
19 | builtin_type::{BuiltinFloat, BuiltinInt}, | 20 | builtin_type::{BuiltinFloat, BuiltinInt}, |
@@ -130,23 +131,10 @@ pub enum Expr { | |||
130 | rhs: ExprId, | 131 | rhs: ExprId, |
131 | op: Option<BinaryOp>, | 132 | op: Option<BinaryOp>, |
132 | }, | 133 | }, |
133 | RangeFull, | ||
134 | RangeFrom { | ||
135 | lhs: ExprId, | ||
136 | }, | ||
137 | RangeTo { | ||
138 | rhs: ExprId, | ||
139 | }, | ||
140 | Range { | 134 | Range { |
141 | lhs: ExprId, | 135 | lhs: Option<ExprId>, |
142 | rhs: ExprId, | 136 | rhs: Option<ExprId>, |
143 | }, | 137 | range_type: RangeOp, |
144 | RangeToInclusive { | ||
145 | rhs: ExprId, | ||
146 | }, | ||
147 | RangeInclusive { | ||
148 | lhs: ExprId, | ||
149 | rhs: ExprId, | ||
150 | }, | 138 | }, |
151 | Index { | 139 | Index { |
152 | base: ExprId, | 140 | base: ExprId, |
@@ -302,21 +290,23 @@ impl Expr { | |||
302 | Expr::Lambda { body, .. } => { | 290 | Expr::Lambda { body, .. } => { |
303 | f(*body); | 291 | f(*body); |
304 | } | 292 | } |
305 | Expr::BinaryOp { lhs, rhs, .. } | 293 | Expr::BinaryOp { lhs, rhs, .. } => { |
306 | | Expr::Range { lhs, rhs } | ||
307 | | Expr::RangeInclusive { lhs, rhs } => { | ||
308 | f(*lhs); | 294 | f(*lhs); |
309 | f(*rhs); | 295 | f(*rhs); |
310 | } | 296 | } |
297 | Expr::Range { lhs, rhs, .. } => { | ||
298 | if let Some(lhs) = rhs { | ||
299 | f(*lhs); | ||
300 | } | ||
301 | if let Some(rhs) = lhs { | ||
302 | f(*rhs); | ||
303 | } | ||
304 | } | ||
311 | Expr::Index { base, index } => { | 305 | Expr::Index { base, index } => { |
312 | f(*base); | 306 | f(*base); |
313 | f(*index); | 307 | f(*index); |
314 | } | 308 | } |
315 | Expr::RangeFull => {} | 309 | Expr::Field { expr, .. } |
316 | Expr::RangeFrom { lhs: expr } | ||
317 | | Expr::RangeTo { rhs: expr } | ||
318 | | Expr::RangeToInclusive { rhs: expr } | ||
319 | | Expr::Field { expr, .. } | ||
320 | | Expr::Await { expr } | 310 | | Expr::Await { expr } |
321 | | Expr::Try { expr } | 311 | | Expr::Try { expr } |
322 | | Expr::Cast { expr, .. } | 312 | | Expr::Cast { expr, .. } |