diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index aab70456dc18d..f1e2794691556 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]) } @@ -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, } } @@ -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 2d83c158fe08f..3f6d34617c832 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -38,13 +38,13 @@ enum Target { impl Target { fn from_item(item: &hir::Item) -> Target { match item.node { - hir::ItemFn(..) => Target::Fn, - hir::ItemStruct(..) => Target::Struct, - hir::ItemUnion(..) => Target::Union, - hir::ItemEnum(..) => Target::Enum, - hir::ItemConst(..) => Target::Const, - hir::ItemForeignMod(..) => Target::ForeignMod, - hir::ItemStatic(..) => Target::Static, + hir::ItemKind::Fn(..) => Target::Fn, + hir::ItemKind::Struct(..) => Target::Struct, + hir::ItemKind::Union(..) => Target::Union, + hir::ItemKind::Enum(..) => Target::Enum, + hir::ItemKind::Const(..) => Target::Const, + hir::ItemKind::ForeignMod(..) => Target::ForeignMod, + hir::ItemKind::Static(..) => Target::Static, _ => Target::Other, } } @@ -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); @@ -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() { @@ -340,7 +340,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { } fn is_c_like_enum(item: &hir::Item) -> bool { - if let hir::ItemEnum(ref def, _) = item.node { + if let hir::ItemKind::Enum(ref def, _) = item.node { for variant in &def.variants { match variant.node.data { hir::VariantData::Unit(_) => { /* continue */ } diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index e2c0020db2ff3..2fefd2b33189c 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -50,6 +50,7 @@ use super::itemlikevisit::DeepVisitor; use std::cmp; use std::u32; +use std::result::Result::Err; #[derive(Copy, Clone)] pub enum FnKind<'a> { @@ -462,23 +463,23 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_vis(&item.vis); visitor.visit_name(item.span, item.name); match item.node { - ItemExternCrate(orig_name) => { + ItemKind::ExternCrate(orig_name) => { visitor.visit_id(item.id); if let Some(orig_name) = orig_name { visitor.visit_name(item.span, orig_name); } } - ItemUse(ref path, _) => { + ItemKind::Use(ref path, _) => { visitor.visit_id(item.id); visitor.visit_path(path, item.id); } - ItemStatic(ref typ, _, body) | - ItemConst(ref typ, body) => { + ItemKind::Static(ref typ, _, body) | + ItemKind::Const(ref typ, body) => { visitor.visit_id(item.id); visitor.visit_ty(typ); visitor.visit_nested_body(body); } - ItemFn(ref declaration, header, ref generics, body_id) => { + ItemKind::Fn(ref declaration, header, ref generics, body_id) => { visitor.visit_fn(FnKind::ItemFn(item.name, generics, header, @@ -489,23 +490,23 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { item.span, item.id) } - ItemMod(ref module) => { + ItemKind::Mod(ref module) => { // visit_mod() takes care of visiting the Item's NodeId visitor.visit_mod(module, item.span, item.id) } - ItemForeignMod(ref foreign_module) => { + ItemKind::ForeignMod(ref foreign_module) => { visitor.visit_id(item.id); walk_list!(visitor, visit_foreign_item, &foreign_module.items); } - ItemGlobalAsm(_) => { + ItemKind::GlobalAsm(_) => { visitor.visit_id(item.id); } - ItemTy(ref typ, ref type_parameters) => { + ItemKind::Ty(ref typ, ref type_parameters) => { visitor.visit_id(item.id); visitor.visit_ty(typ); visitor.visit_generics(type_parameters) } - ItemExistential(ExistTy {ref generics, ref bounds, impl_trait_fn}) => { + ItemKind::Existential(ExistTy {ref generics, ref bounds, impl_trait_fn}) => { visitor.visit_id(item.id); walk_generics(visitor, generics); walk_list!(visitor, visit_param_bound, bounds); @@ -513,31 +514,37 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_def_mention(Def::Fn(impl_trait_fn)) } } - ItemEnum(ref enum_definition, ref type_parameters) => { + ItemKind::Enum(ref enum_definition, ref type_parameters) => { visitor.visit_generics(type_parameters); // visit_enum_def() takes care of visiting the Item's NodeId visitor.visit_enum_def(enum_definition, type_parameters, item.id, item.span) } - ItemImpl(.., ref type_parameters, ref opt_trait_reference, ref typ, ref impl_item_refs) => { + ItemKind::Impl( + .., + ref type_parameters, + ref opt_trait_reference, + ref typ, + ref impl_item_refs + ) => { visitor.visit_id(item.id); visitor.visit_generics(type_parameters); walk_list!(visitor, visit_trait_ref, opt_trait_reference); visitor.visit_ty(typ); walk_list!(visitor, visit_impl_item_ref, impl_item_refs); } - ItemStruct(ref struct_definition, ref generics) | - ItemUnion(ref struct_definition, ref generics) => { + ItemKind::Struct(ref struct_definition, ref generics) | + ItemKind::Union(ref struct_definition, ref generics) => { visitor.visit_generics(generics); visitor.visit_id(item.id); visitor.visit_variant_data(struct_definition, item.name, generics, item.id, item.span); } - ItemTrait(.., ref generics, ref bounds, ref trait_item_refs) => { + ItemKind::Trait(.., ref generics, ref bounds, ref trait_item_refs) => { visitor.visit_id(item.id); visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_trait_item_ref, trait_item_refs); } - ItemTraitAlias(ref generics, ref bounds) => { + ItemKind::TraitAlias(ref generics, ref bounds) => { visitor.visit_id(item.id); visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); @@ -576,41 +583,41 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { visitor.visit_id(typ.id); match typ.node { - TySlice(ref ty) => { + TyKind::Slice(ref ty) => { visitor.visit_ty(ty) } - TyPtr(ref mutable_type) => { + TyKind::Ptr(ref mutable_type) => { visitor.visit_ty(&mutable_type.ty) } - TyRptr(ref lifetime, ref mutable_type) => { + TyKind::Rptr(ref lifetime, ref mutable_type) => { visitor.visit_lifetime(lifetime); visitor.visit_ty(&mutable_type.ty) } - TyNever => {}, - TyTup(ref tuple_element_types) => { + TyKind::Never => {}, + TyKind::Tup(ref tuple_element_types) => { walk_list!(visitor, visit_ty, tuple_element_types); } - TyBareFn(ref function_declaration) => { + TyKind::BareFn(ref function_declaration) => { walk_list!(visitor, visit_generic_param, &function_declaration.generic_params); visitor.visit_fn_decl(&function_declaration.decl); } - TyPath(ref qpath) => { + TyKind::Path(ref qpath) => { visitor.visit_qpath(qpath, typ.id, typ.span); } - TyArray(ref ty, ref length) => { + TyKind::Array(ref ty, ref length) => { visitor.visit_ty(ty); visitor.visit_anon_const(length) } - TyTraitObject(ref bounds, ref lifetime) => { + TyKind::TraitObject(ref bounds, ref lifetime) => { for bound in bounds { visitor.visit_poly_trait_ref(bound, TraitBoundModifier::None); } visitor.visit_lifetime(lifetime); } - TyTypeof(ref expression) => { + TyKind::Typeof(ref expression) => { visitor.visit_anon_const(expression) } - TyInfer | TyErr => {} + TyKind::Infer | TyKind::Err => {} } } @@ -709,15 +716,15 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v visitor.visit_name(foreign_item.span, foreign_item.name); match foreign_item.node { - ForeignItemFn(ref function_declaration, ref param_names, ref generics) => { + ForeignItemKind::Fn(ref function_declaration, ref param_names, ref generics) => { visitor.visit_generics(generics); visitor.visit_fn_decl(function_declaration); for ¶m_name in param_names { visitor.visit_ident(param_name); } } - ForeignItemStatic(ref typ, _) => visitor.visit_ty(typ), - ForeignItemType => (), + ForeignItemKind::Static(ref typ, _) => visitor.visit_ty(typ), + ForeignItemKind::Type => (), } walk_list!(visitor, visit_attribute, &foreign_item.attrs); @@ -935,12 +942,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) } @@ -949,8 +956,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), } } @@ -963,17 +970,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 +989,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 +1070,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 +1079,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 +1090,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 cb53f963d41f1..722934ac39a53 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -384,8 +384,8 @@ impl<'a> LoweringContext<'a> { if item_lowered { let item_generics = match self.lctx.items.get(&item.id).unwrap().node { - hir::Item_::ItemImpl(_, _, _, ref generics, ..) - | hir::Item_::ItemTrait(_, _, ref generics, ..) => { + hir::ItemKind::Impl(_, _, _, ref generics, ..) + | hir::ItemKind::Trait(_, _, ref generics, ..) => { generics.params.clone() } _ => HirVec::new(), @@ -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 @@ -1080,17 +1080,17 @@ impl<'a> LoweringContext<'a> { fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext) -> hir::Ty { let kind = match t.node { - TyKind::Infer => hir::TyInfer, - TyKind::Err => hir::TyErr, - TyKind::Slice(ref ty) => hir::TySlice(self.lower_ty(ty, itctx)), - TyKind::Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt, itctx)), + TyKind::Infer => hir::TyKind::Infer, + TyKind::Err => hir::TyKind::Err, + TyKind::Slice(ref ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)), + TyKind::Ptr(ref mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)), TyKind::Rptr(ref region, ref mt) => { let span = t.span.shrink_to_lo(); let lifetime = match *region { Some(ref lt) => self.lower_lifetime(lt), None => self.elided_ref_lifetime(span), }; - hir::TyRptr(lifetime, self.lower_mt(mt, itctx)) + hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx)) } TyKind::BareFn(ref f) => self.with_in_scope_lifetime_defs( &f.generic_params, @@ -1098,7 +1098,7 @@ impl<'a> LoweringContext<'a> { this.with_anonymous_lifetime_mode( AnonymousLifetimeMode::PassThrough, |this| { - hir::TyBareFn(P(hir::BareFnTy { + hir::TyKind::BareFn(P(hir::BareFnTy { generic_params: this.lower_generic_params( &f.generic_params, &NodeMap(), @@ -1113,9 +1113,9 @@ impl<'a> LoweringContext<'a> { ) }, ), - TyKind::Never => hir::TyNever, + TyKind::Never => hir::TyKind::Never, TyKind::Tup(ref tys) => { - hir::TyTup(tys.iter().map(|ty| { + hir::TyKind::Tup(tys.iter().map(|ty| { self.lower_ty_direct(ty, itctx.reborrow()) }).collect()) } @@ -1126,12 +1126,12 @@ impl<'a> LoweringContext<'a> { let id = self.lower_node_id(t.id); let qpath = self.lower_qpath(t.id, qself, path, ParamMode::Explicit, itctx); let ty = self.ty_path(id, t.span, qpath); - if let hir::TyTraitObject(..) = ty.node { + if let hir::TyKind::TraitObject(..) = ty.node { self.maybe_lint_bare_trait(t.span, t.id, qself.is_none() && path.is_global()); } return ty; } - TyKind::ImplicitSelf => hir::TyPath(hir::QPath::Resolved( + TyKind::ImplicitSelf => hir::TyKind::Path(hir::QPath::Resolved( None, P(hir::Path { def: self.expect_full_def(t.id), @@ -1140,10 +1140,10 @@ impl<'a> LoweringContext<'a> { }), )), TyKind::Array(ref ty, ref length) => { - hir::TyArray(self.lower_ty(ty, itctx), self.lower_anon_const(length)) + hir::TyKind::Array(self.lower_ty(ty, itctx), self.lower_anon_const(length)) } TyKind::Typeof(ref expr) => { - hir::TyTypeof(self.lower_anon_const(expr)) + hir::TyKind::Typeof(self.lower_anon_const(expr)) } TyKind::TraitObject(ref bounds, kind) => { let mut lifetime_bound = None; @@ -1167,7 +1167,7 @@ impl<'a> LoweringContext<'a> { if kind != TraitObjectSyntax::Dyn { self.maybe_lint_bare_trait(t.span, t.id, false); } - hir::TyTraitObject(bounds, lifetime_bound) + hir::TyKind::TraitObject(bounds, lifetime_bound) } TyKind::ImplTrait(def_node_id, ref bounds) => { let span = t.span; @@ -1206,7 +1206,7 @@ impl<'a> LoweringContext<'a> { } }); - hir::TyPath(hir::QPath::Resolved( + hir::TyKind::Path(hir::QPath::Resolved( None, P(hir::Path { span, @@ -1223,7 +1223,7 @@ impl<'a> LoweringContext<'a> { "`impl Trait` not allowed outside of function \ and inherent method return types" ); - hir::TyErr + hir::TyKind::Err } } } @@ -1245,7 +1245,7 @@ impl<'a> LoweringContext<'a> { fn_def_id: DefId, exist_ty_node_id: NodeId, lower_bounds: impl FnOnce(&mut LoweringContext) -> hir::GenericBounds, - ) -> hir::Ty_ { + ) -> hir::TyKind { // Make sure we know that some funky desugaring has been going on here. // This is a first: there is code in other places like for loop // desugaring that explicitly states that we don't want to track that. @@ -1274,7 +1274,7 @@ impl<'a> LoweringContext<'a> { ); self.with_hir_id_owner(exist_ty_node_id, |lctx| { - let exist_ty_item_kind = hir::ItemExistential(hir::ExistTy { + let exist_ty_item_kind = hir::ItemKind::Existential(hir::ExistTy { generics: hir::Generics { params: lifetime_defs, where_clause: hir::WhereClause { @@ -1320,7 +1320,7 @@ impl<'a> LoweringContext<'a> { })) }], }); - hir::TyPath(hir::QPath::Resolved(None, path)) + hir::TyKind::Path(hir::QPath::Resolved(None, path)) }) } @@ -1365,7 +1365,7 @@ impl<'a> LoweringContext<'a> { fn visit_ty(&mut self, t: &'v hir::Ty) { // Don't collect elided lifetimes used inside of `fn()` syntax - if let hir::Ty_::TyBareFn(_) = t.node { + if let hir::TyKind::BareFn(_) = t.node { let old_collect_elided_lifetimes = self.collect_elided_lifetimes; self.collect_elided_lifetimes = false; @@ -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), @@ -1805,7 +1805,7 @@ impl<'a> LoweringContext<'a> { let inputs = inputs.iter().map(|ty| this.lower_ty_direct(ty, DISALLOWED)).collect(); let mk_tup = |this: &mut Self, tys, span| { let LoweredNodeId { node_id, hir_id } = this.next_id(); - hir::Ty { node: hir::TyTup(tys), id: node_id, hir_id, span } + hir::Ty { node: hir::TyKind::Tup(tys), id: node_id, hir_id, span } }; ( @@ -1985,7 +1985,7 @@ impl<'a> LoweringContext<'a> { fn visit_ty(&mut self, t: &'v hir::Ty) { // Don't collect elided lifetimes used inside of `fn()` syntax - if let &hir::Ty_::TyBareFn(_) = &t.node { + if let &hir::TyKind::BareFn(_) = &t.node { let old_collect_elided_lifetimes = self.collect_elided_lifetimes; self.collect_elided_lifetimes = false; @@ -2105,7 +2105,7 @@ impl<'a> LoweringContext<'a> { P(hir::Ty { id: node_id, hir_id: hir_id, - node: hir::TyTup(hir_vec![]), + node: hir::TyKind::Tup(hir_vec![]), span: *span, }) } @@ -2575,9 +2575,9 @@ impl<'a> LoweringContext<'a> { attrs: &hir::HirVec, vis: &mut hir::Visibility, i: &ItemKind, - ) -> hir::Item_ { + ) -> hir::ItemKind { match *i { - ItemKind::ExternCrate(orig_name) => hir::ItemExternCrate(orig_name), + ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(orig_name), ItemKind::Use(ref use_tree) => { // Start with an empty prefix let prefix = Path { @@ -2589,7 +2589,7 @@ impl<'a> LoweringContext<'a> { } ItemKind::Static(ref t, m, ref e) => { let value = self.lower_body(None, |this| this.lower_expr(e)); - hir::ItemStatic( + hir::ItemKind::Static( self.lower_ty(t, ImplTraitContext::Disallowed), self.lower_mutability(m), value, @@ -2597,7 +2597,7 @@ impl<'a> LoweringContext<'a> { } ItemKind::Const(ref t, ref e) => { let value = self.lower_body(None, |this| this.lower_expr(e)); - hir::ItemConst(self.lower_ty(t, ImplTraitContext::Disallowed), value) + hir::ItemKind::Const(self.lower_ty(t, ImplTraitContext::Disallowed), value) } ItemKind::Fn(ref decl, header, ref generics, ref body) => { let fn_def_id = self.resolver.definitions().local_def_id(id); @@ -2617,7 +2617,7 @@ impl<'a> LoweringContext<'a> { decl, Some((fn_def_id, idty)), true, header.asyncness.opt_return_id()), ); - hir::ItemFn( + hir::ItemKind::Fn( fn_decl, this.lower_fn_header(header), generics, @@ -2625,14 +2625,14 @@ impl<'a> LoweringContext<'a> { ) }) } - ItemKind::Mod(ref m) => hir::ItemMod(self.lower_mod(m)), - ItemKind::ForeignMod(ref nm) => hir::ItemForeignMod(self.lower_foreign_mod(nm)), - ItemKind::GlobalAsm(ref ga) => hir::ItemGlobalAsm(self.lower_global_asm(ga)), - ItemKind::Ty(ref t, ref generics) => hir::ItemTy( + ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)), + ItemKind::ForeignMod(ref nm) => hir::ItemKind::ForeignMod(self.lower_foreign_mod(nm)), + ItemKind::GlobalAsm(ref ga) => hir::ItemKind::GlobalAsm(self.lower_global_asm(ga)), + ItemKind::Ty(ref t, ref generics) => hir::ItemKind::Ty( self.lower_ty(t, ImplTraitContext::Disallowed), self.lower_generics(generics, ImplTraitContext::Disallowed), ), - ItemKind::Enum(ref enum_definition, ref generics) => hir::ItemEnum( + ItemKind::Enum(ref enum_definition, ref generics) => hir::ItemKind::Enum( hir::EnumDef { variants: enum_definition .variants @@ -2644,14 +2644,14 @@ impl<'a> LoweringContext<'a> { ), ItemKind::Struct(ref struct_def, ref generics) => { let struct_def = self.lower_variant_data(struct_def); - hir::ItemStruct( + hir::ItemKind::Struct( struct_def, self.lower_generics(generics, ImplTraitContext::Disallowed), ) } ItemKind::Union(ref vdata, ref generics) => { let vdata = self.lower_variant_data(vdata); - hir::ItemUnion( + hir::ItemKind::Union( vdata, self.lower_generics(generics, ImplTraitContext::Disallowed), ) @@ -2711,7 +2711,7 @@ impl<'a> LoweringContext<'a> { }, ); - hir::ItemImpl( + hir::ItemKind::Impl( self.lower_unsafety(unsafety), self.lower_impl_polarity(polarity), self.lower_defaultness(defaultness, true /* [1] */), @@ -2727,7 +2727,7 @@ impl<'a> LoweringContext<'a> { .iter() .map(|item| self.lower_trait_item_ref(item)) .collect(); - hir::ItemTrait( + hir::ItemKind::Trait( self.lower_is_auto(is_auto), self.lower_unsafety(unsafety), self.lower_generics(generics, ImplTraitContext::Disallowed), @@ -2735,7 +2735,7 @@ impl<'a> LoweringContext<'a> { items, ) } - ItemKind::TraitAlias(ref generics, ref bounds) => hir::ItemTraitAlias( + ItemKind::TraitAlias(ref generics, ref bounds) => hir::ItemKind::TraitAlias( self.lower_generics(generics, ImplTraitContext::Disallowed), self.lower_param_bounds(bounds, ImplTraitContext::Disallowed), ), @@ -2754,7 +2754,7 @@ impl<'a> LoweringContext<'a> { vis: &mut hir::Visibility, name: &mut Name, attrs: &hir::HirVec, - ) -> hir::Item_ { + ) -> hir::ItemKind { let path = &tree.prefix; match tree.kind { @@ -2804,7 +2804,7 @@ impl<'a> LoweringContext<'a> { self.with_hir_id_owner(new_node_id, |this| { let new_id = this.lower_node_id(new_node_id); let path = this.lower_path_extra(def, &path, None, ParamMode::Explicit); - let item = hir::ItemUse(P(path), hir::UseKind::Single); + let item = hir::ItemKind::Use(P(path), hir::UseKind::Single); let vis_kind = match vis.node { hir::VisibilityKind::Public => hir::VisibilityKind::Public, hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar), @@ -2835,7 +2835,7 @@ impl<'a> LoweringContext<'a> { } let path = P(self.lower_path_extra(ret_def, &path, None, ParamMode::Explicit)); - hir::ItemUse(path, hir::UseKind::Single) + hir::ItemKind::Use(path, hir::UseKind::Single) } UseTreeKind::Glob => { let path = P(self.lower_path( @@ -2851,7 +2851,7 @@ impl<'a> LoweringContext<'a> { }, ParamMode::Explicit, )); - hir::ItemUse(path, hir::UseKind::Glob) + hir::ItemKind::Use(path, hir::UseKind::Glob) } UseTreeKind::Nested(ref trees) => { let prefix = Path { @@ -2912,7 +2912,7 @@ impl<'a> LoweringContext<'a> { // a re-export by accident when `pub`, e.g. in documentation. let path = P(self.lower_path(id, &prefix, ParamMode::Explicit)); *vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited); - hir::ItemUse(path, hir::UseKind::ListStem) + hir::ItemKind::Use(path, hir::UseKind::ListStem) } } } @@ -3230,12 +3230,12 @@ impl<'a> LoweringContext<'a> { }, ); - hir::ForeignItemFn(fn_dec, fn_args, generics) + hir::ForeignItemKind::Fn(fn_dec, fn_args, generics) } ForeignItemKind::Static(ref t, m) => { - hir::ForeignItemStatic(self.lower_ty(t, ImplTraitContext::Disallowed), m) + hir::ForeignItemKind::Static(self.lower_ty(t, ImplTraitContext::Disallowed), m) } - ForeignItemKind::Ty => hir::ForeignItemType, + ForeignItemKind::Ty => hir::ForeignItemKind::Type, ForeignItemKind::Macro(_) => panic!("shouldn't exist here"), }, vis: self.lower_visibility(&i.vis, None), @@ -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, } @@ -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,10 @@ 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 +3919,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 +3967,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, @@ -3995,7 +3997,7 @@ impl<'a> LoweringContext<'a> { // ::std::option::Option::None => break // }; // let = __next; - // StmtExpr(); + // StmtKind::Expr(); // } // } // }; @@ -4023,7 +4025,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,11 +4055,18 @@ 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(), )) }; - 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 +4085,10 @@ 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, @@ -4085,7 +4097,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 +4217,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 +4227,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, @@ -4246,9 +4258,9 @@ 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)), + node: hir::DeclKind::Local(self.lower_local(l)), span: s.span, }), self.lower_node_id(s.id).node_id, @@ -4261,9 +4273,9 @@ 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), + node: hir::DeclKind::Item(item_id), span: s.span, }), id.take() @@ -4275,11 +4287,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"), @@ -4390,7 +4402,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 +4412,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 +4426,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 +4439,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 +4452,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 +4464,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, @@ -4493,8 +4505,8 @@ impl<'a> LoweringContext<'a> { attrs: ThinVec::new(), source, }); - let decl = respan(sp, hir::DeclLocal(local)); - respan(sp, hir::StmtDecl(P(decl), self.next_id().node_id)) + let decl = respan(sp, hir::DeclKind::Local(local)); + respan(sp, hir::StmtKind::Decl(P(decl), self.next_id().node_id)) } fn stmt_let( @@ -4624,7 +4636,7 @@ impl<'a> LoweringContext<'a> { let mut id = id; let node = match qpath { hir::QPath::Resolved(None, path) => { - // Turn trait object paths into `TyTraitObject` instead. + // Turn trait object paths into `TyKind::TraitObject` instead. if let Def::Trait(_) = path.def { let principal = hir::PolyTraitRef { bound_generic_params: hir::HirVec::new(), @@ -4638,12 +4650,12 @@ impl<'a> LoweringContext<'a> { // The original ID is taken by the `PolyTraitRef`, // so the `Ty` itself needs a different one. id = self.next_id(); - hir::TyTraitObject(hir_vec![principal], self.elided_dyn_bound(span)) + hir::TyKind::TraitObject(hir_vec![principal], self.elided_dyn_bound(span)) } else { - hir::TyPath(hir::QPath::Resolved(None, path)) + hir::TyKind::Path(hir::QPath::Resolved(None, path)) } } - _ => hir::TyPath(qpath), + _ => hir::TyKind::Path(qpath), }; hir::Ty { id: id.node_id, diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 930db8b0ccc3f..5a595d14db7aa 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. @@ -47,7 +47,7 @@ pub trait MaybeFnLike { fn is_fn_like(&self) -> bool; } impl MaybeFnLike for ast::Item { fn is_fn_like(&self) -> bool { - match self.node { ast::ItemFn(..) => true, _ => false, } + match self.node { ast::ItemKind::Fn(..) => true, _ => false, } } } @@ -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, } } @@ -229,7 +229,7 @@ impl<'a> FnLikeNode<'a> { { match self.node { map::NodeItem(i) => match i.node { - ast::ItemFn(ref decl, header, ref generics, block) => + ast::ItemKind::Fn(ref decl, header, ref generics, block) => item_fn(ItemFnParts { id: i.id, name: i.name, @@ -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/collector.rs b/src/librustc/hir/map/collector.rs index 3cc25bfd2d4d7..0150ba659c900 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -329,7 +329,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { this.insert(i.id, NodeItem(i)); this.with_parent(i.id, |this| { match i.node { - ItemStruct(ref struct_def, _) => { + ItemKind::Struct(ref struct_def, _) => { // If this is a tuple-like struct, register the constructor. if !struct_def.is_struct() { this.insert(struct_def.id(), NodeStructCtor(struct_def)); diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index b90bca84ed602..656f325b4dd89 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -179,7 +179,7 @@ impl<'a, 'hir: 'a> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> { fn visit_impl_item_ref(&mut self, _: &'hir hir::ImplItemRef) { // Explicitly do nothing here. ImplItemRefs contain hir::Visibility - // values that actually belong to an ImplItem instead of the ItemImpl + // values that actually belong to an ImplItem instead of the ItemKind::Impl // we are currently in. So for those it's correct that they have a // different owner. } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 08a130f049bf7..d413a544c4e41 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -33,6 +33,7 @@ use hir::svh::Svh; use util::nodemap::FxHashMap; use std::io; +use std::result::Result::Err; use ty::TyCtxt; pub mod blocks; @@ -174,7 +175,7 @@ impl<'hir> MapEntry<'hir> { match self { EntryItem(_, _, ref item) => { match item.node { - ItemFn(ref fn_decl, _, _, _) => Some(&fn_decl), + ItemKind::Fn(ref fn_decl, _, _, _) => Some(&fn_decl), _ => None, } } @@ -195,7 +196,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, } } @@ -208,9 +209,9 @@ impl<'hir> MapEntry<'hir> { match self { EntryItem(_, _, item) => { match item.node { - ItemConst(_, body) | - ItemStatic(.., body) | - ItemFn(_, _, _, body) => Some(body), + ItemKind::Const(_, body) | + ItemKind::Static(.., body) | + ItemKind::Fn(_, _, _, body) => Some(body), _ => None, } } @@ -235,7 +236,7 @@ impl<'hir> MapEntry<'hir> { EntryExpr(_, _, expr) => { match expr.node { - ExprClosure(.., body, _, _) => Some(body), + ExprKind::Closure(.., body, _, _) => Some(body), _ => None, } } @@ -426,33 +427,33 @@ impl<'hir> Map<'hir> { }; match item.node { - ItemStatic(_, m, _) => Some(Def::Static(def_id(), + ItemKind::Static(_, m, _) => Some(Def::Static(def_id(), m == MutMutable)), - ItemConst(..) => Some(Def::Const(def_id())), - ItemFn(..) => Some(Def::Fn(def_id())), - ItemMod(..) => Some(Def::Mod(def_id())), - ItemGlobalAsm(..) => Some(Def::GlobalAsm(def_id())), - ItemExistential(..) => Some(Def::Existential(def_id())), - ItemTy(..) => Some(Def::TyAlias(def_id())), - ItemEnum(..) => Some(Def::Enum(def_id())), - ItemStruct(..) => Some(Def::Struct(def_id())), - ItemUnion(..) => Some(Def::Union(def_id())), - ItemTrait(..) => Some(Def::Trait(def_id())), - ItemTraitAlias(..) => { + ItemKind::Const(..) => Some(Def::Const(def_id())), + ItemKind::Fn(..) => Some(Def::Fn(def_id())), + ItemKind::Mod(..) => Some(Def::Mod(def_id())), + ItemKind::GlobalAsm(..) => Some(Def::GlobalAsm(def_id())), + ItemKind::Existential(..) => Some(Def::Existential(def_id())), + ItemKind::Ty(..) => Some(Def::TyAlias(def_id())), + ItemKind::Enum(..) => Some(Def::Enum(def_id())), + ItemKind::Struct(..) => Some(Def::Struct(def_id())), + ItemKind::Union(..) => Some(Def::Union(def_id())), + ItemKind::Trait(..) => Some(Def::Trait(def_id())), + ItemKind::TraitAlias(..) => { bug!("trait aliases are not yet implemented (see issue #41517)") }, - ItemExternCrate(_) | - ItemUse(..) | - ItemForeignMod(..) | - ItemImpl(..) => None, + ItemKind::ExternCrate(_) | + ItemKind::Use(..) | + ItemKind::ForeignMod(..) | + ItemKind::Impl(..) => None, } } NodeForeignItem(item) => { let def_id = self.local_def_id(item.id); match item.node { - ForeignItemFn(..) => Some(Def::Fn(def_id)), - ForeignItemStatic(_, m) => Some(Def::Static(def_id, m)), - ForeignItemType => Some(Def::TyForeign(def_id)), + ForeignItemKind::Fn(..) => Some(Def::Fn(def_id)), + ForeignItemKind::Static(_, m) => Some(Def::Static(def_id, m)), + ForeignItemKind::Type => Some(Def::TyForeign(def_id)), } } NodeTraitItem(item) => { @@ -586,13 +587,13 @@ impl<'hir> Map<'hir> { pub fn body_owner_kind(&self, id: NodeId) -> BodyOwnerKind { match self.get(id) { - NodeItem(&Item { node: ItemConst(..), .. }) | + NodeItem(&Item { node: ItemKind::Const(..), .. }) | NodeTraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) | NodeImplItem(&ImplItem { node: ImplItemKind::Const(..), .. }) | NodeAnonConst(_) => { BodyOwnerKind::Const } - NodeItem(&Item { node: ItemStatic(_, m, _), .. }) => { + NodeItem(&Item { node: ItemKind::Static(_, m, _), .. }) => { BodyOwnerKind::Static(m) } // Default to function if it's not a constant or static. @@ -602,7 +603,7 @@ impl<'hir> Map<'hir> { pub fn ty_param_owner(&self, id: NodeId) -> NodeId { match self.get(id) { - NodeItem(&Item { node: ItemTrait(..), .. }) => id, + NodeItem(&Item { node: ItemKind::Trait(..), .. }) => id, NodeGenericParam(_) => self.get_parent_node(id), _ => { bug!("ty_param_owner: {} not a type parameter", @@ -613,7 +614,7 @@ impl<'hir> Map<'hir> { pub fn ty_param_name(&self, id: NodeId) -> Name { match self.get(id) { - NodeItem(&Item { node: ItemTrait(..), .. }) => { + NodeItem(&Item { node: ItemKind::Trait(..), .. }) => { keywords::SelfType.name() } NodeGenericParam(param) => param.name.ident().name, @@ -671,14 +672,14 @@ impl<'hir> Map<'hir> { NodeTraitItem(ref trait_item) => Some(&trait_item.generics), NodeItem(ref item) => { match item.node { - ItemFn(_, _, ref generics, _) | - ItemTy(_, ref generics) | - ItemEnum(_, ref generics) | - ItemStruct(_, ref generics) | - ItemUnion(_, ref generics) | - ItemTrait(_, _, ref generics, ..) | - ItemTraitAlias(ref generics, _) | - ItemImpl(_, _, _, ref generics, ..) => Some(generics), + ItemKind::Fn(_, _, ref generics, _) | + ItemKind::Ty(_, ref generics) | + ItemKind::Enum(_, ref generics) | + ItemKind::Struct(_, ref generics) | + ItemKind::Union(_, ref generics) | + ItemKind::Trait(_, _, ref generics, ..) | + ItemKind::TraitAlias(ref generics, _) | + ItemKind::Impl(_, _, _, ref generics, ..) => Some(generics), _ => None, } } @@ -734,7 +735,7 @@ impl<'hir> Map<'hir> { Some(NodeImplItem(_)) => true, Some(NodeExpr(e)) => { match e.node { - ExprClosure(..) => true, + ExprKind::Closure(..) => true, _ => false, } } @@ -821,7 +822,7 @@ impl<'hir> Map<'hir> { match *node { NodeExpr(ref expr) => { match expr.node { - ExprWhile(..) | ExprLoop(..) => true, + ExprKind::While(..) | ExprKind::Loop(..) => true, _ => false, } } @@ -856,7 +857,7 @@ impl<'hir> Map<'hir> { /// module parent is in this map. pub fn get_module_parent(&self, id: NodeId) -> DefId { let id = match self.walk_parent_nodes(id, |node| match *node { - NodeItem(&Item { node: Item_::ItemMod(_), .. }) => true, + NodeItem(&Item { node: ItemKind::Mod(_), .. }) => true, _ => false, }, |_| false) { Ok(id) => id, @@ -892,7 +893,7 @@ impl<'hir> Map<'hir> { let abi = match self.find_entry(parent) { Some(EntryItem(_, _, i)) => { match i.node { - ItemForeignMod(ref nm) => Some(nm.abi), + ItemKind::ForeignMod(ref nm) => Some(nm.abi), _ => None } } @@ -933,8 +934,8 @@ impl<'hir> Map<'hir> { match self.find(id) { Some(NodeItem(i)) => { match i.node { - ItemStruct(ref struct_def, _) | - ItemUnion(ref struct_def, _) => struct_def, + ItemKind::Struct(ref struct_def, _) | + ItemKind::Union(ref struct_def, _) => struct_def, _ => { bug!("struct ID bound to non-struct {}", self.node_to_string(id)); @@ -1128,7 +1129,7 @@ impl<'a, 'hir> NodesMatchingSuffix<'a, 'hir> { fn item_is_mod(item: &Item) -> bool { match item.node { - ItemMod(_) => true, + ItemKind::Mod(_) => true, _ => false, } } @@ -1176,7 +1177,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 } } @@ -1313,22 +1314,22 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String { match map.find(id) { Some(NodeItem(item)) => { let item_str = match item.node { - ItemExternCrate(..) => "extern crate", - ItemUse(..) => "use", - ItemStatic(..) => "static", - ItemConst(..) => "const", - ItemFn(..) => "fn", - ItemMod(..) => "mod", - ItemForeignMod(..) => "foreign mod", - ItemGlobalAsm(..) => "global asm", - ItemTy(..) => "ty", - ItemExistential(..) => "existential", - ItemEnum(..) => "enum", - ItemStruct(..) => "struct", - ItemUnion(..) => "union", - ItemTrait(..) => "trait", - ItemTraitAlias(..) => "trait alias", - ItemImpl(..) => "impl", + ItemKind::ExternCrate(..) => "extern crate", + ItemKind::Use(..) => "use", + ItemKind::Static(..) => "static", + ItemKind::Const(..) => "const", + ItemKind::Fn(..) => "fn", + ItemKind::Mod(..) => "mod", + ItemKind::ForeignMod(..) => "foreign mod", + ItemKind::GlobalAsm(..) => "global asm", + ItemKind::Ty(..) => "ty", + ItemKind::Existential(..) => "existential", + ItemKind::Enum(..) => "enum", + ItemKind::Struct(..) => "struct", + ItemKind::Union(..) => "union", + ItemKind::Trait(..) => "trait", + ItemKind::TraitAlias(..) => "trait alias", + ItemKind::Impl(..) => "impl", }; format!("{} {}{}", item_str, path_str(), id_str) } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index bf83fa15727d1..c1a885d80bf8b 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -10,18 +10,11 @@ // The Rust HIR. -pub use self::BinOp_::*; pub use self::BlockCheckMode::*; pub use self::CaptureClause::*; -pub use self::Decl_::*; -pub use self::Expr_::*; pub use self::FunctionRetTy::*; -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::*; @@ -443,7 +436,7 @@ impl GenericArgs { match arg { GenericArg::Lifetime(_) => {} GenericArg::Type(ref ty) => { - if let TyTup(ref tys) = ty.node { + if let TyKind::Tup(ref tys) = ty.node { return tys; } break; @@ -941,98 +934,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 +1040,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 { @@ -1098,9 +1096,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()); @@ -1112,31 +1110,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, } } } @@ -1155,27 +1153,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, } } @@ -1283,7 +1281,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, } @@ -1291,34 +1289,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, } } } @@ -1331,18 +1329,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 @@ -1352,83 +1350,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