From 77a2e9858b44598454aa6240475255cd5547d519 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Fri, 19 May 2017 19:31:29 +0900 Subject: [PATCH] Format source codes --- build.rs | 4 ++-- src/expr.rs | 14 +++++++------- src/items.rs | 8 ++++---- src/lists.rs | 3 ++- src/missed_spans.rs | 2 +- src/patterns.rs | 2 +- src/types.rs | 42 +++++++++++++++++++++++++----------------- src/visitor.rs | 8 ++++---- 8 files changed, 46 insertions(+), 37 deletions(-) diff --git a/build.rs b/build.rs index 4f4a63be436..aca96774d06 100644 --- a/build.rs +++ b/build.rs @@ -16,11 +16,11 @@ fn main() { writeln!(f, "const COMMIT_HASH: Option<&'static str> = {:?};", git_head_sha1()) - .unwrap(); + .unwrap(); writeln!(f, "const WORKTREE_CLEAN: Option = {:?};", git_tree_is_clean()) - .unwrap(); + .unwrap(); // cargo:rerun-if-changed requires one entry per individual file. for entry in WalkDir::new("src") { diff --git a/src/expr.rs b/src/expr.rs index 7226357f7a3..31953380a73 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -120,7 +120,7 @@ fn format_expr(expr: &ast::Expr, expr_type == ExprType::SubExpression, false, expr.span) - .rewrite(context, shape) + .rewrite(context, shape) } ast::ExprKind::IfLet(ref pat, ref cond, ref if_block, ref else_block) => { ControlFlow::new_if(cond, @@ -130,7 +130,7 @@ fn format_expr(expr: &ast::Expr, expr_type == ExprType::SubExpression, false, expr.span) - .rewrite(context, shape) + .rewrite(context, shape) } ast::ExprKind::Match(ref cond, ref arms) => { rewrite_match(context, cond, arms, shape, expr.span) @@ -372,7 +372,7 @@ pub fn rewrite_array<'a, I>(expr_iter: I, |item| item.rewrite(context, nested_shape), span.lo, span.hi) - .collect::>(); + .collect::>(); if items.is_empty() { if context.config.spaces_within_square_brackets() { @@ -716,7 +716,7 @@ impl Rewrite for ast::Stmt { }, context, try_opt!(shape.sub_width(suffix.len()))) - .map(|s| s + suffix) + .map(|s| s + suffix) } ast::StmtKind::Mac(..) | ast::StmtKind::Item(..) => None, @@ -1012,7 +1012,7 @@ impl<'a> Rewrite for ControlFlow<'a> { false, true, mk_sp(else_block.span.lo, self.span.hi)) - .rewrite(context, shape) + .rewrite(context, shape) } ast::ExprKind::If(ref cond, ref if_block, ref next_else_block) => { ControlFlow::new_if(cond, @@ -1022,7 +1022,7 @@ impl<'a> Rewrite for ControlFlow<'a> { false, true, mk_sp(else_block.span.lo, self.span.hi)) - .rewrite(context, shape) + .rewrite(context, shape) } _ => { last_in_chain = true; @@ -1065,7 +1065,7 @@ impl<'a> Rewrite for ControlFlow<'a> { .as_ref() .map_or(between_sep, |s| &**s), after_else_comment.as_ref().map_or(after_sep, |s| &**s)) - .ok()); + .ok()); result.push_str(&try_opt!(rewrite)); } diff --git a/src/items.rs b/src/items.rs index 953aecb3305..f98cf9507e1 100644 --- a/src/items.rs +++ b/src/items.rs @@ -332,7 +332,7 @@ impl<'a> FmtVisitor<'a> { let suffix = if semicolon_for_expr(e) { ";" } else { "" }; e.rewrite(&self.get_context(), - Shape::indented(self.block_indent, self.config)) + Shape::indented(self.block_indent, self.config)) .map(|s| s + suffix) .or_else(|| Some(self.snippet(e.span))) } @@ -376,7 +376,7 @@ impl<'a> FmtVisitor<'a> { enum_def.variants.is_empty(), self.block_indent, mk_sp(span.lo, body_start)) - .unwrap(); + .unwrap(); self.buffer.push_str(&generics_str); self.last_pos = body_start; @@ -941,7 +941,7 @@ fn format_struct_struct(context: &RewriteContext, |field| field.rewrite(context, Shape::legacy(item_budget, item_indent)), context.codemap.span_after(span, "{"), span.hi) - .collect::>(); + .collect::>(); // 1 = , let budget = context.config.max_width() - offset.width() + context.config.tab_spaces() - 1; @@ -1295,7 +1295,7 @@ pub fn rewrite_static(prefix: &str, lhs, expr, Shape::legacy(remaining_width, offset.block_only())) - .map(|s| s + ";") + .map(|s| s + ";") } else { let lhs = format!("{}{};", prefix, ty_str); Some(lhs) diff --git a/src/lists.rs b/src/lists.rs index a48f9a382e6..3448f8a446a 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -266,7 +266,8 @@ pub fn write_list(items: I, formatting: &ListFormatting) -> Option // Post-comments if tactic != DefinitiveListTactic::Vertical && item.post_comment.is_some() { let comment = item.post_comment.as_ref().unwrap(); - let formatted_comment = try_opt!(rewrite_comment(comment, + let formatted_comment = + try_opt!(rewrite_comment(comment, true, Shape::legacy(formatting.shape.width, Indent::empty()), formatting.config)); diff --git a/src/missed_spans.rs b/src/missed_spans.rs index 2f4dda2a1b4..d6157cd6a29 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -163,7 +163,7 @@ impl<'a> FmtVisitor<'a> { Shape::legacy(comment_width, self.block_indent), self.config) - .unwrap()); + .unwrap()); last_wspace = None; line_start = offset + subslice.len(); diff --git a/src/patterns.rs b/src/patterns.rs index 5dc70f6d2d8..afea0ddb299 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -293,7 +293,7 @@ fn rewrite_tuple_pat(pats: &[ptr::P], |item| item.rewrite(context, nested_shape), context.codemap.span_after(span, "("), span.hi - BytePos(1)) - .collect(); + .collect(); // Condense wildcard string suffix into a single .. let wildcard_suffix_len = count_wildcard_suffix_len(&items); diff --git a/src/types.rs b/src/types.rs index ffa9639005a..570755d4441 100644 --- a/src/types.rs +++ b/src/types.rs @@ -364,7 +364,9 @@ impl Rewrite for ast::WherePredicate { let colon = type_bound_colon(context); if !bound_lifetimes.is_empty() { - let lifetime_str: String = try_opt!(bound_lifetimes.iter() + let lifetime_str: String = + try_opt!(bound_lifetimes + .iter() .map(|lt| lt.rewrite(context, shape)) .intersperse(Some(", ".to_string())) .collect()); @@ -376,14 +378,17 @@ impl Rewrite for ast::WherePredicate { // 6 = "for<> ".len() let used_width = lifetime_str.len() + type_str.len() + colon.len() + 6; let budget = try_opt!(shape.width.checked_sub(used_width)); - let bounds_str: String = try_opt!(bounds.iter() - .map(|ty_bound| { - ty_bound.rewrite(context, - Shape::legacy(budget, - shape.indent + used_width)) - }) - .intersperse(Some(joiner.to_string())) - .collect()); + let bounds_str: String = + try_opt!(bounds + .iter() + .map(|ty_bound| { + ty_bound.rewrite(context, + Shape::legacy(budget, + shape.indent + + used_width)) + }) + .intersperse(Some(joiner.to_string())) + .collect()); if context.config.spaces_within_angle_brackets() && lifetime_str.len() > 0 { format!("for< {} > {}{}{}", @@ -401,14 +406,17 @@ impl Rewrite for ast::WherePredicate { }; let used_width = type_str.len() + colon.len(); let budget = try_opt!(shape.width.checked_sub(used_width)); - let bounds_str: String = try_opt!(bounds.iter() - .map(|ty_bound| { - ty_bound.rewrite(context, - Shape::legacy(budget, - shape.indent + used_width)) - }) - .intersperse(Some(joiner.to_string())) - .collect()); + let bounds_str: String = + try_opt!(bounds + .iter() + .map(|ty_bound| { + ty_bound.rewrite(context, + Shape::legacy(budget, + shape.indent + + used_width)) + }) + .intersperse(Some(joiner.to_string())) + .collect()); format!("{}{}{}", type_str, colon, bounds_str) } diff --git a/src/visitor.rs b/src/visitor.rs index 0e6817be4f7..96327ef96a7 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -282,10 +282,10 @@ impl<'a> FmtVisitor<'a> { item.span, indent, None) - .map(|s| match *def { - ast::VariantData::Tuple(..) => s + ";", - _ => s, - }) + .map(|s| match *def { + ast::VariantData::Tuple(..) => s + ";", + _ => s, + }) }; self.push_rewrite(item.span, rewrite); }