From 6a16b38198c68cf932d3f43a9663f7588d6a1a3b Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Wed, 11 Jul 2018 20:05:29 +0800 Subject: [PATCH] ExprKind --- src/librustc/cfg/construct.rs | 68 ++++---- src/librustc/hir/check_attr.rs | 2 +- src/librustc/hir/intravisit.rs | 54 +++---- src/librustc/hir/lowering.rs | 116 ++++++------- src/librustc/hir/map/blocks.rs | 6 +- src/librustc/hir/map/mod.rs | 8 +- src/librustc/hir/mod.rs | 123 +++++++------- src/librustc/hir/print.rs | 106 ++++++------ src/librustc/ich/impls_hir.rs | 60 +++---- src/librustc/infer/error_reporting/mod.rs | 12 +- .../nice_region_error/outlives_closure.rs | 4 +- src/librustc/middle/dead.rs | 10 +- src/librustc/middle/expr_use_visitor.rs | 58 +++---- src/librustc/middle/intrinsicck.rs | 2 +- src/librustc/middle/liveness.rs | 122 +++++++------- src/librustc/middle/mem_categorization.rs | 32 ++-- src/librustc/middle/reachable.rs | 6 +- src/librustc/middle/region.rs | 38 ++--- src/librustc/middle/resolve_lifetime.rs | 4 +- src/librustc/traits/error_reporting.rs | 4 +- src/librustc/ty/context.rs | 2 +- src/librustc_borrowck/borrowck/check_loans.rs | 2 +- .../borrowck/gather_loans/gather_moves.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 4 +- src/librustc_lint/builtin.rs | 16 +- src/librustc_lint/types.rs | 16 +- src/librustc_lint/unused.rs | 14 +- src/librustc_metadata/encoder.rs | 2 +- .../borrow_check/error_reporting.rs | 4 +- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/hair/cx/expr.rs | 70 ++++---- src/librustc_mir/hair/pattern/check_match.rs | 2 +- src/librustc_mir/hair/pattern/mod.rs | 8 +- src/librustc_mir/transform/add_validation.rs | 2 +- src/librustc_passes/loops.rs | 16 +- src/librustc_passes/rvalue_promotion.rs | 58 +++---- src/librustc_privacy/lib.rs | 6 +- src/librustc_save_analysis/lib.rs | 4 +- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/_match.rs | 2 +- src/librustc_typeck/check/callee.rs | 6 +- src/librustc_typeck/check/demand.rs | 14 +- src/librustc_typeck/check/method/confirm.rs | 10 +- src/librustc_typeck/check/method/suggest.rs | 6 +- src/librustc_typeck/check/mod.rs | 152 +++++++++--------- src/librustc_typeck/check/regionck.rs | 42 ++--- src/librustc_typeck/check/upvar.rs | 2 +- src/librustc_typeck/check/writeback.rs | 18 +-- src/librustc_typeck/collect.rs | 12 +- .../borrowck/two-phase-nonrecv-autoref.rs | 2 +- 50 files changed, 666 insertions(+), 667 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index e4b9ec89bc563..f1e2794691556 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -179,12 +179,12 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { fn expr(&mut self, expr: &hir::Expr, pred: CFGIndex) -> CFGIndex { match expr.node { - hir::ExprBlock(ref blk, _) => { + hir::ExprKind::Block(ref blk, _) => { let blk_exit = self.block(&blk, pred); self.add_ast_node(expr.hir_id.local_id, &[blk_exit]) } - hir::ExprIf(ref cond, ref then, None) => { + hir::ExprKind::If(ref cond, ref then, None) => { // // [pred] // | @@ -204,7 +204,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.add_ast_node(expr.hir_id.local_id, &[cond_exit, then_exit]) // 3,4 } - hir::ExprIf(ref cond, ref then, Some(ref otherwise)) => { + hir::ExprKind::If(ref cond, ref then, Some(ref otherwise)) => { // // [pred] // | @@ -225,7 +225,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.add_ast_node(expr.hir_id.local_id, &[then_exit, else_exit]) // 4, 5 } - hir::ExprWhile(ref cond, ref body, _) => { + hir::ExprKind::While(ref cond, ref body, _) => { // // [pred] // | @@ -267,7 +267,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { expr_exit } - hir::ExprLoop(ref body, _, _) => { + hir::ExprKind::Loop(ref body, _, _) => { // // [pred] // | @@ -295,11 +295,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { expr_exit } - hir::ExprMatch(ref discr, ref arms, _) => { + hir::ExprKind::Match(ref discr, ref arms, _) => { self.match_(expr.hir_id.local_id, &discr, &arms, pred) } - hir::ExprBinary(op, ref l, ref r) if op.node.is_lazy() => { + hir::ExprKind::Binary(op, ref l, ref r) if op.node.is_lazy() => { // // [pred] // | @@ -319,14 +319,14 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.add_ast_node(expr.hir_id.local_id, &[l_exit, r_exit]) // 3,4 } - hir::ExprRet(ref v) => { + hir::ExprKind::Ret(ref v) => { let v_exit = self.opt_expr(v, pred); let b = self.add_ast_node(expr.hir_id.local_id, &[v_exit]); self.add_returning_edge(expr, b); self.add_unreachable_node() } - hir::ExprBreak(destination, ref opt_expr) => { + hir::ExprKind::Break(destination, ref opt_expr) => { let v = self.opt_expr(opt_expr, pred); let (target_scope, break_dest) = self.find_scope_edge(expr, destination, ScopeCfKind::Break); @@ -335,7 +335,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.add_unreachable_node() } - hir::ExprContinue(destination) => { + hir::ExprKind::Continue(destination) => { let (target_scope, cont_dest) = self.find_scope_edge(expr, destination, ScopeCfKind::Continue); let a = self.add_ast_node(expr.hir_id.local_id, &[pred]); @@ -343,66 +343,66 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.add_unreachable_node() } - hir::ExprArray(ref elems) => { + hir::ExprKind::Array(ref elems) => { self.straightline(expr, pred, elems.iter().map(|e| &*e)) } - hir::ExprCall(ref func, ref args) => { + hir::ExprKind::Call(ref func, ref args) => { self.call(expr, pred, &func, args.iter().map(|e| &*e)) } - hir::ExprMethodCall(.., ref args) => { + hir::ExprKind::MethodCall(.., ref args) => { self.call(expr, pred, &args[0], args[1..].iter().map(|e| &*e)) } - hir::ExprIndex(ref l, ref r) | - hir::ExprBinary(_, ref l, ref r) if self.tables.is_method_call(expr) => { + hir::ExprKind::Index(ref l, ref r) | + hir::ExprKind::Binary(_, ref l, ref r) if self.tables.is_method_call(expr) => { self.call(expr, pred, &l, Some(&**r).into_iter()) } - hir::ExprUnary(_, ref e) if self.tables.is_method_call(expr) => { + hir::ExprKind::Unary(_, ref e) if self.tables.is_method_call(expr) => { self.call(expr, pred, &e, None::.iter()) } - hir::ExprTup(ref exprs) => { + hir::ExprKind::Tup(ref exprs) => { self.straightline(expr, pred, exprs.iter().map(|e| &*e)) } - hir::ExprStruct(_, ref fields, ref base) => { + hir::ExprKind::Struct(_, ref fields, ref base) => { let field_cfg = self.straightline(expr, pred, fields.iter().map(|f| &*f.expr)); self.opt_expr(base, field_cfg) } - hir::ExprAssign(ref l, ref r) | - hir::ExprAssignOp(_, ref l, ref r) => { + hir::ExprKind::Assign(ref l, ref r) | + hir::ExprKind::AssignOp(_, ref l, ref r) => { self.straightline(expr, pred, [r, l].iter().map(|&e| &**e)) } - hir::ExprIndex(ref l, ref r) | - hir::ExprBinary(_, ref l, ref r) => { // NB: && and || handled earlier + hir::ExprKind::Index(ref l, ref r) | + hir::ExprKind::Binary(_, ref l, ref r) => { // NB: && and || handled earlier self.straightline(expr, pred, [l, r].iter().map(|&e| &**e)) } - hir::ExprBox(ref e) | - hir::ExprAddrOf(_, ref e) | - hir::ExprCast(ref e, _) | - hir::ExprType(ref e, _) | - hir::ExprUnary(_, ref e) | - hir::ExprField(ref e, _) | - hir::ExprYield(ref e) | - hir::ExprRepeat(ref e, _) => { + hir::ExprKind::Box(ref e) | + hir::ExprKind::AddrOf(_, ref e) | + hir::ExprKind::Cast(ref e, _) | + hir::ExprKind::Type(ref e, _) | + hir::ExprKind::Unary(_, ref e) | + hir::ExprKind::Field(ref e, _) | + hir::ExprKind::Yield(ref e) | + hir::ExprKind::Repeat(ref e, _) => { self.straightline(expr, pred, Some(&**e).into_iter()) } - hir::ExprInlineAsm(_, ref outputs, ref inputs) => { + hir::ExprKind::InlineAsm(_, ref outputs, ref inputs) => { let post_outputs = self.exprs(outputs.iter().map(|e| &*e), pred); let post_inputs = self.exprs(inputs.iter().map(|e| &*e), post_outputs); self.add_ast_node(expr.hir_id.local_id, &[post_inputs]) } - hir::ExprClosure(..) | - hir::ExprLit(..) | - hir::ExprPath(_) => { + hir::ExprKind::Closure(..) | + hir::ExprKind::Lit(..) | + hir::ExprKind::Path(_) => { self.straightline(expr, pred, None::.iter()) } } diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index a4e9279b23f7d..71f160dd32187 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -283,7 +283,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> { fn check_expr_attributes(&self, expr: &hir::Expr) { let target = match expr.node { - hir::ExprClosure(..) => Target::Closure, + hir::ExprKind::Closure(..) => Target::Closure, _ => Target::Expression, }; for attr in expr.attrs.iter() { diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 01c318ca17c3b..11800d7f9c9ed 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -963,17 +963,17 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { visitor.visit_id(expression.id); walk_list!(visitor, visit_attribute, expression.attrs.iter()); match expression.node { - ExprBox(ref subexpression) => { + ExprKind::Box(ref subexpression) => { visitor.visit_expr(subexpression) } - ExprArray(ref subexpressions) => { + ExprKind::Array(ref subexpressions) => { walk_list!(visitor, visit_expr, subexpressions); } - ExprRepeat(ref element, ref count) => { + ExprKind::Repeat(ref element, ref count) => { visitor.visit_expr(element); visitor.visit_anon_const(count) } - ExprStruct(ref qpath, ref fields, ref optional_base) => { + ExprKind::Struct(ref qpath, ref fields, ref optional_base) => { visitor.visit_qpath(qpath, expression.id, expression.span); for field in fields { visitor.visit_id(field.id); @@ -982,78 +982,78 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { } walk_list!(visitor, visit_expr, optional_base); } - ExprTup(ref subexpressions) => { + ExprKind::Tup(ref subexpressions) => { walk_list!(visitor, visit_expr, subexpressions); } - ExprCall(ref callee_expression, ref arguments) => { + ExprKind::Call(ref callee_expression, ref arguments) => { visitor.visit_expr(callee_expression); walk_list!(visitor, visit_expr, arguments); } - ExprMethodCall(ref segment, _, ref arguments) => { + ExprKind::MethodCall(ref segment, _, ref arguments) => { visitor.visit_path_segment(expression.span, segment); walk_list!(visitor, visit_expr, arguments); } - ExprBinary(_, ref left_expression, ref right_expression) => { + ExprKind::Binary(_, ref left_expression, ref right_expression) => { visitor.visit_expr(left_expression); visitor.visit_expr(right_expression) } - ExprAddrOf(_, ref subexpression) | ExprUnary(_, ref subexpression) => { + ExprKind::AddrOf(_, ref subexpression) | ExprKind::Unary(_, ref subexpression) => { visitor.visit_expr(subexpression) } - ExprLit(_) => {} - ExprCast(ref subexpression, ref typ) | ExprType(ref subexpression, ref typ) => { + ExprKind::Lit(_) => {} + ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => { visitor.visit_expr(subexpression); visitor.visit_ty(typ) } - ExprIf(ref head_expression, ref if_block, ref optional_else) => { + ExprKind::If(ref head_expression, ref if_block, ref optional_else) => { visitor.visit_expr(head_expression); visitor.visit_expr(if_block); walk_list!(visitor, visit_expr, optional_else); } - ExprWhile(ref subexpression, ref block, ref opt_label) => { + ExprKind::While(ref subexpression, ref block, ref opt_label) => { walk_list!(visitor, visit_label, opt_label); visitor.visit_expr(subexpression); visitor.visit_block(block); } - ExprLoop(ref block, ref opt_label, _) => { + ExprKind::Loop(ref block, ref opt_label, _) => { walk_list!(visitor, visit_label, opt_label); visitor.visit_block(block); } - ExprMatch(ref subexpression, ref arms, _) => { + ExprKind::Match(ref subexpression, ref arms, _) => { visitor.visit_expr(subexpression); walk_list!(visitor, visit_arm, arms); } - ExprClosure(_, ref function_declaration, body, _fn_decl_span, _gen) => { + ExprKind::Closure(_, ref function_declaration, body, _fn_decl_span, _gen) => { visitor.visit_fn(FnKind::Closure(&expression.attrs), function_declaration, body, expression.span, expression.id) } - ExprBlock(ref block, ref opt_label) => { + ExprKind::Block(ref block, ref opt_label) => { walk_list!(visitor, visit_label, opt_label); visitor.visit_block(block); } - ExprAssign(ref left_hand_expression, ref right_hand_expression) => { + ExprKind::Assign(ref left_hand_expression, ref right_hand_expression) => { visitor.visit_expr(right_hand_expression); visitor.visit_expr(left_hand_expression) } - ExprAssignOp(_, ref left_expression, ref right_expression) => { + ExprKind::AssignOp(_, ref left_expression, ref right_expression) => { visitor.visit_expr(right_expression); visitor.visit_expr(left_expression) } - ExprField(ref subexpression, ident) => { + ExprKind::Field(ref subexpression, ident) => { visitor.visit_expr(subexpression); visitor.visit_ident(ident); } - ExprIndex(ref main_expression, ref index_expression) => { + ExprKind::Index(ref main_expression, ref index_expression) => { visitor.visit_expr(main_expression); visitor.visit_expr(index_expression) } - ExprPath(ref qpath) => { + ExprKind::Path(ref qpath) => { visitor.visit_qpath(qpath, expression.id, expression.span); } - ExprBreak(ref destination, ref opt_expr) => { + ExprKind::Break(ref destination, ref opt_expr) => { if let Some(ref label) = destination.label { visitor.visit_label(label); match destination.target_id { @@ -1063,7 +1063,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { } walk_list!(visitor, visit_expr, opt_expr); } - ExprContinue(ref destination) => { + ExprKind::Continue(ref destination) => { if let Some(ref label) = destination.label { visitor.visit_label(label); match destination.target_id { @@ -1072,10 +1072,10 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { }; } } - ExprRet(ref optional_expression) => { + ExprKind::Ret(ref optional_expression) => { walk_list!(visitor, visit_expr, optional_expression); } - ExprInlineAsm(_, ref outputs, ref inputs) => { + ExprKind::InlineAsm(_, ref outputs, ref inputs) => { for output in outputs { visitor.visit_expr(output) } @@ -1083,7 +1083,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { visitor.visit_expr(input) } } - ExprYield(ref subexpression) => { + ExprKind::Yield(ref subexpression) => { visitor.visit_expr(subexpression); } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index c6f2f71460e26..a583ef0c09f1e 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -853,7 +853,7 @@ impl<'a> LoweringContext<'a> { closure_node_id: NodeId, ret_ty: Option<&Ty>, body: impl FnOnce(&mut LoweringContext) -> hir::Expr, - ) -> hir::Expr_ { + ) -> hir::ExprKind { let prev_is_generator = mem::replace(&mut self.is_generator, true); let body_expr = body(self); let span = body_expr.span; @@ -875,7 +875,7 @@ impl<'a> LoweringContext<'a> { let generator = hir::Expr { id: closure_node_id, hir_id: closure_hir_id, - node: hir::ExprClosure(capture_clause, decl, body_id, span, + node: hir::ExprKind::Closure(capture_clause, decl, body_id, span, Some(hir::GeneratorMovability::Static)), span, attrs: ThinVec::new(), @@ -884,7 +884,7 @@ impl<'a> LoweringContext<'a> { let unstable_span = self.allow_internal_unstable(CompilerDesugaringKind::Async, span); let gen_future = self.expr_std_path( unstable_span, &["future", "from_generator"], None, ThinVec::new()); - hir::ExprCall(P(gen_future), hir_vec![generator]) + hir::ExprKind::Call(P(gen_future), hir_vec![generator]) } fn lower_body(&mut self, decl: Option<&FnDecl>, f: F) -> hir::BodyId @@ -3468,25 +3468,25 @@ impl<'a> LoweringContext<'a> { fn lower_expr(&mut self, e: &Expr) -> hir::Expr { let kind = match e.node { - ExprKind::Box(ref inner) => hir::ExprBox(P(self.lower_expr(inner))), + ExprKind::Box(ref inner) => hir::ExprKind::Box(P(self.lower_expr(inner))), ExprKind::ObsoleteInPlace(..) => { self.sess.abort_if_errors(); span_bug!(e.span, "encountered ObsoleteInPlace expr during lowering"); } ExprKind::Array(ref exprs) => { - hir::ExprArray(exprs.iter().map(|x| self.lower_expr(x)).collect()) + hir::ExprKind::Array(exprs.iter().map(|x| self.lower_expr(x)).collect()) } ExprKind::Repeat(ref expr, ref count) => { let expr = P(self.lower_expr(expr)); let count = self.lower_anon_const(count); - hir::ExprRepeat(expr, count) + hir::ExprKind::Repeat(expr, count) } ExprKind::Tup(ref elts) => { - hir::ExprTup(elts.iter().map(|x| self.lower_expr(x)).collect()) + hir::ExprKind::Tup(elts.iter().map(|x| self.lower_expr(x)).collect()) } ExprKind::Call(ref f, ref args) => { let f = P(self.lower_expr(f)); - hir::ExprCall(f, args.iter().map(|x| self.lower_expr(x)).collect()) + hir::ExprKind::Call(f, args.iter().map(|x| self.lower_expr(x)).collect()) } ExprKind::MethodCall(ref seg, ref args) => { let hir_seg = self.lower_path_segment( @@ -3498,32 +3498,32 @@ impl<'a> LoweringContext<'a> { ImplTraitContext::Disallowed, ); let args = args.iter().map(|x| self.lower_expr(x)).collect(); - hir::ExprMethodCall(hir_seg, seg.ident.span, args) + hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args) } ExprKind::Binary(binop, ref lhs, ref rhs) => { let binop = self.lower_binop(binop); let lhs = P(self.lower_expr(lhs)); let rhs = P(self.lower_expr(rhs)); - hir::ExprBinary(binop, lhs, rhs) + hir::ExprKind::Binary(binop, lhs, rhs) } ExprKind::Unary(op, ref ohs) => { let op = self.lower_unop(op); let ohs = P(self.lower_expr(ohs)); - hir::ExprUnary(op, ohs) + hir::ExprKind::Unary(op, ohs) } - ExprKind::Lit(ref l) => hir::ExprLit(P((**l).clone())), + ExprKind::Lit(ref l) => hir::ExprKind::Lit(P((**l).clone())), ExprKind::Cast(ref expr, ref ty) => { let expr = P(self.lower_expr(expr)); - hir::ExprCast(expr, self.lower_ty(ty, ImplTraitContext::Disallowed)) + hir::ExprKind::Cast(expr, self.lower_ty(ty, ImplTraitContext::Disallowed)) } ExprKind::Type(ref expr, ref ty) => { let expr = P(self.lower_expr(expr)); - hir::ExprType(expr, self.lower_ty(ty, ImplTraitContext::Disallowed)) + hir::ExprKind::Type(expr, self.lower_ty(ty, ImplTraitContext::Disallowed)) } ExprKind::AddrOf(m, ref ohs) => { let m = self.lower_mutability(m); let ohs = P(self.lower_expr(ohs)); - hir::ExprAddrOf(m, ohs) + hir::ExprKind::AddrOf(m, ohs) } // More complicated than you might expect because the else branch // might be `if let`. @@ -3554,17 +3554,17 @@ impl<'a> LoweringContext<'a> { let then_blk = self.lower_block(blk, false); let then_expr = self.expr_block(then_blk, ThinVec::new()); - hir::ExprIf(P(self.lower_expr(cond)), P(then_expr), else_opt) + hir::ExprKind::If(P(self.lower_expr(cond)), P(then_expr), else_opt) } ExprKind::While(ref cond, ref body, opt_label) => self.with_loop_scope(e.id, |this| { - hir::ExprWhile( + hir::ExprKind::While( this.with_loop_condition_scope(|this| P(this.lower_expr(cond))), this.lower_block(body, false), this.lower_label(opt_label), ) }), ExprKind::Loop(ref body, opt_label) => self.with_loop_scope(e.id, |this| { - hir::ExprLoop( + hir::ExprKind::Loop( this.lower_block(body, false), this.lower_label(opt_label), hir::LoopSource::Loop, @@ -3582,7 +3582,7 @@ impl<'a> LoweringContext<'a> { hir::Expr { id: node_id, span, - node: hir::ExprTup(hir_vec![]), + node: hir::ExprKind::Tup(hir_vec![]), attrs: ThinVec::new(), hir_id, } @@ -3591,10 +3591,10 @@ impl<'a> LoweringContext<'a> { ); block.expr = Some(this.wrap_in_try_constructor( "from_ok", tail, unstable_span)); - hir::ExprBlock(P(block), None) + hir::ExprKind::Block(P(block), None) }) } - ExprKind::Match(ref expr, ref arms) => hir::ExprMatch( + ExprKind::Match(ref expr, ref arms) => hir::ExprKind::Match( P(self.lower_expr(expr)), arms.iter().map(|x| self.lower_arm(x)).collect(), hir::MatchSource::Normal, @@ -3652,7 +3652,7 @@ impl<'a> LoweringContext<'a> { }); this.expr(fn_decl_span, async_body, ThinVec::new()) }); - hir::ExprClosure( + hir::ExprKind::Closure( this.lower_capture_clause(capture_clause), fn_decl, body_id, @@ -3696,7 +3696,7 @@ impl<'a> LoweringContext<'a> { } None }; - hir::ExprClosure( + hir::ExprKind::Closure( this.lower_capture_clause(capture_clause), fn_decl, body_id, @@ -3707,21 +3707,21 @@ impl<'a> LoweringContext<'a> { } } ExprKind::Block(ref blk, opt_label) => { - hir::ExprBlock(self.lower_block(blk, + hir::ExprKind::Block(self.lower_block(blk, opt_label.is_some()), self.lower_label(opt_label)) } ExprKind::Assign(ref el, ref er) => { - hir::ExprAssign(P(self.lower_expr(el)), P(self.lower_expr(er))) + hir::ExprKind::Assign(P(self.lower_expr(el)), P(self.lower_expr(er))) } - ExprKind::AssignOp(op, ref el, ref er) => hir::ExprAssignOp( + ExprKind::AssignOp(op, ref el, ref er) => hir::ExprKind::AssignOp( self.lower_binop(op), P(self.lower_expr(el)), P(self.lower_expr(er)), ), - ExprKind::Field(ref el, ident) => hir::ExprField(P(self.lower_expr(el)), ident), + ExprKind::Field(ref el, ident) => hir::ExprKind::Field(P(self.lower_expr(el)), ident), ExprKind::Index(ref el, ref er) => { - hir::ExprIndex(P(self.lower_expr(el)), P(self.lower_expr(er))) + hir::ExprKind::Index(P(self.lower_expr(el)), P(self.lower_expr(er))) } // Desugar `..=` to `std::ops::RangeInclusive::new(, )` ExprKind::Range(Some(ref e1), Some(ref e2), RangeLimits::Closed) => { @@ -3734,8 +3734,8 @@ impl<'a> LoweringContext<'a> { let ty = P(self.ty_path(id, span, hir::QPath::Resolved(None, ty_path))); let new_seg = P(hir::PathSegment::from_ident(Ident::from_str("new"))); let new_path = hir::QPath::TypeRelative(ty, new_seg); - let new = P(self.expr(span, hir::ExprPath(new_path), ThinVec::new())); - hir::ExprCall(new, hir_vec![e1, e2]) + let new = P(self.expr(span, hir::ExprKind::Path(new_path), ThinVec::new())); + hir::ExprKind::Call(new, hir_vec![e1, e2]) } ExprKind::Range(ref e1, ref e2, lims) => { use syntax::ast::RangeLimits::*; @@ -3779,15 +3779,15 @@ impl<'a> LoweringContext<'a> { id: node_id, hir_id, node: if is_unit { - hir::ExprPath(struct_path) + hir::ExprKind::Path(struct_path) } else { - hir::ExprStruct(struct_path, fields, None) + hir::ExprKind::Struct(struct_path, fields, None) }, span: unstable_span, attrs: e.attrs.clone(), }; } - ExprKind::Path(ref qself, ref path) => hir::ExprPath(self.lower_qpath( + ExprKind::Path(ref qself, ref path) => hir::ExprKind::Path(self.lower_qpath( e.id, qself, path, @@ -3803,13 +3803,13 @@ impl<'a> LoweringContext<'a> { } else { self.lower_loop_destination(opt_label.map(|label| (e.id, label))) }; - hir::ExprBreak( + hir::ExprKind::Break( destination, opt_expr.as_ref().map(|x| P(self.lower_expr(x))), ) } ExprKind::Continue(opt_label) => { - hir::ExprContinue(if self.is_in_loop_condition && opt_label.is_none() { + hir::ExprKind::Continue(if self.is_in_loop_condition && opt_label.is_none() { hir::Destination { label: None, target_id: Err(hir::LoopIdError::UnlabeledCfInWhileCondition).into(), @@ -3818,7 +3818,7 @@ impl<'a> LoweringContext<'a> { self.lower_loop_destination(opt_label.map(|label| (e.id, label))) }) } - ExprKind::Ret(ref e) => hir::ExprRet(e.as_ref().map(|x| P(self.lower_expr(x)))), + ExprKind::Ret(ref e) => hir::ExprKind::Ret(e.as_ref().map(|x| P(self.lower_expr(x)))), ExprKind::InlineAsm(ref asm) => { let hir_asm = hir::InlineAsm { inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(), @@ -3846,9 +3846,9 @@ impl<'a> LoweringContext<'a> { .iter() .map(|&(_, ref input)| self.lower_expr(input)) .collect(); - hir::ExprInlineAsm(P(hir_asm), outputs, inputs) + hir::ExprKind::InlineAsm(P(hir_asm), outputs, inputs) } - ExprKind::Struct(ref path, ref fields, ref maybe_expr) => hir::ExprStruct( + ExprKind::Struct(ref path, ref fields, ref maybe_expr) => hir::ExprKind::Struct( self.lower_qpath( e.id, &None, @@ -3877,8 +3877,8 @@ impl<'a> LoweringContext<'a> { let expr = opt_expr .as_ref() .map(|x| self.lower_expr(x)) - .unwrap_or_else(|| self.expr(e.span, hir::ExprTup(hir_vec![]), ThinVec::new())); - hir::ExprYield(P(expr)) + .unwrap_or_else(|| self.expr(e.span, hir::ExprKind::Tup(hir_vec![]), ThinVec::new())); + hir::ExprKind::Yield(P(expr)) } // Desugar ExprIfLet @@ -3917,7 +3917,7 @@ impl<'a> LoweringContext<'a> { let sub_expr = P(self.lower_expr(sub_expr)); - hir::ExprMatch( + hir::ExprKind::Match( sub_expr, arms.into(), hir::MatchSource::IfLetDesugar { @@ -3965,13 +3965,13 @@ impl<'a> LoweringContext<'a> { let arms = hir_vec![pat_arm, break_arm]; let match_expr = self.expr( sub_expr.span, - hir::ExprMatch(sub_expr, arms, hir::MatchSource::WhileLetDesugar), + hir::ExprKind::Match(sub_expr, arms, hir::MatchSource::WhileLetDesugar), ThinVec::new(), ); // `[opt_ident]: loop { ... }` let loop_block = P(self.block_expr(P(match_expr))); - let loop_expr = hir::ExprLoop( + let loop_expr = hir::ExprKind::Loop( loop_block, self.lower_label(opt_label), hir::LoopSource::WhileLet, @@ -4023,7 +4023,7 @@ impl<'a> LoweringContext<'a> { let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat.id)); let assign = P(self.expr( pat.span, - hir::ExprAssign(next_expr, val_expr), + hir::ExprKind::Assign(next_expr, val_expr), ThinVec::new(), )); let some_pat = self.pat_some(pat.span, val_pat); @@ -4053,7 +4053,7 @@ impl<'a> LoweringContext<'a> { P(self.expr( head_sp, - hir::ExprMatch(next_expr, arms, hir::MatchSource::ForLoopDesugar), + hir::ExprKind::Match(next_expr, arms, hir::MatchSource::ForLoopDesugar), ThinVec::new(), )) }; @@ -4085,7 +4085,7 @@ impl<'a> LoweringContext<'a> { )); // `[opt_ident]: loop { ... }` - let loop_expr = hir::ExprLoop( + let loop_expr = hir::ExprKind::Loop( loop_block, self.lower_label(opt_label), hir::LoopSource::ForLoop, @@ -4205,7 +4205,7 @@ impl<'a> LoweringContext<'a> { let ret_expr = if let Some(catch_node) = catch_scope { P(self.expr( e.span, - hir::ExprBreak( + hir::ExprKind::Break( hir::Destination { label: None, target_id: Ok(catch_node), @@ -4215,14 +4215,14 @@ impl<'a> LoweringContext<'a> { thin_attrs, )) } else { - P(self.expr(e.span, hir::Expr_::ExprRet(Some(from_err_expr)), thin_attrs)) + P(self.expr(e.span, hir::ExprKind::Ret(Some(from_err_expr)), thin_attrs)) }; let err_pat = self.pat_err(e.span, err_local); self.arm(hir_vec![err_pat], ret_expr) }; - hir::ExprMatch( + hir::ExprKind::Match( discr, hir_vec![err_arm, ok_arm], hir::MatchSource::TryDesugar, @@ -4390,7 +4390,7 @@ impl<'a> LoweringContext<'a> { } fn expr_break(&mut self, span: Span, attrs: ThinVec) -> P { - let expr_break = hir::ExprBreak(self.lower_loop_destination(None), None); + let expr_break = hir::ExprKind::Break(self.lower_loop_destination(None), None); P(self.expr(span, expr_break, attrs)) } @@ -4400,7 +4400,7 @@ impl<'a> LoweringContext<'a> { e: P, args: hir::HirVec, ) -> hir::Expr { - self.expr(span, hir::ExprCall(e, args), ThinVec::new()) + self.expr(span, hir::ExprKind::Call(e, args), ThinVec::new()) } fn expr_ident(&mut self, span: Span, ident: Ident, binding: NodeId) -> hir::Expr { @@ -4414,7 +4414,7 @@ impl<'a> LoweringContext<'a> { binding: NodeId, attrs: ThinVec, ) -> hir::Expr { - let expr_path = hir::ExprPath(hir::QPath::Resolved( + let expr_path = hir::ExprKind::Path(hir::QPath::Resolved( None, P(hir::Path { span, @@ -4427,7 +4427,7 @@ impl<'a> LoweringContext<'a> { } fn expr_mut_addr_of(&mut self, span: Span, e: P) -> hir::Expr { - self.expr(span, hir::ExprAddrOf(hir::MutMutable, e), ThinVec::new()) + self.expr(span, hir::ExprKind::AddrOf(hir::MutMutable, e), ThinVec::new()) } fn expr_std_path( @@ -4440,7 +4440,7 @@ impl<'a> LoweringContext<'a> { let path = self.std_path(span, components, params, true); self.expr( span, - hir::ExprPath(hir::QPath::Resolved(None, P(path))), + hir::ExprKind::Path(hir::QPath::Resolved(None, P(path))), attrs, ) } @@ -4452,18 +4452,18 @@ impl<'a> LoweringContext<'a> { arms: hir::HirVec, source: hir::MatchSource, ) -> hir::Expr { - self.expr(span, hir::ExprMatch(arg, arms, source), ThinVec::new()) + self.expr(span, hir::ExprKind::Match(arg, arms, source), ThinVec::new()) } fn expr_block(&mut self, b: P, attrs: ThinVec) -> hir::Expr { - self.expr(b.span, hir::ExprBlock(b, None), attrs) + self.expr(b.span, hir::ExprKind::Block(b, None), attrs) } fn expr_tuple(&mut self, sp: Span, exprs: hir::HirVec) -> P { - P(self.expr(sp, hir::ExprTup(exprs), ThinVec::new())) + P(self.expr(sp, hir::ExprKind::Tup(exprs), ThinVec::new())) } - fn expr(&mut self, span: Span, node: hir::Expr_, attrs: ThinVec) -> hir::Expr { + fn expr(&mut self, span: Span, node: hir::ExprKind, attrs: ThinVec) -> hir::Expr { let LoweredNodeId { node_id, hir_id } = self.next_id(); hir::Expr { id: node_id, diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 930db8b0ccc3f..6d4bff5a35282 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -34,7 +34,7 @@ use syntax_pos::Span; /// More specifically, it is one of either: /// /// - A function item, -/// - A closure expr (i.e. an ExprClosure), or +/// - A closure expr (i.e. an ExprKind::Closure), or /// - The default implementation for a trait method. /// /// To construct one, use the `Code::from_node` function. @@ -63,7 +63,7 @@ impl MaybeFnLike for ast::TraitItem { impl MaybeFnLike for ast::Expr { fn is_fn_like(&self) -> bool { match self.node { - ast::ExprClosure(..) => true, + ast::ExprKind::Closure(..) => true, _ => false, } } @@ -260,7 +260,7 @@ impl<'a> FnLikeNode<'a> { } }, map::NodeExpr(e) => match e.node { - ast::ExprClosure(_, ref decl, block, _fn_decl_span, _gen) => + ast::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) => closure(ClosureParts::new(&decl, block, e.id, e.span, &e.attrs)), _ => bug!("expr FnLikeNode that is not fn-like"), }, diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 6298c3882533b..ae77f634d7918 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -195,7 +195,7 @@ impl<'hir> MapEntry<'hir> { EntryExpr(_, _, ref expr) => { match expr.node { - ExprClosure(_, ref fn_decl, ..) => Some(&fn_decl), + ExprKind::Closure(_, ref fn_decl, ..) => Some(&fn_decl), _ => None, } } @@ -235,7 +235,7 @@ impl<'hir> MapEntry<'hir> { EntryExpr(_, _, expr) => { match expr.node { - ExprClosure(.., body, _, _) => Some(body), + ExprKind::Closure(.., body, _, _) => Some(body), _ => None, } } @@ -734,7 +734,7 @@ impl<'hir> Map<'hir> { Some(NodeImplItem(_)) => true, Some(NodeExpr(e)) => { match e.node { - ExprClosure(..) => true, + ExprKind::Closure(..) => true, _ => false, } } @@ -821,7 +821,7 @@ impl<'hir> Map<'hir> { match *node { NodeExpr(ref expr) => { match expr.node { - ExprWhile(..) | ExprLoop(..) => true, + ExprKind::While(..) | ExprKind::Loop(..) => true, _ => false, } } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 5ae0c3250fff6..5a185b966fd1d 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -12,7 +12,6 @@ pub use self::BlockCheckMode::*; pub use self::CaptureClause::*; -pub use self::ExprKind::*; pub use self::FunctionRetTy::*; pub use self::ForeignItem_::*; pub use self::Item_::*; @@ -1285,7 +1284,7 @@ pub struct AnonConst { pub struct Expr { pub id: NodeId, pub span: Span, - pub node: Expr_, + pub node: ExprKind, pub attrs: ThinVec, pub hir_id: HirId, } @@ -1293,34 +1292,34 @@ pub struct Expr { impl Expr { pub fn precedence(&self) -> ExprPrecedence { match self.node { - ExprBox(_) => ExprPrecedence::Box, - ExprArray(_) => ExprPrecedence::Array, - ExprCall(..) => ExprPrecedence::Call, - ExprMethodCall(..) => ExprPrecedence::MethodCall, - ExprTup(_) => ExprPrecedence::Tup, - ExprBinary(op, ..) => ExprPrecedence::Binary(op.node.into()), - ExprUnary(..) => ExprPrecedence::Unary, - ExprLit(_) => ExprPrecedence::Lit, - ExprType(..) | ExprCast(..) => ExprPrecedence::Cast, - ExprIf(..) => ExprPrecedence::If, - ExprWhile(..) => ExprPrecedence::While, - ExprLoop(..) => ExprPrecedence::Loop, - ExprMatch(..) => ExprPrecedence::Match, - ExprClosure(..) => ExprPrecedence::Closure, - ExprBlock(..) => ExprPrecedence::Block, - ExprAssign(..) => ExprPrecedence::Assign, - ExprAssignOp(..) => ExprPrecedence::AssignOp, - ExprField(..) => ExprPrecedence::Field, - ExprIndex(..) => ExprPrecedence::Index, - ExprPath(..) => ExprPrecedence::Path, - ExprAddrOf(..) => ExprPrecedence::AddrOf, - ExprBreak(..) => ExprPrecedence::Break, - ExprContinue(..) => ExprPrecedence::Continue, - ExprRet(..) => ExprPrecedence::Ret, - ExprInlineAsm(..) => ExprPrecedence::InlineAsm, - ExprStruct(..) => ExprPrecedence::Struct, - ExprRepeat(..) => ExprPrecedence::Repeat, - ExprYield(..) => ExprPrecedence::Yield, + ExprKind::Box(_) => ExprPrecedence::Box, + ExprKind::Array(_) => ExprPrecedence::Array, + ExprKind::Call(..) => ExprPrecedence::Call, + ExprKind::MethodCall(..) => ExprPrecedence::MethodCall, + ExprKind::Tup(_) => ExprPrecedence::Tup, + ExprKind::Binary(op, ..) => ExprPrecedence::Binary(op.node.into()), + ExprKind::Unary(..) => ExprPrecedence::Unary, + ExprKind::Lit(_) => ExprPrecedence::Lit, + ExprKind::Type(..) | ExprKind::Cast(..) => ExprPrecedence::Cast, + ExprKind::If(..) => ExprPrecedence::If, + ExprKind::While(..) => ExprPrecedence::While, + ExprKind::Loop(..) => ExprPrecedence::Loop, + ExprKind::Match(..) => ExprPrecedence::Match, + ExprKind::Closure(..) => ExprPrecedence::Closure, + ExprKind::Block(..) => ExprPrecedence::Block, + ExprKind::Assign(..) => ExprPrecedence::Assign, + ExprKind::AssignOp(..) => ExprPrecedence::AssignOp, + ExprKind::Field(..) => ExprPrecedence::Field, + ExprKind::Index(..) => ExprPrecedence::Index, + ExprKind::Path(..) => ExprPrecedence::Path, + ExprKind::AddrOf(..) => ExprPrecedence::AddrOf, + ExprKind::Break(..) => ExprPrecedence::Break, + ExprKind::Continue(..) => ExprPrecedence::Continue, + ExprKind::Ret(..) => ExprPrecedence::Ret, + ExprKind::InlineAsm(..) => ExprPrecedence::InlineAsm, + ExprKind::Struct(..) => ExprPrecedence::Struct, + ExprKind::Repeat(..) => ExprPrecedence::Repeat, + ExprKind::Yield(..) => ExprPrecedence::Yield, } } } @@ -1333,18 +1332,18 @@ impl fmt::Debug for Expr { } #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum Expr_ { +pub enum ExprKind { /// A `box x` expression. - ExprBox(P), + Box(P), /// An array (`[a, b, c, d]`) - ExprArray(HirVec), + Array(HirVec), /// A function call /// - /// The first field resolves to the function itself (usually an `ExprPath`), + /// The first field resolves to the function itself (usually an `ExprKind::Path`), /// and the second field is the list of arguments. /// This also represents calling the constructor of /// tuple-like ADTs such as tuple structs and enum variants. - ExprCall(P, HirVec), + Call(P, HirVec), /// A method call (`x.foo::<'static, Bar, Baz>(a, b, c, d)`) /// /// The `PathSegment`/`Span` represent the method name and its generic arguments @@ -1354,83 +1353,83 @@ pub enum Expr_ { /// and the remaining elements are the rest of the arguments. /// Thus, `x.foo::(a, b, c, d)` is represented as /// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, [x, a, b, c, d])`. - ExprMethodCall(PathSegment, Span, HirVec), + MethodCall(PathSegment, Span, HirVec), /// A tuple (`(a, b, c ,d)`) - ExprTup(HirVec), + Tup(HirVec), /// A binary operation (For example: `a + b`, `a * b`) - ExprBinary(BinOp, P, P), + Binary(BinOp, P, P), /// A unary operation (For example: `!x`, `*x`) - ExprUnary(UnOp, P), + Unary(UnOp, P), /// A literal (For example: `1`, `"foo"`) - ExprLit(P), + Lit(P), /// A cast (`foo as f64`) - ExprCast(P, P), - ExprType(P, P), + Cast(P, P), + Type(P, P), /// An `if` block, with an optional else block /// /// `if expr { expr } else { expr }` - ExprIf(P, P, Option>), + If(P, P, Option>), /// A while loop, with an optional label /// /// `'label: while expr { block }` - ExprWhile(P, P, Option