]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_passes/rvalue_promotion.rs
Remove Ty prefix from Ty{Adt|Array|Slice|RawPtr|Ref|FnDef|FnPtr|Dynamic|Closure|Gener...
[rust.git] / src / librustc_passes / rvalue_promotion.rs
index 6fbe4e0f240bbcef8bb4ac9eb9ac65fb31a74dd2..fca1c7f27ab37a590274385579ca5b7cf94a2efe 100644 (file)
@@ -248,7 +248,8 @@ fn check_nested_body(&mut self, body_id: hir::BodyId) -> Promotability {
         let tcx = self.tcx;
         let param_env = self.param_env;
         let region_scope_tree = self.tcx.region_scope_tree(item_def_id);
-        euv::ExprUseVisitor::new(self, tcx, param_env, &region_scope_tree, self.tables, None)
+        let tables = self.tables;
+        euv::ExprUseVisitor::new(self, tcx, param_env, &region_scope_tree, tables, None)
             .consume_body(body);
 
         let body_promotable = self.check_expr(&body.value);
@@ -261,9 +262,9 @@ fn check_nested_body(&mut self, body_id: hir::BodyId) -> Promotability {
 
     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) => {
+                    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,11 +278,11 @@ fn check_stmt(&mut self, stmt: &'tcx hir::Stmt) -> Promotability {
                         NotPromotable
                     }
                     // Item statements are allowed
-                    hir::DeclItem(_) => Promotable
+                    hir::DeclKind::Item(_) => 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
             }
@@ -327,18 +328,18 @@ fn check_expr_kind<'a, 'tcx>(
     e: &'tcx hir::Expr, node_ty: Ty<'tcx>) -> Promotability {
 
     let ty_result = match node_ty.sty {
-        ty::TyAdt(def, _) if def.has_dtor(v.tcx) => {
+        ty::Adt(def, _) if def.has_dtor(v.tcx) => {
             NotPromotable
         }
         _ => Promotable
     };
 
     let node_result = match e.node {
-        hir::ExprBox(ref expr) => {
+        hir::ExprKind::Box(ref expr) => {
             let _ = v.check_expr(&expr);
             NotPromotable
         }
-        hir::ExprUnary(op, ref expr) => {
+        hir::ExprKind::Unary(op, ref expr) => {
             let expr_promotability = v.check_expr(expr);
             if v.tables.is_method_call(e) {
                 return NotPromotable;
@@ -348,24 +349,24 @@ fn check_expr_kind<'a, 'tcx>(
             }
             expr_promotability
         }
-        hir::ExprBinary(op, ref lhs, ref rhs) => {
+        hir::ExprKind::Binary(op, ref lhs, ref rhs) => {
             let lefty = v.check_expr(lhs);
             let righty = v.check_expr(rhs);
             if v.tables.is_method_call(e) {
                 return NotPromotable;
             }
             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);
+                ty::RawPtr(_) => {
+                    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
                 }
                 _ => lefty & righty
             }
         }
-        hir::ExprCast(ref from, _) => {
+        hir::ExprKind::Cast(ref from, _) => {
             let expr_promotability = v.check_expr(from);
             debug!("Checking const cast(id={})", from.id);
             match v.tables.cast_kinds().get(from.hir_id) {
@@ -379,7 +380,7 @@ fn check_expr_kind<'a, 'tcx>(
                 _ => expr_promotability
             }
         }
-        hir::ExprPath(ref qpath) => {
+        hir::ExprKind::Path(ref qpath) => {
             let def = v.tables.qpath_def(qpath, e.hir_id);
             match def {
                 Def::VariantCtor(..) | Def::StructCtor(..) |
@@ -426,7 +427,7 @@ fn check_expr_kind<'a, 'tcx>(
                 _ => NotPromotable
             }
         }
-        hir::ExprCall(ref callee, ref hirvec) => {
+        hir::ExprKind::Call(ref callee, ref hirvec) => {
             let mut call_result = v.check_expr(callee);
             for index in hirvec.iter() {
                 call_result = call_result & v.check_expr(index);
@@ -434,7 +435,7 @@ fn check_expr_kind<'a, 'tcx>(
             let mut callee = &**callee;
             loop {
                 callee = match callee.node {
-                    hir::ExprBlock(ref block, _) => match block.expr {
+                    hir::ExprKind::Block(ref block, _) => match block.expr {
                         Some(ref tail) => &tail,
                         None => break
                     },
@@ -442,7 +443,7 @@ fn check_expr_kind<'a, 'tcx>(
                 };
             }
             // The callee is an arbitrary expression, it doesn't necessarily have a definition.
-            let def = if let hir::ExprPath(ref qpath) = callee.node {
+            let def = if let hir::ExprKind::Path(ref qpath) = callee.node {
                 v.tables.qpath_def(qpath, callee.hir_id)
             } else {
                 Def::Err
@@ -465,7 +466,7 @@ fn check_expr_kind<'a, 'tcx>(
             };
             def_result & call_result
         }
-        hir::ExprMethodCall(ref _pathsegment, ref _span, ref hirvec) => {
+        hir::ExprKind::MethodCall(ref _pathsegment, ref _span, ref hirvec) => {
             let mut method_call_result = Promotable;
             for index in hirvec.iter() {
                 method_call_result = method_call_result & v.check_expr(index);
@@ -484,7 +485,7 @@ fn check_expr_kind<'a, 'tcx>(
             }
             method_call_result
         }
-        hir::ExprStruct(ref _qpath, ref hirvec, ref option_expr) => {
+        hir::ExprKind::Struct(ref _qpath, ref hirvec, ref option_expr) => {
             let mut struct_result = Promotable;
             for index in hirvec.iter() {
                 struct_result = struct_result & v.check_expr(&index.expr);
@@ -493,7 +494,7 @@ fn check_expr_kind<'a, 'tcx>(
                 Some(ref expr) => { struct_result = struct_result & v.check_expr(&expr); },
                 None => {},
             }
-            if let ty::TyAdt(adt, ..) = v.tables.expr_ty(e).sty {
+            if let ty::Adt(adt, ..) = v.tables.expr_ty(e).sty {
                 // unsafe_cell_type doesn't necessarily exist with no_core
                 if Some(adt.did) == v.tcx.lang_items().unsafe_cell_type() {
                     return NotPromotable;
@@ -502,14 +503,14 @@ fn check_expr_kind<'a, 'tcx>(
             struct_result
         }
 
-        hir::ExprLit(_) => Promotable,
+        hir::ExprKind::Lit(_) => Promotable,
 
-        hir::ExprAddrOf(_, ref expr) |
-        hir::ExprRepeat(ref expr, _) => {
+        hir::ExprKind::AddrOf(_, ref expr) |
+        hir::ExprKind::Repeat(ref expr, _) => {
             v.check_expr(&expr)
         }
 
-        hir::ExprClosure(_capture_clause, ref _box_fn_decl,
+        hir::ExprKind::Closure(_capture_clause, ref _box_fn_decl,
                          body_id, _span, _option_generator_movability) => {
             let nested_body_promotable = v.check_nested_body(body_id);
             // Paths in constant contexts cannot refer to local variables,
@@ -521,7 +522,7 @@ fn check_expr_kind<'a, 'tcx>(
             }
         }
 
-        hir::ExprField(ref expr, _ident) => {
+        hir::ExprKind::Field(ref expr, _ident) => {
             let expr_promotability = v.check_expr(&expr);
             if let Some(def) = v.tables.expr_ty(expr).ty_adt_def() {
                 if def.is_union() {
@@ -531,11 +532,11 @@ fn check_expr_kind<'a, 'tcx>(
             expr_promotability
         }
 
-        hir::ExprBlock(ref box_block, ref _option_label) => {
+        hir::ExprKind::Block(ref box_block, ref _option_label) => {
             v.check_block(box_block)
         }
 
-        hir::ExprIndex(ref lhs, ref rhs) => {
+        hir::ExprKind::Index(ref lhs, ref rhs) => {
             let lefty = v.check_expr(lhs);
             let righty = v.check_expr(rhs);
             if v.tables.is_method_call(e) {
@@ -544,7 +545,7 @@ fn check_expr_kind<'a, 'tcx>(
             lefty & righty
         }
 
-        hir::ExprArray(ref hirvec) => {
+        hir::ExprKind::Array(ref hirvec) => {
             let mut array_result = Promotable;
             for index in hirvec.iter() {
                 array_result = array_result & v.check_expr(index);
@@ -552,11 +553,11 @@ fn check_expr_kind<'a, 'tcx>(
             array_result
         }
 
-        hir::ExprType(ref expr, ref _ty) => {
+        hir::ExprKind::Type(ref expr, ref _ty) => {
             v.check_expr(&expr)
         }
 
-        hir::ExprTup(ref hirvec) => {
+        hir::ExprKind::Tup(ref hirvec) => {
             let mut tup_result = Promotable;
             for index in hirvec.iter() {
                 tup_result = tup_result & v.check_expr(index);
@@ -566,7 +567,7 @@ fn check_expr_kind<'a, 'tcx>(
 
 
         // Conditional control flow (possible to implement).
-        hir::ExprMatch(ref expr, ref hirvec_arm, ref _match_source) => {
+        hir::ExprKind::Match(ref expr, ref hirvec_arm, ref _match_source) => {
             // Compute the most demanding borrow from all the arms'
             // patterns and set that on the discriminator.
             let mut mut_borrow = false;
@@ -590,7 +591,7 @@ fn check_expr_kind<'a, 'tcx>(
             NotPromotable
         }
 
-        hir::ExprIf(ref lhs, ref rhs, ref option_expr) => {
+        hir::ExprKind::If(ref lhs, ref rhs, ref option_expr) => {
             let _ = v.check_expr(lhs);
             let _ = v.check_expr(rhs);
             match option_expr {
@@ -601,19 +602,19 @@ fn check_expr_kind<'a, 'tcx>(
         }
 
         // Loops (not very meaningful in constants).
-        hir::ExprWhile(ref expr, ref box_block, ref _option_label) => {
+        hir::ExprKind::While(ref expr, ref box_block, ref _option_label) => {
             let _ = v.check_expr(expr);
             let _ = v.check_block(box_block);
             NotPromotable
         }
 
-        hir::ExprLoop(ref box_block, ref _option_label, ref _loop_source) => {
+        hir::ExprKind::Loop(ref box_block, ref _option_label, ref _loop_source) => {
             let _ = v.check_block(box_block);
             NotPromotable
         }
 
         // More control flow (also not very meaningful).
-        hir::ExprBreak(_, ref option_expr) | hir::ExprRet(ref option_expr) => {
+        hir::ExprKind::Break(_, ref option_expr) | hir::ExprKind::Ret(ref option_expr) => {
             match *option_expr {
                 Some(ref expr) => { let _ = v.check_expr(&expr); },
                 None => {},
@@ -621,24 +622,24 @@ fn check_expr_kind<'a, 'tcx>(
             NotPromotable
         }
 
-        hir::ExprContinue(_) => {
+        hir::ExprKind::Continue(_) => {
             NotPromotable
         }
 
         // Generator expressions
-        hir::ExprYield(ref expr) => {
+        hir::ExprKind::Yield(ref expr) => {
             let _ = v.check_expr(&expr);
             NotPromotable
         }
 
         // Expressions with side-effects.
-        hir::ExprAssignOp(_, ref lhs, ref rhs) | hir::ExprAssign(ref lhs, ref rhs) => {
+        hir::ExprKind::AssignOp(_, ref lhs, ref rhs) | hir::ExprKind::Assign(ref lhs, ref rhs) => {
             let _ = v.check_expr(lhs);
             let _ = v.check_expr(rhs);
             NotPromotable
         }
 
-        hir::ExprInlineAsm(ref _inline_asm, ref hirvec_lhs, ref hirvec_rhs) => {
+        hir::ExprKind::InlineAsm(ref _inline_asm, ref hirvec_lhs, ref hirvec_rhs) => {
             for index in hirvec_lhs.iter() {
                 let _ = v.check_expr(index);
             }