From 589dabda2f212d8ae231ed6aab2bbf851eaed90c Mon Sep 17 00:00:00 2001 From: Kamal Marhubi Date: Tue, 1 Mar 2016 17:27:19 -0500 Subject: [PATCH] deps: Update syntex_syntax to 0.29.1 --- Cargo.lock | 4 +- Cargo.toml | 2 +- src/chains.rs | 42 +++++++------- src/expr.rs | 145 ++++++++++++++++++++++++------------------------ src/imports.rs | 10 ++-- src/items.rs | 47 ++++++++-------- src/lib.rs | 34 +++++++++--- src/modules.rs | 2 +- src/patterns.rs | 31 ++++++----- src/types.rs | 48 ++++++++-------- src/utils.rs | 28 +++++----- src/visitor.rs | 50 ++++++++--------- 12 files changed, 230 insertions(+), 213 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40b04c3ef16..9ebeff7bb25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,7 +9,7 @@ dependencies = [ "regex 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "strings 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "syntex_syntax 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex_syntax 0.29.1 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -108,7 +108,7 @@ dependencies = [ [[package]] name = "syntex_syntax" -version = "0.23.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 94ff9ce1ec6..49bd30a73ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ regex = "0.1.41" term = "0.2.11" strings = "0.0.1" diff = "0.1.8" -syntex_syntax = "0.23.0" +syntex_syntax = "0.29.1" log = "0.3.2" env_logger = "0.3.1" getopts = "0.2" diff --git a/src/chains.rs b/src/chains.rs index 12f879eb59c..191b4a2ea4c 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -94,7 +94,7 @@ pub fn rewrite_chain(mut expr: &ast::Expr, let fits_single_line = !veto_single_line && match subexpr_list[0].node { - ast::Expr_::ExprMethodCall(ref method_name, ref types, ref expressions) + ast::ExprKind::MethodCall(ref method_name, ref types, ref expressions) if context.config.chains_overflow_last => { let len = rewrites.len(); let (init, last) = rewrites.split_at_mut(len - 1); @@ -150,28 +150,28 @@ pub fn rewrite_chain(mut expr: &ast::Expr, // parens, braces and brackets in its idiomatic formatting. fn is_block_expr(expr: &ast::Expr, repr: &str) -> bool { match expr.node { - ast::Expr_::ExprStruct(..) | - ast::Expr_::ExprWhile(..) | - ast::Expr_::ExprWhileLet(..) | - ast::Expr_::ExprIf(..) | - ast::Expr_::ExprIfLet(..) | - ast::Expr_::ExprBlock(..) | - ast::Expr_::ExprLoop(..) | - ast::Expr_::ExprForLoop(..) | - ast::Expr_::ExprMatch(..) => repr.contains('\n'), - ast::Expr_::ExprParen(ref expr) | - ast::Expr_::ExprBinary(_, _, ref expr) | - ast::Expr_::ExprIndex(_, ref expr) | - ast::Expr_::ExprUnary(_, ref expr) => is_block_expr(expr, repr), + ast::ExprKind::Struct(..) | + ast::ExprKind::While(..) | + ast::ExprKind::WhileLet(..) | + ast::ExprKind::If(..) | + ast::ExprKind::IfLet(..) | + ast::ExprKind::Block(..) | + ast::ExprKind::Loop(..) | + ast::ExprKind::ForLoop(..) | + ast::ExprKind::Match(..) => repr.contains('\n'), + ast::ExprKind::Paren(ref expr) | + ast::ExprKind::Binary(_, _, ref expr) | + ast::ExprKind::Index(_, ref expr) | + ast::ExprKind::Unary(_, ref expr) => is_block_expr(expr, repr), _ => false, } } fn pop_expr_chain(expr: &ast::Expr) -> Option<&ast::Expr> { match expr.node { - ast::Expr_::ExprMethodCall(_, _, ref expressions) => Some(&expressions[0]), - ast::Expr_::ExprTupField(ref subexpr, _) | - ast::Expr_::ExprField(ref subexpr, _) => Some(subexpr), + ast::ExprKind::MethodCall(_, _, ref expressions) => Some(&expressions[0]), + ast::ExprKind::TupField(ref subexpr, _) | + ast::ExprKind::Field(ref subexpr, _) => Some(subexpr), _ => None, } } @@ -183,7 +183,7 @@ fn rewrite_chain_expr(expr: &ast::Expr, offset: Indent) -> Option { match expr.node { - ast::Expr_::ExprMethodCall(ref method_name, ref types, ref expressions) => { + ast::ExprKind::MethodCall(ref method_name, ref types, ref expressions) => { let inner = &RewriteContext { block_indent: offset, ..*context }; rewrite_method_call(method_name.node, types, @@ -193,7 +193,7 @@ fn rewrite_chain_expr(expr: &ast::Expr, width, offset) } - ast::Expr_::ExprField(_, ref field) => { + ast::ExprKind::Field(_, ref field) => { let s = format!(".{}", field.node); if s.len() <= width { Some(s) @@ -201,7 +201,7 @@ fn rewrite_chain_expr(expr: &ast::Expr, None } } - ast::Expr_::ExprTupField(_, ref field) => { + ast::ExprKind::TupField(_, ref field) => { let s = format!(".{}", field.node); if s.len() <= width { Some(s) @@ -216,7 +216,7 @@ fn rewrite_chain_expr(expr: &ast::Expr, // Determines we can continue formatting a given expression on the same line. fn is_continuable(expr: &ast::Expr) -> bool { match expr.node { - ast::Expr_::ExprPath(..) => true, + ast::ExprKind::Path(..) => true, _ => false, } } diff --git a/src/expr.rs b/src/expr.rs index 34a30e94899..6409ab8fdac 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -37,16 +37,16 @@ use syntax::visit::Visitor; impl Rewrite for ast::Expr { fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option { let result = match self.node { - ast::Expr_::ExprVec(ref expr_vec) => { + ast::ExprKind::Vec(ref expr_vec) => { rewrite_array(expr_vec.iter().map(|e| &**e), mk_sp(span_after(self.span, "[", context.codemap), self.span.hi), context, width, offset) } - ast::Expr_::ExprLit(ref l) => { + ast::ExprKind::Lit(ref l) => { match l.node { - ast::Lit_::LitStr(_, ast::StrStyle::CookedStr) => { + ast::LitKind::Str(_, ast::StrStyle::Cooked) => { rewrite_string_lit(context, l.span, width, offset) } _ => { @@ -57,18 +57,18 @@ impl Rewrite for ast::Expr { } } } - ast::Expr_::ExprCall(ref callee, ref args) => { + ast::ExprKind::Call(ref callee, ref args) => { let inner_span = mk_sp(callee.span.hi, self.span.hi); rewrite_call(context, &**callee, args, inner_span, width, offset) } - ast::Expr_::ExprParen(ref subexpr) => rewrite_paren(context, subexpr, width, offset), - ast::Expr_::ExprBinary(ref op, ref lhs, ref rhs) => { + ast::ExprKind::Paren(ref subexpr) => rewrite_paren(context, subexpr, width, offset), + ast::ExprKind::Binary(ref op, ref lhs, ref rhs) => { rewrite_binary_op(context, op, lhs, rhs, width, offset) } - ast::Expr_::ExprUnary(ref op, ref subexpr) => { + ast::ExprKind::Unary(ref op, ref subexpr) => { rewrite_unary_op(context, op, subexpr, width, offset) } - ast::Expr_::ExprStruct(ref path, ref fields, ref base) => { + ast::ExprKind::Struct(ref path, ref fields, ref base) => { rewrite_struct_lit(context, path, fields, @@ -77,27 +77,27 @@ impl Rewrite for ast::Expr { width, offset) } - ast::Expr_::ExprTup(ref items) => { + ast::ExprKind::Tup(ref items) => { rewrite_tuple(context, items.iter().map(|x| &**x), self.span, width, offset) } - ast::Expr_::ExprWhile(ref cond, ref block, label) => { + ast::ExprKind::While(ref cond, ref block, label) => { Loop::new_while(None, cond, block, label).rewrite(context, width, offset) } - ast::Expr_::ExprWhileLet(ref pat, ref cond, ref block, label) => { + ast::ExprKind::WhileLet(ref pat, ref cond, ref block, label) => { Loop::new_while(Some(pat), cond, block, label).rewrite(context, width, offset) } - ast::Expr_::ExprForLoop(ref pat, ref cond, ref block, label) => { + ast::ExprKind::ForLoop(ref pat, ref cond, ref block, label) => { Loop::new_for(pat, cond, block, label).rewrite(context, width, offset) } - ast::Expr_::ExprLoop(ref block, label) => { + ast::ExprKind::Loop(ref block, label) => { Loop::new_loop(block, label).rewrite(context, width, offset) } - ast::Expr_::ExprBlock(ref block) => block.rewrite(context, width, offset), - ast::Expr_::ExprIf(ref cond, ref if_block, ref else_block) => { + ast::ExprKind::Block(ref block) => block.rewrite(context, width, offset), + ast::ExprKind::If(ref cond, ref if_block, ref else_block) => { rewrite_if_else(context, cond, if_block, @@ -108,7 +108,7 @@ impl Rewrite for ast::Expr { offset, true) } - ast::Expr_::ExprIfLet(ref pat, ref cond, ref if_block, ref else_block) => { + ast::ExprKind::IfLet(ref pat, ref cond, ref if_block, ref else_block) => { rewrite_if_else(context, cond, if_block, @@ -119,39 +119,39 @@ impl Rewrite for ast::Expr { offset, true) } - ast::Expr_::ExprMatch(ref cond, ref arms) => { + ast::ExprKind::Match(ref cond, ref arms) => { rewrite_match(context, cond, arms, width, offset, self.span) } - ast::Expr_::ExprPath(ref qself, ref path) => { + ast::ExprKind::Path(ref qself, ref path) => { rewrite_path(context, true, qself.as_ref(), path, width, offset) } - ast::Expr_::ExprAssign(ref lhs, ref rhs) => { + ast::ExprKind::Assign(ref lhs, ref rhs) => { rewrite_assignment(context, lhs, rhs, None, width, offset) } - ast::Expr_::ExprAssignOp(ref op, ref lhs, ref rhs) => { + ast::ExprKind::AssignOp(ref op, ref lhs, ref rhs) => { rewrite_assignment(context, lhs, rhs, Some(op), width, offset) } - ast::Expr_::ExprAgain(ref opt_ident) => { + ast::ExprKind::Again(ref opt_ident) => { let id_str = match *opt_ident { Some(ident) => format!(" {}", ident.node), None => String::new(), }; Some(format!("continue{}", id_str)) } - ast::Expr_::ExprBreak(ref opt_ident) => { + ast::ExprKind::Break(ref opt_ident) => { let id_str = match *opt_ident { Some(ident) => format!(" {}", ident.node), None => String::new(), }; Some(format!("break{}", id_str)) } - ast::Expr_::ExprClosure(capture, ref fn_decl, ref body) => { + ast::ExprKind::Closure(capture, ref fn_decl, ref body) => { rewrite_closure(capture, fn_decl, body, self.span, context, width, offset) } - ast::Expr_::ExprField(..) | - ast::Expr_::ExprTupField(..) | - ast::Expr_::ExprMethodCall(..) => rewrite_chain(self, context, width, offset), - ast::Expr_::ExprMac(ref mac) => { + ast::ExprKind::Field(..) | + ast::ExprKind::TupField(..) | + ast::ExprKind::MethodCall(..) => rewrite_chain(self, context, width, offset), + ast::ExprKind::Mac(ref mac) => { // Failure to rewrite a marco should not imply failure to // rewrite the expression. rewrite_macro(mac, context, width, offset).or_else(|| { @@ -161,40 +161,43 @@ impl Rewrite for ast::Expr { offset) }) } - ast::Expr_::ExprRet(None) => { + ast::ExprKind::Ret(None) => { wrap_str("return".to_owned(), context.config.max_width, width, offset) } - ast::Expr_::ExprRet(Some(ref expr)) => { + ast::ExprKind::Ret(Some(ref expr)) => { rewrite_unary_prefix(context, "return ", &**expr, width, offset) } - ast::Expr_::ExprBox(ref expr) => { + ast::ExprKind::Box(ref expr) => { rewrite_unary_prefix(context, "box ", &**expr, width, offset) } - ast::Expr_::ExprAddrOf(mutability, ref expr) => { + ast::ExprKind::AddrOf(mutability, ref expr) => { rewrite_expr_addrof(context, mutability, expr, width, offset) } - ast::Expr_::ExprCast(ref expr, ref ty) => { + ast::ExprKind::Cast(ref expr, ref ty) => { rewrite_pair(&**expr, &**ty, "", " as ", "", context, width, offset) } - ast::Expr_::ExprIndex(ref expr, ref index) => { + // TODO(#848): Handle type ascription; rust tracking issue + // https://github.com/rust-lang/rust/issues/23416 + ast::ExprKind::Type(_, _) => unimplemented!(), + ast::ExprKind::Index(ref expr, ref index) => { rewrite_pair(&**expr, &**index, "", "[", "]", context, width, offset) } - ast::Expr_::ExprRepeat(ref expr, ref repeats) => { + ast::ExprKind::Repeat(ref expr, ref repeats) => { rewrite_pair(&**expr, &**repeats, "[", "; ", "]", context, width, offset) } - ast::Expr_::ExprRange(Some(ref lhs), Some(ref rhs)) => { + ast::ExprKind::Range(Some(ref lhs), Some(ref rhs)) => { rewrite_pair(&**lhs, &**rhs, "", "..", "", context, width, offset) } - ast::Expr_::ExprRange(None, Some(ref rhs)) => { + ast::ExprKind::Range(None, Some(ref rhs)) => { rewrite_unary_prefix(context, "..", &**rhs, width, offset) } - ast::Expr_::ExprRange(Some(ref lhs), None) => { + ast::ExprKind::Range(Some(ref lhs), None) => { Some(format!("{}..", try_opt!(lhs.rewrite(context, try_opt!(width.checked_sub(2)), offset)))) } - ast::Expr_::ExprRange(None, None) => { + ast::ExprKind::Range(None, None) => { if width >= 2 { Some("..".into()) } else { @@ -203,8 +206,8 @@ impl Rewrite for ast::Expr { } // We do not format these expressions yet, but they should still // satisfy our width restrictions. - ast::Expr_::ExprInPlace(..) | - ast::Expr_::ExprInlineAsm(..) => { + ast::ExprKind::InPlace(..) | + ast::ExprKind::InlineAsm(..) => { wrap_str(context.snippet(self.span), context.config.max_width, width, @@ -302,7 +305,7 @@ pub fn rewrite_array<'a, I>(expr_iter: I, // This functions is pretty messy because of the wrapping and unwrapping of // expressions into and from blocks. See rust issue #27872. -fn rewrite_closure(capture: ast::CaptureClause, +fn rewrite_closure(capture: ast::CaptureBy, fn_decl: &ast::FnDecl, body: &ast::Block, span: Span, @@ -310,7 +313,7 @@ fn rewrite_closure(capture: ast::CaptureClause, width: usize, offset: Indent) -> Option { - let mover = if capture == ast::CaptureClause::CaptureByValue { + let mover = if capture == ast::CaptureBy::Value { "move " } else { "" @@ -374,9 +377,8 @@ fn rewrite_closure(capture: ast::CaptureClause, // All closure bodies are blocks in the eyes of the AST, but we may not // want to unwrap them when they only contain a single expression. let inner_expr = match expr.node { - ast::Expr_::ExprBlock(ref inner) if inner.stmts.is_empty() && inner.expr.is_some() && - inner.rules == - ast::BlockCheckMode::DefaultBlock => { + ast::ExprKind::Block(ref inner) if inner.stmts.is_empty() && inner.expr.is_some() && + inner.rules == ast::BlockCheckMode::Default => { inner.expr.as_ref().unwrap() } _ => expr, @@ -398,7 +400,7 @@ fn rewrite_closure(capture: ast::CaptureClause, let body_rewrite = body.expr .as_ref() .and_then(|body_expr| { - if let ast::Expr_::ExprBlock(ref inner) = body_expr.node { + if let ast::ExprKind::Block(ref inner) = body_expr.node { Some(inner.rewrite(&context, 2, Indent::empty())) } else { None @@ -431,7 +433,7 @@ impl Rewrite for ast::Block { visitor.block_indent = context.block_indent; let prefix = match self.rules { - ast::BlockCheckMode::UnsafeBlock(..) => { + ast::BlockCheckMode::Unsafe(..) => { let snippet = context.snippet(self.span); let open_pos = try_opt!(snippet.find_uncommented("{")); visitor.last_pos = self.span.lo + BytePos(open_pos as u32); @@ -467,7 +469,7 @@ impl Rewrite for ast::Block { prefix } - ast::BlockCheckMode::DefaultBlock => { + ast::BlockCheckMode::Default => { visitor.last_pos = self.span.lo; String::new() @@ -483,14 +485,14 @@ impl Rewrite for ast::Block { impl Rewrite for ast::Stmt { fn rewrite(&self, context: &RewriteContext, _width: usize, offset: Indent) -> Option { let result = match self.node { - ast::Stmt_::StmtDecl(ref decl, _) => { - if let ast::Decl_::DeclLocal(ref local) = decl.node { + ast::StmtKind::Decl(ref decl, _) => { + if let ast::DeclKind::Local(ref local) = decl.node { local.rewrite(context, context.config.max_width, offset) } else { None } } - ast::Stmt_::StmtExpr(ref ex, _) | ast::Stmt_::StmtSemi(ref ex, _) => { + ast::StmtKind::Expr(ref ex, _) | ast::StmtKind::Semi(ref ex, _) => { let suffix = if semicolon_for_stmt(self) { ";" } else { @@ -502,7 +504,7 @@ impl Rewrite for ast::Stmt { offset) .map(|s| s + suffix) } - ast::Stmt_::StmtMac(..) => None, + ast::StmtKind::Mac(..) => None, }; result.and_then(|res| recover_comment_removed(res, self.span, context, _width, offset)) } @@ -681,7 +683,7 @@ fn rewrite_if_else(context: &RewriteContext, let rewrite = match else_block.node { // If the else expression is another if-else expression, prevent it // from being formatted on a single line. - ast::Expr_::ExprIfLet(ref pat, ref cond, ref if_block, ref next_else_block) => { + ast::ExprKind::IfLet(ref pat, ref cond, ref if_block, ref next_else_block) => { rewrite_if_else(context, cond, if_block, @@ -692,7 +694,7 @@ fn rewrite_if_else(context: &RewriteContext, offset, false) } - ast::Expr_::ExprIf(ref cond, ref if_block, ref next_else_block) => { + ast::ExprKind::If(ref cond, ref if_block, ref next_else_block) => { rewrite_if_else(context, cond, if_block, @@ -741,7 +743,7 @@ fn single_line_if_else(context: &RewriteContext, let else_block = try_opt!(else_block_opt); let fixed_cost = "if { } else { }".len(); - if let ast::ExprBlock(ref else_node) = else_block.node { + if let ast::ExprKind::Block(ref else_node) = else_block.node { if !is_simple_block(if_node, context.codemap) || !is_simple_block(else_node, context.codemap) || pat_expr_str.contains('\n') { return None; @@ -794,7 +796,7 @@ pub fn is_empty_block(block: &ast::Block, codemap: &CodeMap) -> bool { } fn is_unsafe_block(block: &ast::Block) -> bool { - if let ast::BlockCheckMode::UnsafeBlock(..) = block.rules { + if let ast::BlockCheckMode::Unsafe(..) = block.rules { true } else { false @@ -925,15 +927,15 @@ fn arm_end_pos(arm: &ast::Arm) -> BytePos { fn arm_comma(config: &Config, arm: &ast::Arm, body: &ast::Expr) -> &'static str { if !config.match_wildcard_trailing_comma { - if arm.pats.len() == 1 && arm.pats[0].node == ast::PatWild && arm.guard.is_none() { + if arm.pats.len() == 1 && arm.pats[0].node == ast::PatKind::Wild && arm.guard.is_none() { return ""; } } if config.match_block_trailing_comma { "," - } else if let ast::ExprBlock(ref block) = body.node { - if let ast::DefaultBlock = block.rules { + } else if let ast::ExprKind::Block(ref block) = body.node { + if let ast::BlockCheckMode::Default = block.rules { "" } else { "," @@ -1015,12 +1017,9 @@ impl Rewrite for ast::Arm { } let body = match **body { - ast::Expr { node: ast::ExprBlock(ref block), .. } if !is_unsafe_block(block) && - is_simple_block(block, - context.codemap) && - context.config.wrap_match_arms => { - block.expr.as_ref().map(|e| &**e).unwrap() - } + ast::Expr { node: ast::ExprKind::Block(ref block), .. } + if !is_unsafe_block(block) && is_simple_block(block, context.codemap) && + context.config.wrap_match_arms => block.expr.as_ref().map(|e| &**e).unwrap(), ref x => x, }; @@ -1032,7 +1031,7 @@ impl Rewrite for ast::Arm { let budget = context.config.max_width - line_start - comma.len() - 4; let offset = Indent::new(offset.block_indent, line_start + 4 - offset.block_indent); let rewrite = nop_block_collapse(body.rewrite(context, budget, offset), budget); - let is_block = if let ast::ExprBlock(..) = body.node { + let is_block = if let ast::ExprKind::Block(..) = body.node { true } else { false @@ -1307,8 +1306,8 @@ fn rewrite_call_inner(context: &RewriteContext, // indentation. If its first line fits on one line with the other arguments, // we format the function arguments horizontally. let overflow_last = match args.last().map(|x| &x.node) { - Some(&ast::Expr_::ExprClosure(..)) | - Some(&ast::Expr_::ExprBlock(..)) if arg_count > 1 => true, + Some(&ast::ExprKind::Closure(..)) | + Some(&ast::ExprKind::Block(..)) if arg_count > 1 => true, _ => false, } && context.config.chains_overflow_last; @@ -1666,9 +1665,9 @@ fn rewrite_unary_op(context: &RewriteContext, -> Option { // For some reason, an UnOp is not spanned like BinOp! let operator_str = match *op { - ast::UnOp::UnDeref => "*", - ast::UnOp::UnNot => "!", - ast::UnOp::UnNeg => "-", + ast::UnOp::Deref => "*", + ast::UnOp::Not => "!", + ast::UnOp::Neg => "-", }; rewrite_unary_prefix(context, operator_str, expr, width, offset) } @@ -1744,8 +1743,8 @@ fn rewrite_expr_addrof(context: &RewriteContext, offset: Indent) -> Option { let operator_str = match mutability { - ast::Mutability::MutImmutable => "&", - ast::Mutability::MutMutable => "&mut ", + ast::Mutability::Immutable => "&", + ast::Mutability::Mutable => "&mut ", }; rewrite_unary_prefix(context, operator_str, expr, width, offset) } diff --git a/src/imports.rs b/src/imports.rs index 70351ca8d79..38720d84cce 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -51,7 +51,7 @@ impl Rewrite for ast::ViewPath { } fn rewrite_single_use_list(path_str: String, vpi: &ast::PathListItem) -> String { - let path_item_str = if let ast::PathListItem_::PathListIdent { name, .. } = vpi.node { + let path_item_str = if let ast::PathListItemKind::Ident { name, .. } = vpi.node { // A name. if path_str.is_empty() { name.to_string() @@ -74,8 +74,8 @@ fn rewrite_single_use_list(path_str: String, vpi: &ast::PathListItem) -> String fn rewrite_path_item(vpi: &&ast::PathListItem) -> Option { let path_item_str = match vpi.node { - ast::PathListItem_::PathListIdent { name, .. } => name.to_string(), - ast::PathListItem_::PathListMod { .. } => "self".to_owned(), + ast::PathListItemKind::Ident { name, .. } => name.to_string(), + ast::PathListItemKind::Mod { .. } => "self".to_owned(), }; Some(append_alias(path_item_str, vpi)) @@ -83,8 +83,8 @@ fn rewrite_path_item(vpi: &&ast::PathListItem) -> Option { fn append_alias(path_item_str: String, vpi: &ast::PathListItem) -> String { match vpi.node { - ast::PathListItem_::PathListIdent { rename: Some(rename), .. } | - ast::PathListItem_::PathListMod { rename: Some(rename), .. } => { + ast::PathListItemKind::Ident { rename: Some(rename), .. } | + ast::PathListItemKind::Mod { rename: Some(rename), .. } => { format!("{} as {}", path_item_str, rename) } _ => path_item_str, diff --git a/src/items.rs b/src/items.rs index d7c16c4561c..c013733f37f 100644 --- a/src/items.rs +++ b/src/items.rs @@ -27,7 +27,6 @@ use syntax::{ast, abi}; use syntax::codemap::{Span, BytePos, mk_sp}; use syntax::parse::token; use syntax::ast::ImplItem; -use syntax::ptr::P; // Statements of the form // let pat: ty = init; @@ -110,7 +109,7 @@ impl<'a> FmtVisitor<'a> { let span = mk_sp(item.span.lo, item.span.hi - BytePos(1)); match item.node { - ast::ForeignItem_::ForeignItemFn(ref fn_decl, ref generics) => { + ast::ForeignItemKind::Fn(ref fn_decl, ref generics) => { let indent = self.block_indent; let rewrite = rewrite_fn_base(&self.get_context(), indent, @@ -136,7 +135,7 @@ impl<'a> FmtVisitor<'a> { None => self.format_missing(item.span.hi), } } - ast::ForeignItem_::ForeignItemStatic(ref ty, is_mutable) => { + ast::ForeignItemKind::Static(ref ty, is_mutable) => { // FIXME(#21): we're dropping potential comments in between the // function keywords here. let mut_str = if is_mutable { @@ -441,12 +440,12 @@ impl<'a> FmtVisitor<'a> { } pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -> Option { - if let ast::Item_::ItemImpl(unsafety, - polarity, - ref generics, - ref trait_ref, - ref self_ty, - ref items) = item.node { + if let ast::ItemKind::Impl(unsafety, + polarity, + ref generics, + ref trait_ref, + ref self_ty, + ref items) = item.node { let mut result = String::new(); result.push_str(format_visibility(item.vis)); result.push_str(format_unsafety(unsafety)); @@ -562,7 +561,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) - } fn is_impl_single_line(context: &RewriteContext, - items: &Vec>, + items: &Vec, result: &str, where_clause_str: &str, item: &ast::Item) @@ -919,15 +918,15 @@ pub fn rewrite_static(prefix: &str, impl Rewrite for ast::FunctionRetTy { fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option { match *self { - ast::FunctionRetTy::DefaultReturn(_) => Some(String::new()), - ast::FunctionRetTy::NoReturn(_) => { + ast::FunctionRetTy::Default(_) => Some(String::new()), + ast::FunctionRetTy::None(_) => { if width >= 4 { Some("-> !".to_owned()) } else { None } } - ast::FunctionRetTy::Return(ref ty) => { + ast::FunctionRetTy::Ty(ref ty) => { let inner_width = try_opt!(width.checked_sub(3)); ty.rewrite(context, inner_width, offset + 3).map(|r| format!("-> {}", r)) } @@ -940,7 +939,7 @@ impl Rewrite for ast::Arg { if is_named_arg(self) { let mut result = try_opt!(self.pat.rewrite(context, width, offset)); - if self.ty.node != ast::Ty_::TyInfer { + if self.ty.node != ast::TyKind::Infer { result.push_str(": "); let max_width = try_opt!(width.checked_sub(result.len())); let ty_str = try_opt!(self.ty.rewrite(context, max_width, offset + result.len())); @@ -959,7 +958,7 @@ fn rewrite_explicit_self(explicit_self: &ast::ExplicitSelf, context: &RewriteContext) -> Option { match explicit_self.node { - ast::ExplicitSelf_::SelfRegion(lt, m, _) => { + ast::SelfKind::Region(lt, m, _) => { let mut_str = format_mutability(m); match lt { Some(ref l) => { @@ -971,7 +970,7 @@ fn rewrite_explicit_self(explicit_self: &ast::ExplicitSelf, None => Some(format!("&{}self", mut_str)), } } - ast::ExplicitSelf_::SelfExplicit(ref ty, _) => { + ast::SelfKind::Explicit(ref ty, _) => { assert!(!args.is_empty(), "&[ast::Arg] shouldn't be empty."); let mutability = explicit_self_mutability(&args[0]); @@ -979,7 +978,7 @@ fn rewrite_explicit_self(explicit_self: &ast::ExplicitSelf, Some(format!("{}self: {}", format_mutability(mutability), type_str)) } - ast::ExplicitSelf_::SelfValue(_) => { + ast::SelfKind::Value(_) => { assert!(!args.is_empty(), "&[ast::Arg] shouldn't be empty."); let mutability = explicit_self_mutability(&args[0]); @@ -993,7 +992,7 @@ fn rewrite_explicit_self(explicit_self: &ast::ExplicitSelf, // Hacky solution caused by absence of `Mutability` in `SelfValue` and // `SelfExplicit` variants of `ast::ExplicitSelf_`. fn explicit_self_mutability(arg: &ast::Arg) -> ast::Mutability { - if let ast::Pat_::PatIdent(ast::BindingMode::BindByValue(mutability), _, _) = arg.pat.node { + if let ast::PatKind::Ident(ast::BindingMode::ByValue(mutability), _, _) = arg.pat.node { mutability } else { unreachable!() @@ -1010,13 +1009,13 @@ pub fn span_lo_for_arg(arg: &ast::Arg) -> BytePos { pub fn span_hi_for_arg(arg: &ast::Arg) -> BytePos { match arg.ty.node { - ast::Ty_::TyInfer if is_named_arg(arg) => arg.pat.span.hi, + ast::TyKind::Infer if is_named_arg(arg) => arg.pat.span.hi, _ => arg.ty.span.hi, } } pub fn is_named_arg(arg: &ast::Arg) -> bool { - if let ast::Pat_::PatIdent(_, ident, _) = arg.pat.node { + if let ast::PatKind::Ident(_, ident, _) = arg.pat.node { ident.node != token::special_idents::invalid } else { true @@ -1025,9 +1024,9 @@ pub fn is_named_arg(arg: &ast::Arg) -> bool { fn span_for_return(ret: &ast::FunctionRetTy) -> Span { match *ret { - ast::FunctionRetTy::NoReturn(ref span) | - ast::FunctionRetTy::DefaultReturn(ref span) => span.clone(), - ast::FunctionRetTy::Return(ref ty) => ty.span, + ast::FunctionRetTy::None(ref span) | + ast::FunctionRetTy::Default(ref span) => span.clone(), + ast::FunctionRetTy::Ty(ref ty) => ty.span, } } @@ -1085,7 +1084,7 @@ fn rewrite_fn_base(context: &RewriteContext, result.push_str("const "); } - if abi != abi::Rust { + if abi != abi::Abi::Rust { result.push_str(&::utils::format_abi(abi)); } diff --git a/src/lib.rs b/src/lib.rs index ee671cf0baa..7e074f05124 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,13 +26,15 @@ extern crate diff; extern crate term; use syntax::ast; -use syntax::codemap::{mk_sp, Span}; -use syntax::diagnostic::{EmitterWriter, Handler}; +use syntax::codemap::{mk_sp, CodeMap, Span}; +use syntax::errors::Handler; +use syntax::errors::emitter::{ColorConfig, EmitterWriter}; use syntax::parse::{self, ParseSess}; use std::io::stdout; use std::ops::{Add, Sub}; use std::path::Path; +use std::rc::Rc; use std::collections::HashMap; use std::fmt; @@ -367,15 +369,23 @@ pub fn fmt_lines(file_map: &mut FileMap, config: &Config) -> FormatReport { pub fn format_string(input: String, config: &Config) -> FileMap { let path = "stdin"; - let mut parse_session = ParseSess::new(); + let codemap = Rc::new(CodeMap::new()); + + let tty_handler = Handler::with_tty_emitter(ColorConfig::Auto, + None, + true, + false, + codemap.clone()); + let mut parse_session = ParseSess::with_span_handler(tty_handler, codemap.clone()); + let krate = parse::parse_crate_from_source_str(path.to_owned(), input, Vec::new(), &parse_session); // Suppress error output after parsing. - let emitter = Box::new(EmitterWriter::new(Box::new(Vec::new()), None)); - parse_session.span_diagnostic.handler = Handler::with_emitter(false, emitter); + let silent_emitter = Box::new(EmitterWriter::new(Box::new(Vec::new()), None, codemap.clone())); + parse_session.span_diagnostic = Handler::with_emitter(true, false, silent_emitter); // FIXME: we still use a FileMap even though we only have // one file, because fmt_lines requires a FileMap @@ -393,12 +403,20 @@ pub fn format_string(input: String, config: &Config) -> FileMap { } pub fn format(file: &Path, config: &Config) -> FileMap { - let mut parse_session = ParseSess::new(); + let codemap = Rc::new(CodeMap::new()); + + let tty_handler = Handler::with_tty_emitter(ColorConfig::Auto, + None, + true, + false, + codemap.clone()); + let mut parse_session = ParseSess::with_span_handler(tty_handler, codemap.clone()); + let krate = parse::parse_crate_from_file(file, Vec::new(), &parse_session); // Suppress error output after parsing. - let emitter = Box::new(EmitterWriter::new(Box::new(Vec::new()), None)); - parse_session.span_diagnostic.handler = Handler::with_emitter(false, emitter); + let silent_emitter = Box::new(EmitterWriter::new(Box::new(Vec::new()), None, codemap.clone())); + parse_session.span_diagnostic = Handler::with_emitter(true, false, silent_emitter); let mut file_map = fmt_ast(&krate, &parse_session, file, config); diff --git a/src/modules.rs b/src/modules.rs index 3f96bea9d44..e56fa57ac7b 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -40,7 +40,7 @@ fn list_submodules<'a>(module: &'a ast::Mod, result: &mut HashMap) { debug!("list_submodules: search_dir: {:?}", search_dir); for item in &module.items { - if let ast::ItemMod(ref sub_mod) = item.node { + if let ast::ItemKind::Mod(ref sub_mod) = item.node { if !utils::contains_skip(&item.attrs) { let is_internal = codemap.span_to_filename(item.span) == codemap.span_to_filename(sub_mod.inner); diff --git a/src/patterns.rs b/src/patterns.rs index a5f09823212..a761ad538f5 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -15,16 +15,16 @@ use lists::{format_item_list, itemize_list}; use expr::{rewrite_unary_prefix, rewrite_pair, rewrite_tuple}; use types::rewrite_path; -use syntax::ast::{BindingMode, Pat, Pat_, FieldPat}; +use syntax::ast::{BindingMode, Pat, PatKind, FieldPat}; impl Rewrite for Pat { fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option { match self.node { - Pat_::PatBox(ref pat) => rewrite_unary_prefix(context, "box ", &**pat, width, offset), - Pat_::PatIdent(binding_mode, ident, ref sub_pat) => { + PatKind::Box(ref pat) => rewrite_unary_prefix(context, "box ", &**pat, width, offset), + PatKind::Ident(binding_mode, ident, ref sub_pat) => { let (prefix, mutability) = match binding_mode { - BindingMode::BindByRef(mutability) => ("ref ", mutability), - BindingMode::BindByValue(mutability) => ("", mutability), + BindingMode::ByRef(mutability) => ("ref ", mutability), + BindingMode::ByValue(mutability) => ("", mutability), }; let mut_infix = format_mutability(mutability); let id_str = ident.node.to_string(); @@ -43,31 +43,32 @@ impl Rewrite for Pat { let result = format!("{}{}{}{}", prefix, mut_infix, id_str, sub_pat); wrap_str(result, context.config.max_width, width, offset) } - Pat_::PatWild => { + PatKind::Wild => { if 1 <= width { Some("_".to_owned()) } else { None } } - Pat_::PatQPath(ref q_self, ref path) => { + PatKind::QPath(ref q_self, ref path) => { rewrite_path(context, true, Some(q_self), path, width, offset) } - Pat_::PatRange(ref lhs, ref rhs) => { + PatKind::Range(ref lhs, ref rhs) => { rewrite_pair(&**lhs, &**rhs, "", "...", "", context, width, offset) } - Pat_::PatRegion(ref pat, mutability) => { + PatKind::Ref(ref pat, mutability) => { let prefix = format!("&{}", format_mutability(mutability)); rewrite_unary_prefix(context, &prefix, &**pat, width, offset) } - Pat_::PatTup(ref items) => { + PatKind::Tup(ref items) => { rewrite_tuple(context, items.iter().map(|x| &**x), self.span, width, offset) } - Pat_::PatEnum(ref path, ref pat_vec) => { + PatKind::Path(ref path) => rewrite_path(context, true, None, path, width, offset), + PatKind::TupleStruct(ref path, ref pat_vec) => { let path_str = try_opt!(rewrite_path(context, true, None, path, width, offset)); match *pat_vec { @@ -97,8 +98,8 @@ impl Rewrite for Pat { None => Some(format!("{}(..)", path_str)), } } - Pat_::PatLit(ref expr) => expr.rewrite(context, width, offset), - Pat_::PatVec(ref prefix, ref slice_pat, ref suffix) => { + PatKind::Lit(ref expr) => expr.rewrite(context, width, offset), + PatKind::Vec(ref prefix, ref slice_pat, ref suffix) => { // Rewrite all the sub-patterns. let prefix = prefix.iter().map(|p| p.rewrite(context, width, offset)); let slice_pat = slice_pat.as_ref().map(|p| { @@ -118,7 +119,7 @@ impl Rewrite for Pat { let result = format!("[{}]", pats.join(", ")); wrap_str(result, context.config.max_width, width, offset) } - Pat_::PatStruct(ref path, ref fields, elipses) => { + PatKind::Struct(ref path, ref fields, elipses) => { let path = try_opt!(rewrite_path(context, true, None, path, width, offset)); let (elipses_str, terminator) = if elipses { @@ -167,7 +168,7 @@ impl Rewrite for Pat { } } // FIXME(#819) format pattern macros. - Pat_::PatMac(..) => { + PatKind::Mac(..) => { wrap_str(context.snippet(self.span), context.config.max_width, width, diff --git a/src/types.rs b/src/types.rs index 4f930f22cad..5a08e176618 100644 --- a/src/types.rs +++ b/src/types.rs @@ -172,9 +172,9 @@ fn rewrite_segment(expr_context: bool, let offset = offset + ident_len; let params = match segment.parameters { - ast::PathParameters::AngleBracketedParameters(ref data) if !data.lifetimes.is_empty() || - !data.types.is_empty() || - !data.bindings.is_empty() => { + ast::PathParameters::AngleBracketed(ref data) if !data.lifetimes.is_empty() || + !data.types.is_empty() || + !data.bindings.is_empty() => { let param_list = data.lifetimes .iter() .map(SegmentParam::LifeTime) @@ -213,10 +213,10 @@ fn rewrite_segment(expr_context: bool, format!("{}<{}>", separator, list_str) } - ast::PathParameters::ParenthesizedParameters(ref data) => { + ast::PathParameters::Parenthesized(ref data) => { let output = match data.output { - Some(ref ty) => FunctionRetTy::Return(ty.clone()), - None => FunctionRetTy::DefaultReturn(codemap::DUMMY_SP), + Some(ref ty) => FunctionRetTy::Ty(ty.clone()), + None => FunctionRetTy::Default(codemap::DUMMY_SP), }; try_opt!(format_function_type(data.inputs.iter().map(|x| &**x), &output, @@ -259,13 +259,13 @@ fn format_function_type<'a, I>(inputs: I, let list_str = try_opt!(format_fn_args(items, budget, offset, context.config)); let output = match *output { - FunctionRetTy::Return(ref ty) => { + FunctionRetTy::Ty(ref ty) => { let budget = try_opt!(width.checked_sub(4)); let type_str = try_opt!(ty.rewrite(context, budget, offset + 4)); format!(" -> {}", type_str) } - FunctionRetTy::NoReturn(..) => " -> !".to_owned(), - FunctionRetTy::DefaultReturn(..) => String::new(), + FunctionRetTy::None(..) => " -> !".to_owned(), + FunctionRetTy::Default(..) => String::new(), }; let infix = if output.len() + list_str.len() > width { @@ -470,7 +470,7 @@ impl Rewrite for ast::TraitRef { impl Rewrite for ast::Ty { fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option { match self.node { - ast::TyObjectSum(ref ty, ref bounds) => { + ast::TyKind::ObjectSum(ref ty, ref bounds) => { let ty_str = try_opt!(ty.rewrite(context, width, offset)); let overhead = ty_str.len() + 3; let plus_str = match context.config.type_punctuation_density { @@ -484,15 +484,15 @@ impl Rewrite for ast::Ty { try_opt!(width.checked_sub(overhead)), offset + overhead)))) } - ast::TyPtr(ref mt) => { + ast::TyKind::Ptr(ref mt) => { let prefix = match mt.mutbl { - Mutability::MutMutable => "*mut ", - Mutability::MutImmutable => "*const ", + Mutability::Mutable => "*mut ", + Mutability::Immutable => "*const ", }; rewrite_unary_prefix(context, prefix, &*mt.ty, width, offset) } - ast::TyRptr(ref lifetime, ref mt) => { + ast::TyKind::Rptr(ref lifetime, ref mt) => { let mut_str = format_mutability(mt.mutbl); let mut_len = mut_str.len(); Some(match *lifetime { @@ -520,39 +520,39 @@ impl Rewrite for ast::Ty { } // FIXME: we drop any comments here, even though it's a silly place to put // comments. - ast::TyParen(ref ty) => { + ast::TyKind::Paren(ref ty) => { let budget = try_opt!(width.checked_sub(2)); ty.rewrite(context, budget, offset + 1).map(|ty_str| format!("({})", ty_str)) } - ast::TyVec(ref ty) => { + ast::TyKind::Vec(ref ty) => { let budget = try_opt!(width.checked_sub(2)); ty.rewrite(context, budget, offset + 1).map(|ty_str| format!("[{}]", ty_str)) } - ast::TyTup(ref items) => { + ast::TyKind::Tup(ref items) => { rewrite_tuple(context, items.iter().map(|x| &**x), self.span, width, offset) } - ast::TyPolyTraitRef(ref trait_ref) => trait_ref.rewrite(context, width, offset), - ast::TyPath(ref q_self, ref path) => { + ast::TyKind::PolyTraitRef(ref trait_ref) => trait_ref.rewrite(context, width, offset), + ast::TyKind::Path(ref q_self, ref path) => { rewrite_path(context, false, q_self.as_ref(), path, width, offset) } - ast::TyFixedLengthVec(ref ty, ref repeats) => { + ast::TyKind::FixedLengthVec(ref ty, ref repeats) => { rewrite_pair(&**ty, &**repeats, "[", "; ", "]", context, width, offset) } - ast::TyInfer => { + ast::TyKind::Infer => { if width >= 1 { Some("_".to_owned()) } else { None } } - ast::TyBareFn(ref bare_fn) => { + ast::TyKind::BareFn(ref bare_fn) => { rewrite_bare_fn(bare_fn, self.span, context, width, offset) } - ast::TyMac(..) | ast::TyTypeof(..) => unreachable!(), + ast::TyKind::Mac(..) | ast::TyKind::Typeof(..) => unreachable!(), } } } @@ -567,7 +567,7 @@ fn rewrite_bare_fn(bare_fn: &ast::BareFnTy, result.push_str(&::utils::format_unsafety(bare_fn.unsafety)); - if bare_fn.abi != abi::Rust { + if bare_fn.abi != abi::Abi::Rust { result.push_str(&::utils::format_abi(bare_fn.abi)); } diff --git a/src/utils.rs b/src/utils.rs index 3b03ede2be3..acf758087d4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -10,7 +10,7 @@ use std::cmp::Ordering; -use syntax::ast::{self, Visibility, Attribute, MetaItem, MetaItem_}; +use syntax::ast::{self, Visibility, Attribute, MetaItem, MetaItemKind}; use syntax::codemap::{CodeMap, Span, BytePos}; use syntax::abi; @@ -77,8 +77,8 @@ pub fn format_unsafety(unsafety: ast::Unsafety) -> &'static str { #[inline] pub fn format_mutability(mutability: ast::Mutability) -> &'static str { match mutability { - ast::Mutability::MutMutable => "mut ", - ast::Mutability::MutImmutable => "", + ast::Mutability::Mutable => "mut ", + ast::Mutability::Immutable => "", } } @@ -109,8 +109,8 @@ pub fn last_line_width(s: &str) -> usize { #[inline] fn is_skip(meta_item: &MetaItem) -> bool { match meta_item.node { - MetaItem_::MetaWord(ref s) => *s == SKIP_ANNOTATION, - MetaItem_::MetaList(ref s, ref l) => *s == "cfg_attr" && l.len() == 2 && is_skip(&l[1]), + MetaItemKind::Word(ref s) => *s == SKIP_ANNOTATION, + MetaItemKind::List(ref s, ref l) => *s == "cfg_attr" && l.len() == 2 && is_skip(&l[1]), _ => false, } } @@ -137,9 +137,9 @@ pub fn end_typaram(typaram: &ast::TyParam) -> BytePos { #[inline] pub fn semicolon_for_expr(expr: &ast::Expr) -> bool { match expr.node { - ast::Expr_::ExprRet(..) | - ast::Expr_::ExprAgain(..) | - ast::Expr_::ExprBreak(..) => true, + ast::ExprKind::Ret(..) | + ast::ExprKind::Again(..) | + ast::ExprKind::Break(..) => true, _ => false, } } @@ -147,16 +147,16 @@ pub fn semicolon_for_expr(expr: &ast::Expr) -> bool { #[inline] pub fn semicolon_for_stmt(stmt: &ast::Stmt) -> bool { match stmt.node { - ast::Stmt_::StmtSemi(ref expr, _) => { + ast::StmtKind::Semi(ref expr, _) => { match expr.node { - ast::Expr_::ExprWhile(..) | - ast::Expr_::ExprWhileLet(..) | - ast::Expr_::ExprLoop(..) | - ast::Expr_::ExprForLoop(..) => false, + ast::ExprKind::While(..) | + ast::ExprKind::WhileLet(..) | + ast::ExprKind::Loop(..) | + ast::ExprKind::ForLoop(..) => false, _ => true, } } - ast::Stmt_::StmtExpr(..) => false, + ast::StmtKind::Expr(..) => false, _ => true, } } diff --git a/src/visitor.rs b/src/visitor.rs index f53ed2246d5..ae93ee52aab 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -36,8 +36,8 @@ pub struct FmtVisitor<'a> { impl<'a> FmtVisitor<'a> { fn visit_stmt(&mut self, stmt: &ast::Stmt) { match stmt.node { - ast::Stmt_::StmtDecl(ref decl, _) => { - if let ast::Decl_::DeclItem(ref item) = decl.node { + ast::StmtKind::Decl(ref decl, _) => { + if let ast::DeclKind::Item(ref item) = decl.node { self.visit_item(item); } else { let rewrite = stmt.rewrite(&self.get_context(), @@ -47,14 +47,14 @@ impl<'a> FmtVisitor<'a> { self.push_rewrite(stmt.span, rewrite); } } - ast::Stmt_::StmtExpr(..) | ast::Stmt_::StmtSemi(..) => { + ast::StmtKind::Expr(..) | ast::StmtKind::Semi(..) => { let rewrite = stmt.rewrite(&self.get_context(), self.config.max_width - self.block_indent.width(), self.block_indent); self.push_rewrite(stmt.span, rewrite); } - ast::Stmt_::StmtMac(ref mac, _macro_style, _) => { + ast::StmtKind::Mac(ref mac, _macro_style, _) => { self.format_missing_with_indent(stmt.span.lo); self.visit_mac(mac); } @@ -183,7 +183,7 @@ impl<'a> FmtVisitor<'a> { // FIXME This is overly conservative and means we miss attributes on // inline modules. match item.node { - ast::Item_::ItemMod(_) => { + ast::ItemKind::Mod(_) => { if utils::contains_skip(&item.attrs) { return; } @@ -197,10 +197,10 @@ impl<'a> FmtVisitor<'a> { } match item.node { - ast::Item_::ItemUse(ref vp) => { + ast::ItemKind::Use(ref vp) => { self.format_import(item.vis, vp, item.span); } - ast::Item_::ItemImpl(..) => { + ast::ItemKind::Impl(..) => { self.format_missing_with_indent(item.span.lo); if let Some(impl_str) = format_impl(&self.get_context(), item, self.block_indent) { self.buffer.push_str(&impl_str); @@ -208,7 +208,7 @@ impl<'a> FmtVisitor<'a> { } } // FIXME(#78): format traits. - ast::Item_::ItemTrait(_, _, _, ref trait_items) => { + ast::ItemKind::Trait(_, _, _, ref trait_items) => { self.format_missing_with_indent(item.span.lo); self.block_indent = self.block_indent.block_indent(self.config); for item in trait_items { @@ -216,13 +216,13 @@ impl<'a> FmtVisitor<'a> { } self.block_indent = self.block_indent.block_unindent(self.config); } - ast::Item_::ItemExternCrate(_) => { + ast::ItemKind::ExternCrate(_) => { self.format_missing_with_indent(item.span.lo); let new_str = self.snippet(item.span); self.buffer.push_str(&new_str); self.last_pos = item.span.hi; } - ast::Item_::ItemStruct(ref def, ref generics) => { + ast::ItemKind::Struct(ref def, ref generics) => { let rewrite = { let indent = self.block_indent; let context = self.get_context(); @@ -243,24 +243,24 @@ impl<'a> FmtVisitor<'a> { }; self.push_rewrite(item.span, rewrite); } - ast::Item_::ItemEnum(ref def, ref generics) => { + ast::ItemKind::Enum(ref def, ref generics) => { self.format_missing_with_indent(item.span.lo); self.visit_enum(item.ident, item.vis, def, generics, item.span); self.last_pos = item.span.hi; } - ast::Item_::ItemMod(ref module) => { + ast::ItemKind::Mod(ref module) => { self.format_missing_with_indent(item.span.lo); self.format_mod(module, item.vis, item.span, item.ident); } - ast::Item_::ItemMac(ref mac) => { + ast::ItemKind::Mac(ref mac) => { self.format_missing_with_indent(item.span.lo); self.visit_mac(mac); } - ast::Item_::ItemForeignMod(ref foreign_mod) => { + ast::ItemKind::ForeignMod(ref foreign_mod) => { self.format_missing_with_indent(item.span.lo); self.format_foreign_mod(foreign_mod, item.span); } - ast::Item_::ItemStatic(ref ty, mutability, ref expr) => { + ast::ItemKind::Static(ref ty, mutability, ref expr) => { let rewrite = rewrite_static("static", item.vis, item.ident, @@ -270,32 +270,32 @@ impl<'a> FmtVisitor<'a> { &self.get_context()); self.push_rewrite(item.span, rewrite); } - ast::Item_::ItemConst(ref ty, ref expr) => { + ast::ItemKind::Const(ref ty, ref expr) => { let rewrite = rewrite_static("const", item.vis, item.ident, ty, - ast::Mutability::MutImmutable, + ast::Mutability::Immutable, expr, &self.get_context()); self.push_rewrite(item.span, rewrite); } - ast::Item_::ItemDefaultImpl(..) => { + ast::ItemKind::DefaultImpl(..) => { // FIXME(#78): format impl definitions. } - ast::ItemFn(ref declaration, unsafety, constness, abi, ref generics, ref body) => { + ast::ItemKind::Fn(ref decl, unsafety, constness, abi, ref generics, ref body) => { self.visit_fn(visit::FnKind::ItemFn(item.ident, generics, unsafety, constness, abi, item.vis), - declaration, + decl, body, item.span, item.id) } - ast::Item_::ItemTy(ref ty, ref generics) => { + ast::ItemKind::Ty(ref ty, ref generics) => { let rewrite = rewrite_type_alias(&self.get_context(), self.block_indent, item.ident, @@ -314,22 +314,22 @@ impl<'a> FmtVisitor<'a> { } match ti.node { - ast::ConstTraitItem(..) => { + ast::TraitItemKind::Const(..) => { // FIXME: Implement } - ast::MethodTraitItem(ref sig, None) => { + ast::TraitItemKind::Method(ref sig, None) => { let indent = self.block_indent; let rewrite = self.rewrite_required_fn(indent, ti.ident, sig, ti.span); self.push_rewrite(ti.span, rewrite); } - ast::MethodTraitItem(ref sig, Some(ref body)) => { + ast::TraitItemKind::Method(ref sig, Some(ref body)) => { self.visit_fn(visit::FnKind::Method(ti.ident, sig, None), &sig.decl, &body, ti.span, ti.id); } - ast::TypeTraitItem(..) => { + ast::TraitItemKind::Type(..) => { // FIXME: Implement } }