X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Fhir_def%2Fsrc%2Fexpr.rs;h=4dca8238880d9376833bf406c65369e8550737fe;hb=0b53744f2d7e0694cd7207cca632fd6de1dc5bff;hp=17af48b7bf6ce693a01b3b73219cd16c04de979f;hpb=f87debcf87c16690e8d5e185a35d03a402a2d5bf;p=rust.git diff --git a/crates/hir_def/src/expr.rs b/crates/hir_def/src/expr.rs index 17af48b7bf6..4dca8238880 100644 --- a/crates/hir_def/src/expr.rs +++ b/crates/hir_def/src/expr.rs @@ -40,8 +40,8 @@ pub struct Label { #[derive(Debug, Clone, Eq, PartialEq)] pub enum Literal { - String(String), - ByteString(Vec), + String(Box), + ByteString(Box<[u8]>), Char(char), Bool(bool), Int(i128, Option), @@ -59,9 +59,13 @@ pub enum Expr { then_branch: ExprId, else_branch: Option, }, + Let { + pat: PatId, + expr: ExprId, + }, Block { id: BlockId, - statements: Vec, + statements: Box<[Statement]>, tail: Option, label: Option, }, @@ -82,17 +86,17 @@ pub enum Expr { }, Call { callee: ExprId, - args: Vec, + args: Box<[ExprId]>, }, MethodCall { receiver: ExprId, method_name: Name, - args: Vec, + args: Box<[ExprId]>, generic_args: Option>, }, Match { expr: ExprId, - arms: Vec, + arms: Box<[MatchArm]>, }, Continue { label: Option, @@ -109,7 +113,7 @@ pub enum Expr { }, RecordLit { path: Option>, - fields: Vec, + fields: Box<[RecordLitField]>, spread: Option, }, Field { @@ -162,13 +166,13 @@ pub enum Expr { index: ExprId, }, Lambda { - args: Vec, - arg_types: Vec>>, + args: Box<[PatId]>, + arg_types: Box<[Option>]>, ret_type: Option>, body: ExprId, }, Tuple { - exprs: Vec, + exprs: Box<[ExprId]>, }, Unsafe { body: ExprId, @@ -182,24 +186,17 @@ pub enum Expr { #[derive(Debug, Clone, Eq, PartialEq)] pub enum Array { - ElementList(Vec), + ElementList(Box<[ExprId]>), Repeat { initializer: ExprId, repeat: ExprId }, } #[derive(Debug, Clone, Eq, PartialEq)] pub struct MatchArm { pub pat: PatId, - pub guard: Option, + pub guard: Option, pub expr: ExprId, } -#[derive(Debug, Clone, Eq, PartialEq)] -pub enum MatchGuard { - If { expr: ExprId }, - - IfLet { pat: PatId, expr: ExprId }, -} - #[derive(Debug, Clone, Eq, PartialEq)] pub struct RecordLitField { pub name: Name, @@ -228,23 +225,26 @@ pub fn walk_child_exprs(&self, mut f: impl FnMut(ExprId)) { 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::Let { expr, .. } => { + f(*expr); + } Expr::Block { statements, tail, .. } => { - for stmt in statements { + 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 @@ pub fn walk_child_exprs(&self, mut f: impl FnMut(ExprId)) { } Expr::Call { callee, args } => { f(*callee); - for arg in args { - f(*arg); - } + args.iter().copied().for_each(f); } Expr::MethodCall { receiver, args, .. } => { f(*receiver); - for arg in args { - f(*arg); - } + args.iter().copied().for_each(f); } Expr::Match { expr, arms } => { f(*expr); - for arm in arms { - 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 { + 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 @@ pub fn walk_child_exprs(&self, mut f: impl FnMut(ExprId)) { 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 @@ pub fn walk_child_exprs(&self, mut f: impl FnMut(ExprId)) { | Expr::Box { expr } => { f(*expr); } - Expr::Tuple { exprs } => { - for expr in exprs { - 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, ellipsis: Option }, - Or(Vec), - Record { path: Option>, args: Vec, ellipsis: bool }, + Tuple { args: Box<[PatId]>, ellipsis: Option }, + Or(Box<[PatId]>), + Record { path: Option>, args: Box<[RecordFieldPat]>, ellipsis: bool }, Range { start: ExprId, end: ExprId }, - Slice { prefix: Vec, slice: Option, suffix: Vec }, + Slice { prefix: Box<[PatId]>, slice: Option, suffix: Box<[PatId]> }, Path(Box), Lit(ExprId), Bind { mode: BindingAnnotation, name: Name, subpat: Option }, - TupleStruct { path: Option>, args: Vec, ellipsis: Option }, + TupleStruct { path: Option>, args: Box<[PatId]>, ellipsis: Option }, Ref { pat: PatId, mutability: Mutability }, Box { inner: PatId }, ConstBlock(ExprId),