From fe8955bd585b8e49b01697684becb6a353413fea Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Wed, 11 Jul 2018 18:44:53 +0800 Subject: [PATCH 01/11] BinOpKind --- src/librustc/hir/lowering.rs | 36 +++--- src/librustc/hir/mod.rs | 152 ++++++++++++------------ src/librustc/hir/print.rs | 50 ++++---- src/librustc/ich/impls_hir.rs | 44 +++---- src/librustc/middle/region.rs | 4 +- src/librustc/mir/tcx.rs | 34 +++--- src/librustc_codegen_llvm/base.rs | 34 +++--- src/librustc_codegen_llvm/common.rs | 4 +- src/librustc_codegen_llvm/intrinsic.rs | 12 +- src/librustc_lint/types.rs | 20 ++-- src/librustc_lint/unused.rs | 8 +- src/librustc_mir/hair/cx/expr.rs | 42 +++---- src/librustc_passes/rvalue_promotion.rs | 6 +- src/librustc_typeck/check/op.rs | 144 +++++++++++----------- 14 files changed, 297 insertions(+), 293 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index cb53f963d41f1..86f6e08215e52 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -3314,24 +3314,24 @@ impl<'a> LoweringContext<'a> { fn lower_binop(&mut self, b: BinOp) -> hir::BinOp { Spanned { node: match b.node { - BinOpKind::Add => hir::BiAdd, - BinOpKind::Sub => hir::BiSub, - BinOpKind::Mul => hir::BiMul, - BinOpKind::Div => hir::BiDiv, - BinOpKind::Rem => hir::BiRem, - BinOpKind::And => hir::BiAnd, - BinOpKind::Or => hir::BiOr, - BinOpKind::BitXor => hir::BiBitXor, - BinOpKind::BitAnd => hir::BiBitAnd, - BinOpKind::BitOr => hir::BiBitOr, - BinOpKind::Shl => hir::BiShl, - BinOpKind::Shr => hir::BiShr, - BinOpKind::Eq => hir::BiEq, - BinOpKind::Lt => hir::BiLt, - BinOpKind::Le => hir::BiLe, - BinOpKind::Ne => hir::BiNe, - BinOpKind::Ge => hir::BiGe, - BinOpKind::Gt => hir::BiGt, + BinOpKind::Add => hir::BinOpKind::Add, + BinOpKind::Sub => hir::BinOpKind::Sub, + BinOpKind::Mul => hir::BinOpKind::Mul, + BinOpKind::Div => hir::BinOpKind::Div, + BinOpKind::Rem => hir::BinOpKind::Rem, + BinOpKind::And => hir::BinOpKind::And, + BinOpKind::Or => hir::BinOpKind::Or, + BinOpKind::BitXor => hir::BinOpKind::BitXor, + BinOpKind::BitAnd => hir::BinOpKind::BitAnd, + BinOpKind::BitOr => hir::BinOpKind::BitOr, + BinOpKind::Shl => hir::BinOpKind::Shl, + BinOpKind::Shr => hir::BinOpKind::Shr, + BinOpKind::Eq => hir::BinOpKind::Eq, + BinOpKind::Lt => hir::BinOpKind::Lt, + BinOpKind::Le => hir::BinOpKind::Le, + BinOpKind::Ne => hir::BinOpKind::Ne, + BinOpKind::Ge => hir::BinOpKind::Ge, + BinOpKind::Gt => hir::BinOpKind::Gt, }, span: b.span, } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index bf83fa15727d1..594fae972b173 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -10,7 +10,6 @@ // The Rust HIR. -pub use self::BinOp_::*; pub use self::BlockCheckMode::*; pub use self::CaptureClause::*; pub use self::Decl_::*; @@ -941,98 +940,103 @@ impl Mutability { } #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash)] -pub enum BinOp_ { +pub enum BinOpKind { /// The `+` operator (addition) - BiAdd, + Add, /// The `-` operator (subtraction) - BiSub, + Sub, /// The `*` operator (multiplication) - BiMul, + Mul, /// The `/` operator (division) - BiDiv, + Div, /// The `%` operator (modulus) - BiRem, + Rem, /// The `&&` operator (logical and) - BiAnd, + And, /// The `||` operator (logical or) - BiOr, + Or, /// The `^` operator (bitwise xor) - BiBitXor, + BitXor, /// The `&` operator (bitwise and) - BiBitAnd, + BitAnd, /// The `|` operator (bitwise or) - BiBitOr, + BitOr, /// The `<<` operator (shift left) - BiShl, + Shl, /// The `>>` operator (shift right) - BiShr, + Shr, /// The `==` operator (equality) - BiEq, + Eq, /// The `<` operator (less than) - BiLt, + Lt, /// The `<=` operator (less than or equal to) - BiLe, + Le, /// The `!=` operator (not equal to) - BiNe, + Ne, /// The `>=` operator (greater than or equal to) - BiGe, + Ge, /// The `>` operator (greater than) - BiGt, + Gt, } -impl BinOp_ { +impl BinOpKind { pub fn as_str(self) -> &'static str { match self { - BiAdd => "+", - BiSub => "-", - BiMul => "*", - BiDiv => "/", - BiRem => "%", - BiAnd => "&&", - BiOr => "||", - BiBitXor => "^", - BiBitAnd => "&", - BiBitOr => "|", - BiShl => "<<", - BiShr => ">>", - BiEq => "==", - BiLt => "<", - BiLe => "<=", - BiNe => "!=", - BiGe => ">=", - BiGt => ">", + BinOpKind::Add => "+", + BinOpKind::Sub => "-", + BinOpKind::Mul => "*", + BinOpKind::Div => "/", + BinOpKind::Rem => "%", + BinOpKind::And => "&&", + BinOpKind::Or => "||", + BinOpKind::BitXor => "^", + BinOpKind::BitAnd => "&", + BinOpKind::BitOr => "|", + BinOpKind::Shl => "<<", + BinOpKind::Shr => ">>", + BinOpKind::Eq => "==", + BinOpKind::Lt => "<", + BinOpKind::Le => "<=", + BinOpKind::Ne => "!=", + BinOpKind::Ge => ">=", + BinOpKind::Gt => ">", } } pub fn is_lazy(self) -> bool { match self { - BiAnd | BiOr => true, + BinOpKind::And | BinOpKind::Or => true, _ => false, } } pub fn is_shift(self) -> bool { match self { - BiShl | BiShr => true, + BinOpKind::Shl | BinOpKind::Shr => true, _ => false, } } pub fn is_comparison(self) -> bool { match self { - BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true, - BiAnd | - BiOr | - BiAdd | - BiSub | - BiMul | - BiDiv | - BiRem | - BiBitXor | - BiBitAnd | - BiBitOr | - BiShl | - BiShr => false, + BinOpKind::Eq | + BinOpKind::Lt | + BinOpKind::Le | + BinOpKind::Ne | + BinOpKind::Gt | + BinOpKind::Ge => true, + BinOpKind::And | + BinOpKind::Or | + BinOpKind::Add | + BinOpKind::Sub | + BinOpKind::Mul | + BinOpKind::Div | + BinOpKind::Rem | + BinOpKind::BitXor | + BinOpKind::BitAnd | + BinOpKind::BitOr | + BinOpKind::Shl | + BinOpKind::Shr => false, } } @@ -1042,32 +1046,32 @@ impl BinOp_ { } } -impl Into for BinOp_ { +impl Into for BinOpKind { fn into(self) -> ast::BinOpKind { match self { - BiAdd => ast::BinOpKind::Add, - BiSub => ast::BinOpKind::Sub, - BiMul => ast::BinOpKind::Mul, - BiDiv => ast::BinOpKind::Div, - BiRem => ast::BinOpKind::Rem, - BiAnd => ast::BinOpKind::And, - BiOr => ast::BinOpKind::Or, - BiBitXor => ast::BinOpKind::BitXor, - BiBitAnd => ast::BinOpKind::BitAnd, - BiBitOr => ast::BinOpKind::BitOr, - BiShl => ast::BinOpKind::Shl, - BiShr => ast::BinOpKind::Shr, - BiEq => ast::BinOpKind::Eq, - BiLt => ast::BinOpKind::Lt, - BiLe => ast::BinOpKind::Le, - BiNe => ast::BinOpKind::Ne, - BiGe => ast::BinOpKind::Ge, - BiGt => ast::BinOpKind::Gt, + BinOpKind::Add => ast::BinOpKind::Add, + BinOpKind::Sub => ast::BinOpKind::Sub, + BinOpKind::Mul => ast::BinOpKind::Mul, + BinOpKind::Div => ast::BinOpKind::Div, + BinOpKind::Rem => ast::BinOpKind::Rem, + BinOpKind::And => ast::BinOpKind::And, + BinOpKind::Or => ast::BinOpKind::Or, + BinOpKind::BitXor => ast::BinOpKind::BitXor, + BinOpKind::BitAnd => ast::BinOpKind::BitAnd, + BinOpKind::BitOr => ast::BinOpKind::BitOr, + BinOpKind::Shl => ast::BinOpKind::Shl, + BinOpKind::Shr => ast::BinOpKind::Shr, + BinOpKind::Eq => ast::BinOpKind::Eq, + BinOpKind::Lt => ast::BinOpKind::Lt, + BinOpKind::Le => ast::BinOpKind::Le, + BinOpKind::Ne => ast::BinOpKind::Ne, + BinOpKind::Ge => ast::BinOpKind::Ge, + BinOpKind::Gt => ast::BinOpKind::Gt, } } } -pub type BinOp = Spanned; +pub type BinOp = Spanned; #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash)] pub enum UnOp { diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 377990ef561a7..3004c0d0224c0 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1292,8 +1292,8 @@ impl<'a> State<'a> { // These cases need parens: `x as i32 < y` has the parser thinking that `i32 < y` is // the beginning of a path type. It starts trying to parse `x as (i32 < y ...` instead // of `(x as i32) < ...`. We need to convince it _not_ to do that. - (&hir::ExprCast { .. }, hir::BinOp_::BiLt) | - (&hir::ExprCast { .. }, hir::BinOp_::BiShl) => parser::PREC_FORCE_PAREN, + (&hir::ExprCast { .. }, hir::BinOpKind::Lt) | + (&hir::ExprCast { .. }, hir::BinOpKind::Shl) => parser::PREC_FORCE_PAREN, _ => left_prec, }; @@ -2413,30 +2413,30 @@ fn stmt_ends_with_semi(stmt: &hir::Stmt_) -> bool { } } -fn bin_op_to_assoc_op(op: hir::BinOp_) -> AssocOp { - use hir::BinOp_::*; +fn bin_op_to_assoc_op(op: hir::BinOpKind) -> AssocOp { + use hir::BinOpKind::*; match op { - BiAdd => AssocOp::Add, - BiSub => AssocOp::Subtract, - BiMul => AssocOp::Multiply, - BiDiv => AssocOp::Divide, - BiRem => AssocOp::Modulus, - - BiAnd => AssocOp::LAnd, - BiOr => AssocOp::LOr, - - BiBitXor => AssocOp::BitXor, - BiBitAnd => AssocOp::BitAnd, - BiBitOr => AssocOp::BitOr, - BiShl => AssocOp::ShiftLeft, - BiShr => AssocOp::ShiftRight, - - BiEq => AssocOp::Equal, - BiLt => AssocOp::Less, - BiLe => AssocOp::LessEqual, - BiNe => AssocOp::NotEqual, - BiGe => AssocOp::GreaterEqual, - BiGt => AssocOp::Greater, + Add => AssocOp::Add, + Sub => AssocOp::Subtract, + Mul => AssocOp::Multiply, + Div => AssocOp::Divide, + Rem => AssocOp::Modulus, + + And => AssocOp::LAnd, + Or => AssocOp::LOr, + + BitXor => AssocOp::BitXor, + BitAnd => AssocOp::BitAnd, + BitOr => AssocOp::BitOr, + Shl => AssocOp::ShiftLeft, + Shr => AssocOp::ShiftRight, + + Eq => AssocOp::Equal, + Lt => AssocOp::Less, + Le => AssocOp::LessEqual, + Ne => AssocOp::NotEqual, + Ge => AssocOp::GreaterEqual, + Gt => AssocOp::Greater, } } diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index b6add3e6f1205..71a8d3ccdaf65 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -437,28 +437,28 @@ impl_stable_hash_for!(enum hir::PatKind { Slice(one, two, three) }); -impl_stable_hash_for!(enum hir::BinOp_ { - BiAdd, - BiSub, - BiMul, - BiDiv, - BiRem, - BiAnd, - BiOr, - BiBitXor, - BiBitAnd, - BiBitOr, - BiShl, - BiShr, - BiEq, - BiLt, - BiLe, - BiNe, - BiGe, - BiGt -}); - -impl_stable_hash_for_spanned!(hir::BinOp_); +impl_stable_hash_for!(enum hir::BinOpKind { + Add, + Sub, + Mul, + Div, + Rem, + And, + Or, + BitXor, + BitAnd, + BitOr, + Shl, + Shr, + Eq, + Lt, + Le, + Ne, + Ge, + Gt +}); + +impl_stable_hash_for_spanned!(hir::BinOpKind); impl_stable_hash_for!(enum hir::UnOp { UnDeref, diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index a11c8f5dc044d..a196820fcf17d 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -943,8 +943,8 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr: // scopes, meaning that temporaries cannot outlive them. // This ensures fixed size stacks. - hir::ExprBinary(codemap::Spanned { node: hir::BiAnd, .. }, _, ref r) | - hir::ExprBinary(codemap::Spanned { node: hir::BiOr, .. }, _, ref r) => { + hir::ExprKind::Binary(codemap::Spanned { node: hir::BinOpKind::And, .. }, _, ref r) | + hir::ExprKind::Binary(codemap::Spanned { node: hir::BinOpKind::Or, .. }, _, ref r) => { // For shortcircuiting operators, mark the RHS as a terminating // scope since it only executes conditionally. terminating(r.hir_id.local_id); diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index 67dfad50f4435..6876b1490f376 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -256,24 +256,24 @@ impl BorrowKind { } impl BinOp { - pub fn to_hir_binop(self) -> hir::BinOp_ { + pub fn to_hir_binop(self) -> hir::BinOpKind { match self { - BinOp::Add => hir::BinOp_::BiAdd, - BinOp::Sub => hir::BinOp_::BiSub, - BinOp::Mul => hir::BinOp_::BiMul, - BinOp::Div => hir::BinOp_::BiDiv, - BinOp::Rem => hir::BinOp_::BiRem, - BinOp::BitXor => hir::BinOp_::BiBitXor, - BinOp::BitAnd => hir::BinOp_::BiBitAnd, - BinOp::BitOr => hir::BinOp_::BiBitOr, - BinOp::Shl => hir::BinOp_::BiShl, - BinOp::Shr => hir::BinOp_::BiShr, - BinOp::Eq => hir::BinOp_::BiEq, - BinOp::Ne => hir::BinOp_::BiNe, - BinOp::Lt => hir::BinOp_::BiLt, - BinOp::Gt => hir::BinOp_::BiGt, - BinOp::Le => hir::BinOp_::BiLe, - BinOp::Ge => hir::BinOp_::BiGe, + BinOp::Add => hir::BinOpKind::Add, + BinOp::Sub => hir::BinOpKind::Sub, + BinOp::Mul => hir::BinOpKind::Mul, + BinOp::Div => hir::BinOpKind::Div, + BinOp::Rem => hir::BinOpKind::Rem, + BinOp::BitXor => hir::BinOpKind::BitXor, + BinOp::BitAnd => hir::BinOpKind::BitAnd, + BinOp::BitOr => hir::BinOpKind::BitOr, + BinOp::Shl => hir::BinOpKind::Shl, + BinOp::Shr => hir::BinOpKind::Shr, + BinOp::Eq => hir::BinOpKind::Eq, + BinOp::Ne => hir::BinOpKind::Ne, + BinOp::Lt => hir::BinOpKind::Lt, + BinOp::Gt => hir::BinOpKind::Gt, + BinOp::Le => hir::BinOpKind::Le, + BinOp::Ge => hir::BinOpKind::Ge, BinOp::Offset => unreachable!() } } diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index ea26e271c9bb3..d4d0b67523e11 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -124,16 +124,16 @@ impl<'a, 'tcx> Drop for StatRecorder<'a, 'tcx> { } } -pub fn bin_op_to_icmp_predicate(op: hir::BinOp_, +pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind, signed: bool) -> llvm::IntPredicate { match op { - hir::BiEq => llvm::IntEQ, - hir::BiNe => llvm::IntNE, - hir::BiLt => if signed { llvm::IntSLT } else { llvm::IntULT }, - hir::BiLe => if signed { llvm::IntSLE } else { llvm::IntULE }, - hir::BiGt => if signed { llvm::IntSGT } else { llvm::IntUGT }, - hir::BiGe => if signed { llvm::IntSGE } else { llvm::IntUGE }, + hir::BinOpKind::Eq => llvm::IntEQ, + hir::BinOpKind::Ne => llvm::IntNE, + hir::BinOpKind::Lt => if signed { llvm::IntSLT } else { llvm::IntULT }, + hir::BinOpKind::Le => if signed { llvm::IntSLE } else { llvm::IntULE }, + hir::BinOpKind::Gt => if signed { llvm::IntSGT } else { llvm::IntUGT }, + hir::BinOpKind::Ge => if signed { llvm::IntSGE } else { llvm::IntUGE }, op => { bug!("comparison_op_to_icmp_predicate: expected comparison operator, \ found {:?}", @@ -142,14 +142,14 @@ pub fn bin_op_to_icmp_predicate(op: hir::BinOp_, } } -pub fn bin_op_to_fcmp_predicate(op: hir::BinOp_) -> llvm::RealPredicate { +pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> llvm::RealPredicate { match op { - hir::BiEq => llvm::RealOEQ, - hir::BiNe => llvm::RealUNE, - hir::BiLt => llvm::RealOLT, - hir::BiLe => llvm::RealOLE, - hir::BiGt => llvm::RealOGT, - hir::BiGe => llvm::RealOGE, + hir::BinOpKind::Eq => llvm::RealOEQ, + hir::BinOpKind::Ne => llvm::RealUNE, + hir::BinOpKind::Lt => llvm::RealOLT, + hir::BinOpKind::Le => llvm::RealOLE, + hir::BinOpKind::Gt => llvm::RealOGT, + hir::BinOpKind::Ge => llvm::RealOGE, op => { bug!("comparison_op_to_fcmp_predicate: expected comparison operator, \ found {:?}", @@ -164,7 +164,7 @@ pub fn compare_simd_types<'a, 'tcx>( rhs: ValueRef, t: Ty<'tcx>, ret_ty: Type, - op: hir::BinOp_ + op: hir::BinOpKind ) -> ValueRef { let signed = match t.sty { ty::TyFloat(_) => { @@ -332,12 +332,12 @@ pub fn coerce_unsized_into<'a, 'tcx>(bx: &Builder<'a, 'tcx>, } pub fn cast_shift_expr_rhs( - cx: &Builder, op: hir::BinOp_, lhs: ValueRef, rhs: ValueRef + cx: &Builder, op: hir::BinOpKind, lhs: ValueRef, rhs: ValueRef ) -> ValueRef { cast_shift_rhs(op, lhs, rhs, |a, b| cx.trunc(a, b), |a, b| cx.zext(a, b)) } -fn cast_shift_rhs(op: hir::BinOp_, +fn cast_shift_rhs(op: hir::BinOpKind, lhs: ValueRef, rhs: ValueRef, trunc: F, diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index 7e55642814bba..60bba635a7887 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -350,7 +350,7 @@ pub fn build_unchecked_lshift<'a, 'tcx>( lhs: ValueRef, rhs: ValueRef ) -> ValueRef { - let rhs = base::cast_shift_expr_rhs(bx, hir::BinOp_::BiShl, lhs, rhs); + let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shl, lhs, rhs); // #1877, #10183: Ensure that input is always valid let rhs = shift_mask_rhs(bx, rhs); bx.shl(lhs, rhs) @@ -359,7 +359,7 @@ pub fn build_unchecked_lshift<'a, 'tcx>( pub fn build_unchecked_rshift<'a, 'tcx>( bx: &Builder<'a, 'tcx>, lhs_t: Ty<'tcx>, lhs: ValueRef, rhs: ValueRef ) -> ValueRef { - let rhs = base::cast_shift_expr_rhs(bx, hir::BinOp_::BiShr, lhs, rhs); + let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shr, lhs, rhs); // #1877, #10183: Ensure that input is always valid let rhs = shift_mask_rhs(bx, rhs); let is_signed = lhs_t.is_signed(); diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 7625e4c7e0f29..58a32ad9774f6 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -1022,12 +1022,12 @@ fn generic_simd_intrinsic<'a, 'tcx>( let in_len = arg_tys[0].simd_size(tcx); let comparison = match name { - "simd_eq" => Some(hir::BiEq), - "simd_ne" => Some(hir::BiNe), - "simd_lt" => Some(hir::BiLt), - "simd_le" => Some(hir::BiLe), - "simd_gt" => Some(hir::BiGt), - "simd_ge" => Some(hir::BiGe), + "simd_eq" => Some(hir::BinOpKind::Eq), + "simd_ne" => Some(hir::BinOpKind::Ne), + "simd_lt" => Some(hir::BinOpKind::Lt), + "simd_le" => Some(hir::BinOpKind::Le), + "simd_gt" => Some(hir::BinOpKind::Gt), + "simd_ge" => Some(hir::BinOpKind::Ge), _ => None }; diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index e5bd6a7f610f3..65aa30ab3c0be 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -194,11 +194,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { fn is_valid(binop: hir::BinOp, v: T, min: T, max: T) -> bool { match binop.node { - hir::BiLt => v > min && v <= max, - hir::BiLe => v >= min && v < max, - hir::BiGt => v >= min && v < max, - hir::BiGe => v > min && v <= max, - hir::BiEq | hir::BiNe => v >= min && v <= max, + hir::BinOpKind::Lt => v > min && v <= max, + hir::BinOpKind::Le => v >= min && v < max, + hir::BinOpKind::Gt => v >= min && v < max, + hir::BinOpKind::Ge => v > min && v <= max, + hir::BinOpKind::Eq | hir::BinOpKind::Ne => v >= min && v <= max, _ => bug!(), } } @@ -206,10 +206,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { fn rev_binop(binop: hir::BinOp) -> hir::BinOp { codemap::respan(binop.span, match binop.node { - hir::BiLt => hir::BiGt, - hir::BiLe => hir::BiGe, - hir::BiGt => hir::BiLt, - hir::BiGe => hir::BiLe, + hir::BinOpKind::Lt => hir::BinOpKind::Gt, + hir::BinOpKind::Le => hir::BinOpKind::Ge, + hir::BinOpKind::Gt => hir::BinOpKind::Lt, + hir::BinOpKind::Ge => hir::BinOpKind::Le, _ => return binop, }) } @@ -285,7 +285,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { fn is_comparison(binop: hir::BinOp) -> bool { match binop.node { - hir::BiEq | hir::BiLt | hir::BiLe | hir::BiNe | hir::BiGe | hir::BiGt => true, + hir::BinOpKind::Eq | hir::BinOpKind::Lt | hir::BinOpKind::Le | hir::BinOpKind::Ne | hir::BinOpKind::Ge | hir::BinOpKind::Gt => true, _ => false, } } diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 81b4ae3f6e8db..1ae6289e9399b 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -102,16 +102,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { // attribute which does exist on the comparison trait methods hir::ExprBinary(bin_op, ..) => { match bin_op.node { - hir::BiEq | hir::BiLt | hir::BiLe | hir::BiNe | hir::BiGe | hir::BiGt => { + hir::BinOpKind::Eq | hir::BinOpKind::Lt | hir::BinOpKind::Le | hir::BinOpKind::Ne | hir::BinOpKind::Ge | hir::BinOpKind::Gt => { Some("comparison") }, - hir::BiAdd | hir::BiSub | hir::BiDiv | hir::BiMul | hir::BiRem => { + hir::BinOpKind::Add | hir::BinOpKind::Sub | hir::BinOpKind::Div | hir::BinOpKind::Mul | hir::BinOpKind::Rem => { Some("arithmetic operation") }, - hir::BiAnd | hir::BiOr => { + hir::BinOpKind::And | hir::BinOpKind::Or => { Some("logical operation") }, - hir::BiBitXor | hir::BiBitAnd | hir::BiBitOr | hir::BiShl | hir::BiShr => { + hir::BinOpKind::BitXor | hir::BinOpKind::BitAnd | hir::BinOpKind::BitOr | hir::BinOpKind::Shl | hir::BinOpKind::Shr => { Some("bitwise operation") }, } diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 8c73771e57b22..edbb6cb161315 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -325,14 +325,14 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, match (op.node, cx.constness) { // FIXME(eddyb) use logical ops in constants when // they can handle that kind of control-flow. - (hir::BinOp_::BiAnd, hir::Constness::Const) => { + (hir::BinOpKind::And, hir::Constness::Const) => { ExprKind::Binary { op: BinOp::BitAnd, lhs: lhs.to_ref(), rhs: rhs.to_ref(), } } - (hir::BinOp_::BiOr, hir::Constness::Const) => { + (hir::BinOpKind::Or, hir::Constness::Const) => { ExprKind::Binary { op: BinOp::BitOr, lhs: lhs.to_ref(), @@ -340,14 +340,14 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, } } - (hir::BinOp_::BiAnd, hir::Constness::NotConst) => { + (hir::BinOpKind::And, hir::Constness::NotConst) => { ExprKind::LogicalOp { op: LogicalOp::And, lhs: lhs.to_ref(), rhs: rhs.to_ref(), } } - (hir::BinOp_::BiOr, hir::Constness::NotConst) => { + (hir::BinOpKind::Or, hir::Constness::NotConst) => { ExprKind::LogicalOp { op: LogicalOp::Or, lhs: lhs.to_ref(), @@ -930,24 +930,24 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, } -fn bin_op(op: hir::BinOp_) -> BinOp { +fn bin_op(op: hir::BinOpKind) -> BinOp { match op { - hir::BinOp_::BiAdd => BinOp::Add, - hir::BinOp_::BiSub => BinOp::Sub, - hir::BinOp_::BiMul => BinOp::Mul, - hir::BinOp_::BiDiv => BinOp::Div, - hir::BinOp_::BiRem => BinOp::Rem, - hir::BinOp_::BiBitXor => BinOp::BitXor, - hir::BinOp_::BiBitAnd => BinOp::BitAnd, - hir::BinOp_::BiBitOr => BinOp::BitOr, - hir::BinOp_::BiShl => BinOp::Shl, - hir::BinOp_::BiShr => BinOp::Shr, - hir::BinOp_::BiEq => BinOp::Eq, - hir::BinOp_::BiLt => BinOp::Lt, - hir::BinOp_::BiLe => BinOp::Le, - hir::BinOp_::BiNe => BinOp::Ne, - hir::BinOp_::BiGe => BinOp::Ge, - hir::BinOp_::BiGt => BinOp::Gt, + hir::BinOpKind::Add => BinOp::Add, + hir::BinOpKind::Sub => BinOp::Sub, + hir::BinOpKind::Mul => BinOp::Mul, + hir::BinOpKind::Div => BinOp::Div, + hir::BinOpKind::Rem => BinOp::Rem, + hir::BinOpKind::BitXor => BinOp::BitXor, + hir::BinOpKind::BitAnd => BinOp::BitAnd, + hir::BinOpKind::BitOr => BinOp::BitOr, + hir::BinOpKind::Shl => BinOp::Shl, + hir::BinOpKind::Shr => BinOp::Shr, + hir::BinOpKind::Eq => BinOp::Eq, + hir::BinOpKind::Lt => BinOp::Lt, + hir::BinOpKind::Le => BinOp::Le, + hir::BinOpKind::Ne => BinOp::Ne, + hir::BinOpKind::Ge => BinOp::Ge, + hir::BinOpKind::Gt => BinOp::Gt, _ => bug!("no equivalent for ast binop {:?}", op), } } diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 6fbe4e0f240bb..66633a0de7091 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -356,9 +356,9 @@ fn check_expr_kind<'a, 'tcx>( } match v.tables.node_id_to_type(lhs.hir_id).sty { ty::TyRawPtr(_) => { - assert!(op.node == hir::BiEq || op.node == hir::BiNe || - op.node == hir::BiLe || op.node == hir::BiLt || - op.node == hir::BiGe || op.node == hir::BiGt); + assert!(op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne || + op.node == hir::BinOpKind::Le || op.node == hir::BinOpKind::Lt || + op.node == hir::BinOpKind::Ge || op.node == hir::BinOpKind::Gt); NotPromotable } diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 0a33252d4cd01..ba90f201b63dd 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -285,20 +285,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } let missing_trait = match op.node { - hir::BiAdd => Some("std::ops::AddAssign"), - hir::BiSub => Some("std::ops::SubAssign"), - hir::BiMul => Some("std::ops::MulAssign"), - hir::BiDiv => Some("std::ops::DivAssign"), - hir::BiRem => Some("std::ops::RemAssign"), - hir::BiBitAnd => Some("std::ops::BitAndAssign"), - hir::BiBitXor => Some("std::ops::BitXorAssign"), - hir::BiBitOr => Some("std::ops::BitOrAssign"), - hir::BiShl => Some("std::ops::ShlAssign"), - hir::BiShr => Some("std::ops::ShrAssign"), + hir::BinOpKind::Add => Some("std::ops::AddAssign"), + hir::BinOpKind::Sub => Some("std::ops::SubAssign"), + hir::BinOpKind::Mul => Some("std::ops::MulAssign"), + hir::BinOpKind::Div => Some("std::ops::DivAssign"), + hir::BinOpKind::Rem => Some("std::ops::RemAssign"), + hir::BinOpKind::BitAnd => Some("std::ops::BitAndAssign"), + hir::BinOpKind::BitXor => Some("std::ops::BitXorAssign"), + hir::BinOpKind::BitOr => Some("std::ops::BitOrAssign"), + hir::BinOpKind::Shl => Some("std::ops::ShlAssign"), + hir::BinOpKind::Shr => Some("std::ops::ShrAssign"), _ => None }; if let Some(missing_trait) = missing_trait { - if op.node == hir::BiAdd && + if op.node == hir::BinOpKind::Add && self.check_str_addition(expr, lhs_expr, rhs_expr, lhs_ty, rhs_ty, &mut err) { // This has nothing here because it means we did string @@ -353,23 +353,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } let missing_trait = match op.node { - hir::BiAdd => Some("std::ops::Add"), - hir::BiSub => Some("std::ops::Sub"), - hir::BiMul => Some("std::ops::Mul"), - hir::BiDiv => Some("std::ops::Div"), - hir::BiRem => Some("std::ops::Rem"), - hir::BiBitAnd => Some("std::ops::BitAnd"), - hir::BiBitXor => Some("std::ops::BitXor"), - hir::BiBitOr => Some("std::ops::BitOr"), - hir::BiShl => Some("std::ops::Shl"), - hir::BiShr => Some("std::ops::Shr"), - hir::BiEq | hir::BiNe => Some("std::cmp::PartialEq"), - hir::BiLt | hir::BiLe | hir::BiGt | hir::BiGe => + hir::BinOpKind::Add => Some("std::ops::Add"), + hir::BinOpKind::Sub => Some("std::ops::Sub"), + hir::BinOpKind::Mul => Some("std::ops::Mul"), + hir::BinOpKind::Div => Some("std::ops::Div"), + hir::BinOpKind::Rem => Some("std::ops::Rem"), + hir::BinOpKind::BitAnd => Some("std::ops::BitAnd"), + hir::BinOpKind::BitXor => Some("std::ops::BitXor"), + hir::BinOpKind::BitOr => Some("std::ops::BitOr"), + hir::BinOpKind::Shl => Some("std::ops::Shl"), + hir::BinOpKind::Shr => Some("std::ops::Shr"), + hir::BinOpKind::Eq | hir::BinOpKind::Ne => Some("std::cmp::PartialEq"), + hir::BinOpKind::Lt | hir::BinOpKind::Le | hir::BinOpKind::Gt | hir::BinOpKind::Ge => Some("std::cmp::PartialOrd"), _ => None }; if let Some(missing_trait) = missing_trait { - if op.node == hir::BiAdd && + if op.node == hir::BinOpKind::Add && self.check_str_addition(expr, lhs_expr, rhs_expr, lhs_ty, rhs_ty, &mut err) { // This has nothing here because it means we did string @@ -508,20 +508,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }; let (opname, trait_did) = if let Op::Binary(op, IsAssign::Yes) = op { match op.node { - hir::BiAdd => ("add_assign", lang.add_assign_trait()), - hir::BiSub => ("sub_assign", lang.sub_assign_trait()), - hir::BiMul => ("mul_assign", lang.mul_assign_trait()), - hir::BiDiv => ("div_assign", lang.div_assign_trait()), - hir::BiRem => ("rem_assign", lang.rem_assign_trait()), - hir::BiBitXor => ("bitxor_assign", lang.bitxor_assign_trait()), - hir::BiBitAnd => ("bitand_assign", lang.bitand_assign_trait()), - hir::BiBitOr => ("bitor_assign", lang.bitor_assign_trait()), - hir::BiShl => ("shl_assign", lang.shl_assign_trait()), - hir::BiShr => ("shr_assign", lang.shr_assign_trait()), - hir::BiLt | hir::BiLe | - hir::BiGe | hir::BiGt | - hir::BiEq | hir::BiNe | - hir::BiAnd | hir::BiOr => { + hir::BinOpKind::Add => ("add_assign", lang.add_assign_trait()), + hir::BinOpKind::Sub => ("sub_assign", lang.sub_assign_trait()), + hir::BinOpKind::Mul => ("mul_assign", lang.mul_assign_trait()), + hir::BinOpKind::Div => ("div_assign", lang.div_assign_trait()), + hir::BinOpKind::Rem => ("rem_assign", lang.rem_assign_trait()), + hir::BinOpKind::BitXor => ("bitxor_assign", lang.bitxor_assign_trait()), + hir::BinOpKind::BitAnd => ("bitand_assign", lang.bitand_assign_trait()), + hir::BinOpKind::BitOr => ("bitor_assign", lang.bitor_assign_trait()), + hir::BinOpKind::Shl => ("shl_assign", lang.shl_assign_trait()), + hir::BinOpKind::Shr => ("shr_assign", lang.shr_assign_trait()), + hir::BinOpKind::Lt | hir::BinOpKind::Le | + hir::BinOpKind::Ge | hir::BinOpKind::Gt | + hir::BinOpKind::Eq | hir::BinOpKind::Ne | + hir::BinOpKind::And | hir::BinOpKind::Or => { span_bug!(span, "impossible assignment operation: {}=", op.node.as_str()) @@ -529,23 +529,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } else if let Op::Binary(op, IsAssign::No) = op { match op.node { - hir::BiAdd => ("add", lang.add_trait()), - hir::BiSub => ("sub", lang.sub_trait()), - hir::BiMul => ("mul", lang.mul_trait()), - hir::BiDiv => ("div", lang.div_trait()), - hir::BiRem => ("rem", lang.rem_trait()), - hir::BiBitXor => ("bitxor", lang.bitxor_trait()), - hir::BiBitAnd => ("bitand", lang.bitand_trait()), - hir::BiBitOr => ("bitor", lang.bitor_trait()), - hir::BiShl => ("shl", lang.shl_trait()), - hir::BiShr => ("shr", lang.shr_trait()), - hir::BiLt => ("lt", lang.partial_ord_trait()), - hir::BiLe => ("le", lang.partial_ord_trait()), - hir::BiGe => ("ge", lang.partial_ord_trait()), - hir::BiGt => ("gt", lang.partial_ord_trait()), - hir::BiEq => ("eq", lang.eq_trait()), - hir::BiNe => ("ne", lang.eq_trait()), - hir::BiAnd | hir::BiOr => { + hir::BinOpKind::Add => ("add", lang.add_trait()), + hir::BinOpKind::Sub => ("sub", lang.sub_trait()), + hir::BinOpKind::Mul => ("mul", lang.mul_trait()), + hir::BinOpKind::Div => ("div", lang.div_trait()), + hir::BinOpKind::Rem => ("rem", lang.rem_trait()), + hir::BinOpKind::BitXor => ("bitxor", lang.bitxor_trait()), + hir::BinOpKind::BitAnd => ("bitand", lang.bitand_trait()), + hir::BinOpKind::BitOr => ("bitor", lang.bitor_trait()), + hir::BinOpKind::Shl => ("shl", lang.shl_trait()), + hir::BinOpKind::Shr => ("shr", lang.shr_trait()), + hir::BinOpKind::Lt => ("lt", lang.partial_ord_trait()), + hir::BinOpKind::Le => ("le", lang.partial_ord_trait()), + hir::BinOpKind::Ge => ("ge", lang.partial_ord_trait()), + hir::BinOpKind::Gt => ("gt", lang.partial_ord_trait()), + hir::BinOpKind::Eq => ("eq", lang.eq_trait()), + hir::BinOpKind::Ne => ("ne", lang.eq_trait()), + hir::BinOpKind::And | hir::BinOpKind::Or => { span_bug!(span, "&& and || are not overloadable") } } @@ -608,31 +608,31 @@ enum BinOpCategory { impl BinOpCategory { fn from(op: hir::BinOp) -> BinOpCategory { match op.node { - hir::BiShl | hir::BiShr => + hir::BinOpKind::Shl | hir::BinOpKind::Shr => BinOpCategory::Shift, - hir::BiAdd | - hir::BiSub | - hir::BiMul | - hir::BiDiv | - hir::BiRem => + hir::BinOpKind::Add | + hir::BinOpKind::Sub | + hir::BinOpKind::Mul | + hir::BinOpKind::Div | + hir::BinOpKind::Rem => BinOpCategory::Math, - hir::BiBitXor | - hir::BiBitAnd | - hir::BiBitOr => + hir::BinOpKind::BitXor | + hir::BinOpKind::BitAnd | + hir::BinOpKind::BitOr => BinOpCategory::Bitwise, - hir::BiEq | - hir::BiNe | - hir::BiLt | - hir::BiLe | - hir::BiGe | - hir::BiGt => + hir::BinOpKind::Eq | + hir::BinOpKind::Ne | + hir::BinOpKind::Lt | + hir::BinOpKind::Le | + hir::BinOpKind::Ge | + hir::BinOpKind::Gt => BinOpCategory::Comparison, - hir::BiAnd | - hir::BiOr => + hir::BinOpKind::And | + hir::BinOpKind::Or => BinOpCategory::Shortcircuit, } } From 114314c92037d0e3e1320e9c7e4147f5b3bc2c63 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Wed, 11 Jul 2018 18:54:37 +0800 Subject: [PATCH 02/11] StmtKind --- src/librustc/cfg/construct.rs | 6 +++--- src/librustc/hir/check_attr.rs | 2 +- src/librustc/hir/intravisit.rs | 6 +++--- src/librustc/hir/lowering.rs | 16 +++++++-------- src/librustc/hir/mod.rs | 27 ++++++++++++------------- src/librustc/hir/print.rs | 14 ++++++------- src/librustc/ich/impls_hir.rs | 10 ++++----- src/librustc/middle/expr_use_visitor.rs | 6 +++--- src/librustc/middle/liveness.rs | 4 ++-- src/librustc/middle/region.rs | 4 ++-- src/librustc_lint/unused.rs | 6 +++--- src/librustc_mir/hair/cx/block.rs | 6 +++--- src/librustc_passes/rvalue_promotion.rs | 6 +++--- src/librustc_typeck/check/mod.rs | 12 +++++------ 14 files changed, 62 insertions(+), 63 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index aab70456dc18d..bbea4ad6a4c9b 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -111,13 +111,13 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { fn stmt(&mut self, stmt: &hir::Stmt, pred: CFGIndex) -> CFGIndex { let hir_id = self.tcx.hir.node_to_hir_id(stmt.node.id()); match stmt.node { - hir::StmtDecl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, _) => { let exit = self.decl(&decl, pred); self.add_ast_node(hir_id.local_id, &[exit]) } - hir::StmtExpr(ref expr, _) | - hir::StmtSemi(ref expr, _) => { + hir::StmtKind::Expr(ref expr, _) | + hir::StmtKind::Semi(ref expr, _) => { let exit = self.expr(&expr, pred); self.add_ast_node(hir_id.local_id, &[exit]) } diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 2d83c158fe08f..a4e9279b23f7d 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -264,7 +264,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> { fn check_stmt_attributes(&self, stmt: &hir::Stmt) { // When checking statements ignore expressions, they will be checked later - if let hir::Stmt_::StmtDecl(_, _) = stmt.node { + if let hir::StmtKind::Decl(_, _) = stmt.node { for attr in stmt.node.attrs() { if attr.check_name("inline") { self.check_inline(attr, &stmt.span, Target::Statement); diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index e2c0020db2ff3..de0f3a405d891 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -935,12 +935,12 @@ pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) { pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { match statement.node { - StmtDecl(ref declaration, id) => { + StmtKind::Decl(ref declaration, id) => { visitor.visit_id(id); visitor.visit_decl(declaration) } - StmtExpr(ref expression, id) | - StmtSemi(ref expression, id) => { + StmtKind::Expr(ref expression, id) | + StmtKind::Semi(ref expression, id) => { visitor.visit_id(id); visitor.visit_expr(expression) } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 86f6e08215e52..07d1281ada69e 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -3995,7 +3995,7 @@ impl<'a> LoweringContext<'a> { // ::std::option::Option::None => break // }; // let = __next; - // StmtExpr(); + // StmtKind::Expr(); // } // } // }; @@ -4057,7 +4057,7 @@ impl<'a> LoweringContext<'a> { ThinVec::new(), )) }; - let match_stmt = respan(head_sp, hir::StmtExpr(match_expr, self.next_id().node_id)); + let match_stmt = respan(head_sp, hir::StmtKind::Expr(match_expr, self.next_id().node_id)); let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat.id)); @@ -4076,7 +4076,7 @@ impl<'a> LoweringContext<'a> { let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false)); let body_expr = P(self.expr_block(body_block, ThinVec::new())); - let body_stmt = respan(body.span, hir::StmtExpr(body_expr, self.next_id().node_id)); + let body_stmt = respan(body.span, hir::StmtKind::Expr(body_expr, self.next_id().node_id)); let loop_block = P(self.block_all( e.span, @@ -4246,7 +4246,7 @@ impl<'a> LoweringContext<'a> { fn lower_stmt(&mut self, s: &Stmt) -> SmallVector { SmallVector::one(match s.node { StmtKind::Local(ref l) => Spanned { - node: hir::StmtDecl( + node: hir::StmtKind::Decl( P(Spanned { node: hir::DeclLocal(self.lower_local(l)), span: s.span, @@ -4261,7 +4261,7 @@ impl<'a> LoweringContext<'a> { return self.lower_item_id(it) .into_iter() .map(|item_id| Spanned { - node: hir::StmtDecl( + node: hir::StmtKind::Decl( P(Spanned { node: hir::DeclItem(item_id), span: s.span, @@ -4275,11 +4275,11 @@ impl<'a> LoweringContext<'a> { .collect(); } StmtKind::Expr(ref e) => Spanned { - node: hir::StmtExpr(P(self.lower_expr(e)), self.lower_node_id(s.id).node_id), + node: hir::StmtKind::Expr(P(self.lower_expr(e)), self.lower_node_id(s.id).node_id), span: s.span, }, StmtKind::Semi(ref e) => Spanned { - node: hir::StmtSemi(P(self.lower_expr(e)), self.lower_node_id(s.id).node_id), + node: hir::StmtKind::Semi(P(self.lower_expr(e)), self.lower_node_id(s.id).node_id), span: s.span, }, StmtKind::Mac(..) => panic!("Shouldn't exist here"), @@ -4494,7 +4494,7 @@ impl<'a> LoweringContext<'a> { source, }); let decl = respan(sp, hir::DeclLocal(local)); - respan(sp, hir::StmtDecl(P(decl), self.next_id().node_id)) + respan(sp, hir::StmtKind::Decl(P(decl), self.next_id().node_id)) } fn stmt_let( diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 594fae972b173..bb1536d963028 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -19,7 +19,6 @@ pub use self::ForeignItem_::*; pub use self::Item_::*; pub use self::Mutability::*; pub use self::PrimTy::*; -pub use self::Stmt_::*; pub use self::Ty_::*; pub use self::UnOp::*; pub use self::UnsafeSource::*; @@ -1102,9 +1101,9 @@ impl UnOp { } /// A statement -pub type Stmt = Spanned; +pub type Stmt = Spanned; -impl fmt::Debug for Stmt_ { +impl fmt::Debug for StmtKind { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // Sadness. let spanned = codemap::dummy_spanned(self.clone()); @@ -1116,31 +1115,31 @@ impl fmt::Debug for Stmt_ { } #[derive(Clone, RustcEncodable, RustcDecodable)] -pub enum Stmt_ { +pub enum StmtKind { /// Could be an item or a local (let) binding: - StmtDecl(P, NodeId), + Decl(P, NodeId), /// Expr without trailing semi-colon (must have unit type): - StmtExpr(P, NodeId), + Expr(P, NodeId), /// Expr with trailing semi-colon (may have any type): - StmtSemi(P, NodeId), + Semi(P, NodeId), } -impl Stmt_ { +impl StmtKind { pub fn attrs(&self) -> &[Attribute] { match *self { - StmtDecl(ref d, _) => d.node.attrs(), - StmtExpr(ref e, _) | - StmtSemi(ref e, _) => &e.attrs, + StmtKind::Decl(ref d, _) => d.node.attrs(), + StmtKind::Expr(ref e, _) | + StmtKind::Semi(ref e, _) => &e.attrs, } } pub fn id(&self) -> NodeId { match *self { - StmtDecl(_, id) => id, - StmtExpr(_, id) => id, - StmtSemi(_, id) => id, + StmtKind::Decl(_, id) => id, + StmtKind::Expr(_, id) => id, + StmtKind::Semi(_, id) => id, } } } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 3004c0d0224c0..5a3a36c645850 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1001,14 +1001,14 @@ impl<'a> State<'a> { pub fn print_stmt(&mut self, st: &hir::Stmt) -> io::Result<()> { self.maybe_print_comment(st.span.lo())?; match st.node { - hir::StmtDecl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, _) => { self.print_decl(&decl)?; } - hir::StmtExpr(ref expr, _) => { + hir::StmtKind::Expr(ref expr, _) => { self.space_if_not_bol()?; self.print_expr(&expr)?; } - hir::StmtSemi(ref expr, _) => { + hir::StmtKind::Semi(ref expr, _) => { self.space_if_not_bol()?; self.print_expr(&expr)?; self.s.word(";")?; @@ -2396,18 +2396,18 @@ fn expr_requires_semi_to_be_stmt(e: &hir::Expr) -> bool { /// this statement requires a semicolon after it. /// note that in one case (stmt_semi), we've already /// seen the semicolon, and thus don't need another. -fn stmt_ends_with_semi(stmt: &hir::Stmt_) -> bool { +fn stmt_ends_with_semi(stmt: &hir::StmtKind) -> bool { match *stmt { - hir::StmtDecl(ref d, _) => { + hir::StmtKind::Decl(ref d, _) => { match d.node { hir::DeclLocal(_) => true, hir::DeclItem(_) => false, } } - hir::StmtExpr(ref e, _) => { + hir::StmtKind::Expr(ref e, _) => { expr_requires_semi_to_be_stmt(&e) } - hir::StmtSemi(..) => { + hir::StmtKind::Semi(..) => { false } } diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 71a8d3ccdaf65..8df6539ecfeb6 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -466,7 +466,7 @@ impl_stable_hash_for!(enum hir::UnOp { UnNeg }); -impl_stable_hash_for_spanned!(hir::Stmt_); +impl_stable_hash_for_spanned!(hir::StmtKind); impl_stable_hash_for!(struct hir::Local { pat, @@ -915,10 +915,10 @@ impl_stable_hash_for!(enum hir::ForeignItem_ { ForeignItemType }); -impl_stable_hash_for!(enum hir::Stmt_ { - StmtDecl(decl, id), - StmtExpr(expr, id), - StmtSemi(expr, id) +impl_stable_hash_for!(enum hir::StmtKind { + Decl(decl, id), + Expr(expr, id), + Semi(expr, id) }); impl_stable_hash_for!(struct hir::Arg { diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index a83aa47fd4f13..af7dc3afdbb5e 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -586,7 +586,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { fn walk_stmt(&mut self, stmt: &hir::Stmt) { match stmt.node { - hir::StmtDecl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, _) => { match decl.node { hir::DeclLocal(ref local) => { self.walk_local(&local); @@ -599,8 +599,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } } - hir::StmtExpr(ref expr, _) | - hir::StmtSemi(ref expr, _) => { + hir::StmtKind::Expr(ref expr, _) | + hir::StmtKind::Semi(ref expr, _) => { self.consume_expr(&expr); } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 07a9dd75d4ca4..cad74a0fb9e95 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -860,11 +860,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn propagate_through_stmt(&mut self, stmt: &hir::Stmt, succ: LiveNode) -> LiveNode { match stmt.node { - hir::StmtDecl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, _) => { self.propagate_through_decl(&decl, succ) } - hir::StmtExpr(ref expr, _) | hir::StmtSemi(ref expr, _) => { + hir::StmtKind::Expr(ref expr, _) | hir::StmtKind::Semi(ref expr, _) => { self.propagate_through_expr(&expr, succ) } } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index a196820fcf17d..f822c4c08f279 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -858,8 +858,8 @@ fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk: // index information.) for (i, statement) in blk.stmts.iter().enumerate() { - if let hir::StmtDecl(..) = statement.node { - // Each StmtDecl introduces a subscope for bindings + if let hir::StmtKind::Decl(..) = statement.node { + // Each StmtKind::Decl introduces a subscope for bindings // introduced by the declaration; this subscope covers // a suffix of the block . Each subscope in a block // has the previous subscope in the block as a parent, diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 1ae6289e9399b..c71799a172c96 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -49,7 +49,7 @@ impl LintPass for UnusedResults { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { let expr = match s.node { - hir::StmtSemi(ref expr, _) => &**expr, + hir::StmtKind::Semi(ref expr, _) => &**expr, _ => return, }; @@ -166,8 +166,8 @@ impl LintPass for PathStatements { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathStatements { fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { - if let hir::StmtSemi(ref expr, _) = s.node { - if let hir::ExprPath(_) = expr.node { + if let hir::StmtKind::Semi(ref expr, _) = s.node { + if let hir::ExprKind::Path(_) = expr.node { cx.span_lint(PATH_STATEMENTS, s.span, "path statement with no effect"); } } diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 5ef1eef133d9d..48558ba6db24d 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -55,8 +55,8 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, let hir_id = cx.tcx.hir.node_to_hir_id(stmt.node.id()); let opt_dxn_ext = cx.region_scope_tree.opt_destruction_scope(hir_id.local_id); match stmt.node { - hir::StmtExpr(ref expr, _) | - hir::StmtSemi(ref expr, _) => { + hir::StmtKind::Expr(ref expr, _) | + hir::StmtKind::Semi(ref expr, _) => { result.push(StmtRef::Mirror(Box::new(Stmt { kind: StmtKind::Expr { scope: region::Scope::Node(hir_id.local_id), @@ -65,7 +65,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, opt_destruction_scope: opt_dxn_ext, }))) } - hir::StmtDecl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, _) => { match decl.node { hir::DeclItem(..) => { // ignore for purposes of the MIR diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 66633a0de7091..138731edfff78 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -261,7 +261,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { fn check_stmt(&mut self, stmt: &'tcx hir::Stmt) -> Promotability { match stmt.node { - hir::StmtDecl(ref decl, _node_id) => { + hir::StmtKind::Decl(ref decl, _node_id) => { match &decl.node { hir::DeclLocal(local) => { if self.remove_mut_rvalue_borrow(&local.pat) { @@ -280,8 +280,8 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { hir::DeclItem(_) => Promotable } } - hir::StmtExpr(ref box_expr, _node_id) | - hir::StmtSemi(ref box_expr, _node_id) => { + hir::StmtKind::Expr(ref box_expr, _node_id) | + hir::StmtKind::Semi(ref box_expr, _node_id) => { let _ = self.check_expr(box_expr); NotPromotable } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c7ad3398873ea..0d93c52a24898 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4377,7 +4377,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn check_stmt(&self, stmt: &'gcx hir::Stmt) { // Don't do all the complex logic below for DeclItem. match stmt.node { - hir::StmtDecl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, _) => { match decl.node { hir::DeclLocal(_) => {} hir::DeclItem(_) => { @@ -4385,7 +4385,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } } - hir::StmtExpr(..) | hir::StmtSemi(..) => {} + hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => {} } self.warn_if_unreachable(stmt.node.id(), stmt.span, "statement"); @@ -4397,7 +4397,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.has_errors.set(false); match stmt.node { - hir::StmtDecl(ref decl, _) => { + hir::StmtKind::Decl(ref decl, _) => { match decl.node { hir::DeclLocal(ref l) => { self.check_decl_local(&l); @@ -4405,11 +4405,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { hir::DeclItem(_) => {/* ignore for now */} } } - hir::StmtExpr(ref expr, _) => { + hir::StmtKind::Expr(ref expr, _) => { // Check with expected type of () self.check_expr_has_type_or_error(&expr, self.tcx.mk_nil()); } - hir::StmtSemi(ref expr, _) => { + hir::StmtKind::Semi(ref expr, _) => { self.check_expr(&expr); } } @@ -4733,7 +4733,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { None => return, }; let last_expr = match last_stmt.node { - hir::StmtSemi(ref e, _) => e, + hir::StmtKind::Semi(ref e, _) => e, _ => return, }; let last_expr_ty = self.node_ty(last_expr.hir_id); From 14893ba96b64f6077dae37ded929956046618714 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Wed, 11 Jul 2018 18:59:17 +0800 Subject: [PATCH 03/11] DeclKind --- src/librustc/cfg/construct.rs | 4 ++-- src/librustc/hir/intravisit.rs | 4 ++-- src/librustc/hir/lowering.rs | 6 +++--- src/librustc/hir/mod.rs | 19 +++++++++---------- src/librustc/hir/print.rs | 8 ++++---- src/librustc/ich/impls_hir.rs | 8 ++++---- src/librustc/middle/expr_use_visitor.rs | 4 ++-- src/librustc/middle/liveness.rs | 4 ++-- src/librustc_mir/hair/cx/block.rs | 4 ++-- src/librustc_passes/rvalue_promotion.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 8 ++++---- 11 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index bbea4ad6a4c9b..e4b9ec89bc563 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -126,12 +126,12 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { fn decl(&mut self, decl: &hir::Decl, pred: CFGIndex) -> CFGIndex { match decl.node { - hir::DeclLocal(ref local) => { + hir::DeclKind::Local(ref local) => { let init_exit = self.opt_expr(&local.init, pred); self.pat(&local.pat, init_exit) } - hir::DeclItem(_) => pred, + hir::DeclKind::Item(_) => pred, } } diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index de0f3a405d891..01c318ca17c3b 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -949,8 +949,8 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) { match declaration.node { - DeclLocal(ref local) => visitor.visit_local(local), - DeclItem(item) => visitor.visit_nested_item(item), + DeclKind::Local(ref local) => visitor.visit_local(local), + DeclKind::Item(item) => visitor.visit_nested_item(item), } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 07d1281ada69e..4bdf6e1e96b5a 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -4248,7 +4248,7 @@ impl<'a> LoweringContext<'a> { StmtKind::Local(ref l) => Spanned { node: hir::StmtKind::Decl( P(Spanned { - node: hir::DeclLocal(self.lower_local(l)), + node: hir::DeclKind::Local(self.lower_local(l)), span: s.span, }), self.lower_node_id(s.id).node_id, @@ -4263,7 +4263,7 @@ impl<'a> LoweringContext<'a> { .map(|item_id| Spanned { node: hir::StmtKind::Decl( P(Spanned { - node: hir::DeclItem(item_id), + node: hir::DeclKind::Item(item_id), span: s.span, }), id.take() @@ -4493,7 +4493,7 @@ impl<'a> LoweringContext<'a> { attrs: ThinVec::new(), source, }); - let decl = respan(sp, hir::DeclLocal(local)); + let decl = respan(sp, hir::DeclKind::Local(local)); respan(sp, hir::StmtKind::Decl(P(decl), self.next_id().node_id)) } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index bb1536d963028..6e413416100a8 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -12,8 +12,7 @@ pub use self::BlockCheckMode::*; pub use self::CaptureClause::*; -pub use self::Decl_::*; -pub use self::Expr_::*; +pub use self::ExprKind::*; pub use self::FunctionRetTy::*; pub use self::ForeignItem_::*; pub use self::Item_::*; @@ -1158,27 +1157,27 @@ pub struct Local { pub source: LocalSource, } -pub type Decl = Spanned; +pub type Decl = Spanned; #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum Decl_ { +pub enum DeclKind { /// A local (let) binding: - DeclLocal(P), + Local(P), /// An item binding: - DeclItem(ItemId), + Item(ItemId), } -impl Decl_ { +impl DeclKind { pub fn attrs(&self) -> &[Attribute] { match *self { - DeclLocal(ref l) => &l.attrs, - DeclItem(_) => &[] + DeclKind::Local(ref l) => &l.attrs, + DeclKind::Item(_) => &[] } } pub fn is_local(&self) -> bool { match *self { - Decl_::DeclLocal(_) => true, + DeclKind::Local(_) => true, _ => false, } } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 5a3a36c645850..7fe0647884491 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1575,7 +1575,7 @@ impl<'a> State<'a> { pub fn print_decl(&mut self, decl: &hir::Decl) -> io::Result<()> { self.maybe_print_comment(decl.span.lo())?; match decl.node { - hir::DeclLocal(ref loc) => { + hir::DeclKind::Local(ref loc) => { self.space_if_not_bol()?; self.ibox(indent_unit)?; self.word_nbsp("let")?; @@ -1590,7 +1590,7 @@ impl<'a> State<'a> { } self.end() } - hir::DeclItem(item) => { + hir::DeclKind::Item(item) => { self.ann.nested(self, Nested::Item(item)) } } @@ -2400,8 +2400,8 @@ fn stmt_ends_with_semi(stmt: &hir::StmtKind) -> bool { match *stmt { hir::StmtKind::Decl(ref d, _) => { match d.node { - hir::DeclLocal(_) => true, - hir::DeclItem(_) => false, + hir::DeclKind::Local(_) => true, + hir::DeclKind::Item(_) => false, } } hir::StmtKind::Expr(ref e, _) => { diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 8df6539ecfeb6..c242efeb8b0b5 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -479,10 +479,10 @@ impl_stable_hash_for!(struct hir::Local { source }); -impl_stable_hash_for_spanned!(hir::Decl_); -impl_stable_hash_for!(enum hir::Decl_ { - DeclLocal(local), - DeclItem(item_id) +impl_stable_hash_for_spanned!(hir::DeclKind); +impl_stable_hash_for!(enum hir::DeclKind { + Local(local), + Item(item_id) }); impl_stable_hash_for!(struct hir::Arm { diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index af7dc3afdbb5e..8250821051ab5 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -588,11 +588,11 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { match stmt.node { hir::StmtKind::Decl(ref decl, _) => { match decl.node { - hir::DeclLocal(ref local) => { + hir::DeclKind::Local(ref local) => { self.walk_local(&local); } - hir::DeclItem(_) => { + hir::DeclKind::Item(_) => { // we don't visit nested items in this visitor, // only the fn body we were given. } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index cad74a0fb9e95..fd23ae89940c8 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -873,10 +873,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn propagate_through_decl(&mut self, decl: &hir::Decl, succ: LiveNode) -> LiveNode { match decl.node { - hir::DeclLocal(ref local) => { + hir::DeclKind::Local(ref local) => { self.propagate_through_local(&local, succ) } - hir::DeclItem(_) => succ, + hir::DeclKind::Item(_) => succ, } } diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 48558ba6db24d..6c8b5d97b6ff3 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -67,10 +67,10 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, } hir::StmtKind::Decl(ref decl, _) => { match decl.node { - hir::DeclItem(..) => { + hir::DeclKind::Item(..) => { // ignore for purposes of the MIR } - hir::DeclLocal(ref local) => { + hir::DeclKind::Local(ref local) => { let remainder_scope = region::Scope::Remainder(BlockRemainder { block: block_id, first_statement_index: region::FirstStatementIndex::new(index), diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 138731edfff78..33b104072d918 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -263,7 +263,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { match stmt.node { hir::StmtKind::Decl(ref decl, _node_id) => { match &decl.node { - hir::DeclLocal(local) => { + hir::DeclKind::Local(local) => { if self.remove_mut_rvalue_borrow(&local.pat) { if let Some(init) = &local.init { self.mut_rvalue_borrows.insert(init.id); @@ -277,7 +277,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { NotPromotable } // Item statements are allowed - hir::DeclItem(_) => Promotable + hir::DeclKind::Item(_) => Promotable } } hir::StmtKind::Expr(ref box_expr, _node_id) | diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 0d93c52a24898..75d02e32b64eb 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4379,8 +4379,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { match stmt.node { hir::StmtKind::Decl(ref decl, _) => { match decl.node { - hir::DeclLocal(_) => {} - hir::DeclItem(_) => { + hir::DeclKind::Local(_) => {} + hir::DeclKind::Item(_) => { return; } } @@ -4399,10 +4399,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { match stmt.node { hir::StmtKind::Decl(ref decl, _) => { match decl.node { - hir::DeclLocal(ref l) => { + hir::DeclKind::Local(ref l) => { self.check_decl_local(&l); } - hir::DeclItem(_) => {/* ignore for now */} + hir::DeclKind::Item(_) => {/* ignore for now */} } } hir::StmtKind::Expr(ref expr, _) => { From 1d19e0c8097ead99d306a91b0912f3e6f9c9ddd1 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Wed, 11 Jul 2018 19:18:57 +0800 Subject: [PATCH 04/11] VariantKind --- src/librustc/hir/lowering.rs | 2 +- src/librustc/hir/map/mod.rs | 2 +- src/librustc/hir/mod.rs | 4 ++-- src/librustc/ich/impls_hir.rs | 4 ++-- src/librustc/middle/dead.rs | 2 +- src/librustc/traits/error_reporting.rs | 2 +- src/librustc_typeck/collect.rs | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 4bdf6e1e96b5a..c6f2f71460e26 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1507,7 +1507,7 @@ impl<'a> LoweringContext<'a> { fn lower_variant(&mut self, v: &Variant) -> hir::Variant { Spanned { - node: hir::Variant_ { + node: hir::VariantKind { name: v.node.ident.name, attrs: self.lower_attrs(&v.node.attrs), data: self.lower_variant_data(&v.node.data), diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 08a130f049bf7..6298c3882533b 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -1176,7 +1176,7 @@ impl Named for Spanned { fn name(&self) -> Name { self.node.name() } impl Named for Item { fn name(&self) -> Name { self.name } } impl Named for ForeignItem { fn name(&self) -> Name { self.name } } -impl Named for Variant_ { fn name(&self) -> Name { self.name } } +impl Named for VariantKind { fn name(&self) -> Name { self.name } } impl Named for StructField { fn name(&self) -> Name { self.ident.name } } impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } } impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 6e413416100a8..5ae0c3250fff6 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1878,7 +1878,7 @@ pub struct EnumDef { } #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct Variant_ { +pub struct VariantKind { pub name: Name, pub attrs: HirVec, pub data: VariantData, @@ -1886,7 +1886,7 @@ pub struct Variant_ { pub disr_expr: Option, } -pub type Variant = Spanned; +pub type Variant = Spanned; #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] pub enum UseKind { diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index c242efeb8b0b5..5fbe570a15fb5 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -793,14 +793,14 @@ impl_stable_hash_for!(struct hir::EnumDef { variants }); -impl_stable_hash_for!(struct hir::Variant_ { +impl_stable_hash_for!(struct hir::VariantKind { name, attrs, data, disr_expr }); -impl_stable_hash_for_spanned!(hir::Variant_); +impl_stable_hash_for_spanned!(hir::VariantKind); impl_stable_hash_for!(enum hir::UseKind { Single, diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 180469a5d848a..bb6fa72fbe794 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -475,7 +475,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { && !has_allow_dead_code_or_lang_attr(self.tcx, field.id, &field.attrs) } - fn should_warn_about_variant(&mut self, variant: &hir::Variant_) -> bool { + fn should_warn_about_variant(&mut self, variant: &hir::VariantKind) -> bool { !self.symbol_is_live(variant.data.id(), None) && !has_allow_dead_code_or_lang_attr(self.tcx, variant.data.id(), diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index a5caacea98618..194182ab4960f 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -981,7 +981,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } hir::map::NodeVariant(&hir::Variant { span, - node: hir::Variant_ { + node: hir::VariantKind { data: hir::VariantData::Tuple(ref fields, _), .. }, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 5fa98e3ebe695..21102533f8b8f 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1090,7 +1090,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } NodeStructCtor(&ref def) | - NodeVariant(&Spanned { node: hir::Variant_ { data: ref def, .. }, .. }) => { + NodeVariant(&Spanned { node: hir::VariantKind { data: ref def, .. }, .. }) => { match *def { VariantData::Unit(..) | VariantData::Struct(..) => { tcx.type_of(tcx.hir.get_parent_did(node_id)) @@ -1123,7 +1123,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, NodeExpr(&hir::Expr { node: ExprRepeat(_, ref constant), .. }) if constant.id == node_id => tcx.types.usize, - NodeVariant(&Spanned { node: Variant_ { disr_expr: Some(ref e), .. }, .. }) + NodeVariant(&Spanned { node: VariantKind { disr_expr: Some(ref e), .. }, .. }) if e.id == node_id => { tcx.adt_def(tcx.hir.get_parent_did(node_id)) .repr.discr_type().to_ty(tcx) @@ -1175,7 +1175,7 @@ fn fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } NodeStructCtor(&VariantData::Tuple(ref fields, _)) | - NodeVariant(&Spanned { node: hir::Variant_ { + NodeVariant(&Spanned { node: hir::VariantKind { data: VariantData::Tuple(ref fields, _), .. }, .. }) => { let ty = tcx.type_of(tcx.hir.get_parent_did(node_id)); 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 05/11] 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