Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir_def/src/expr.rs')
| -rw-r--r-- | crates/hir_def/src/expr.rs | 66 |
1 files changed, 26 insertions, 40 deletions
diff --git a/crates/hir_def/src/expr.rs b/crates/hir_def/src/expr.rs index 587a5ce46d..e6518c3e2d 100644 --- a/crates/hir_def/src/expr.rs +++ b/crates/hir_def/src/expr.rs @@ -41,7 +41,7 @@ pub type LabelId = Idx<Label>; #[derive(Debug, Clone, Eq, PartialEq)] pub enum Literal { String(String), - ByteString(Vec<u8>), + ByteString(Box<[u8]>), Char(char), Bool(bool), Int(i128, Option<BuiltinInt>), @@ -182,7 +182,7 @@ pub enum Expr { #[derive(Debug, Clone, Eq, PartialEq)] pub enum Array { - ElementList(Vec<ExprId>), + ElementList(Box<[ExprId]>), Repeat { initializer: ExprId, repeat: ExprId }, } @@ -228,23 +228,23 @@ impl Expr { Expr::If { condition, then_branch, else_branch } => { f(*condition); f(*then_branch); - if let Some(else_branch) = else_branch { - f(*else_branch); + if let &Some(else_branch) = else_branch { + f(else_branch); } } Expr::Block { statements, tail, .. } => { for stmt in statements.iter() { match stmt { Statement::Let { initializer, .. } => { - if let Some(expr) = initializer { - f(*expr); + if let &Some(expr) = initializer { + f(expr); } } Statement::Expr { expr: expression, .. } => f(*expression), } } - if let Some(expr) = tail { - f(*expr); + if let &Some(expr) = tail { + f(expr); } } Expr::TryBlock { body } @@ -262,34 +262,28 @@ impl Expr { } Expr::Call { callee, args } => { f(*callee); - for arg in args.iter() { - f(*arg); - } + args.iter().copied().for_each(f); } Expr::MethodCall { receiver, args, .. } => { f(*receiver); - for arg in args.iter() { - f(*arg); - } + args.iter().copied().for_each(f); } Expr::Match { expr, arms } => { f(*expr); - for arm in arms.iter() { - f(arm.expr); - } + arms.iter().map(|arm| arm.expr).for_each(f); } Expr::Continue { .. } => {} Expr::Break { expr, .. } | Expr::Return { expr } | Expr::Yield { expr } => { - if let Some(expr) = expr { - f(*expr); + if let &Some(expr) = expr { + f(expr); } } Expr::RecordLit { fields, spread, .. } => { for field in fields.iter() { f(field.expr); } - if let Some(expr) = spread { - f(*expr); + if let &Some(expr) = spread { + f(expr); } } Expr::Lambda { body, .. } => { @@ -300,11 +294,11 @@ impl Expr { f(*rhs); } Expr::Range { lhs, rhs, .. } => { - if let Some(lhs) = rhs { - f(*lhs); + if let &Some(lhs) = rhs { + f(lhs); } - if let Some(rhs) = lhs { - f(*rhs); + if let &Some(rhs) = lhs { + f(rhs); } } Expr::Index { base, index } => { @@ -320,17 +314,9 @@ impl Expr { | Expr::Box { expr } => { f(*expr); } - Expr::Tuple { exprs } => { - for expr in exprs.iter() { - f(*expr); - } - } + Expr::Tuple { exprs } => exprs.iter().copied().for_each(f), Expr::Array(a) => match a { - Array::ElementList(exprs) => { - for expr in exprs { - f(*expr); - } - } + Array::ElementList(exprs) => exprs.iter().copied().for_each(f), Array::Repeat { initializer, repeat } => { f(*initializer); f(*repeat) @@ -386,15 +372,15 @@ pub struct RecordFieldPat { pub enum Pat { Missing, Wild, - Tuple { args: Vec<PatId>, ellipsis: Option<usize> }, - Or(Vec<PatId>), - Record { path: Option<Box<Path>>, args: Vec<RecordFieldPat>, ellipsis: bool }, + Tuple { args: Box<[PatId]>, ellipsis: Option<usize> }, + Or(Box<[PatId]>), + Record { path: Option<Box<Path>>, args: Box<[RecordFieldPat]>, ellipsis: bool }, Range { start: ExprId, end: ExprId }, - Slice { prefix: Vec<PatId>, slice: Option<PatId>, suffix: Vec<PatId> }, + Slice { prefix: Box<[PatId]>, slice: Option<PatId>, suffix: Box<[PatId]> }, Path(Box<Path>), Lit(ExprId), Bind { mode: BindingAnnotation, name: Name, subpat: Option<PatId> }, - TupleStruct { path: Option<Box<Path>>, args: Vec<PatId>, ellipsis: Option<usize> }, + TupleStruct { path: Option<Box<Path>>, args: Box<[PatId]>, ellipsis: Option<usize> }, Ref { pat: PatId, mutability: Mutability }, Box { inner: PatId }, ConstBlock(ExprId), |