From 22c9025027144a74bc86893a6af6b9ad807f21dc Mon Sep 17 00:00:00 2001 From: topecongiro Date: Wed, 16 Aug 2017 00:48:12 +0900 Subject: [PATCH] Format source codes --- src/bin/cargo-fmt.rs | 12 +++++++----- src/config.rs | 8 +++++--- src/expr.rs | 30 ++++++++++++++++-------------- src/issues.rs | 32 +++++++++++++++++++------------- src/items.rs | 44 +++++++++++++++++++++++++------------------- src/macros.rs | 12 +++++++----- src/patterns.rs | 12 +++++++----- src/types.rs | 12 +++++++----- src/visitor.rs | 10 ++++++---- 9 files changed, 99 insertions(+), 73 deletions(-) diff --git a/src/bin/cargo-fmt.rs b/src/bin/cargo-fmt.rs index 001ffb649c6..e6a86e04b9e 100644 --- a/src/bin/cargo-fmt.rs +++ b/src/bin/cargo-fmt.rs @@ -94,11 +94,13 @@ fn execute() -> i32 { print_usage_to_stderr(&opts, &e.to_string()); failure } - Ok(status) => if status.success() { - success - } else { - status.code().unwrap_or(failure) - }, + Ok(status) => { + if status.success() { + success + } else { + status.code().unwrap_or(failure) + } + } } } diff --git a/src/config.rs b/src/config.rs index ce045502c9c..2b4665729c4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -568,9 +568,11 @@ pub fn get_toml_path(dir: &Path) -> Result, Error> { Ok(ref md) if md.is_file() => return Ok(Some(config_file)), // Return the error if it's something other than `NotFound`; otherwise we didn't // find the project file yet, and continue searching. - Err(e) => if e.kind() != ErrorKind::NotFound { - return Err(e); - }, + Err(e) => { + if e.kind() != ErrorKind::NotFound { + return Err(e); + } + } _ => {} } } diff --git a/src/expr.rs b/src/expr.rs index 46641a10ae6..e75c7e2c9dd 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -462,18 +462,20 @@ pub fn rewrite_array<'a, I>( None => DefinitiveListTactic::Vertical, } } - IndentStyle::Visual => if has_long_item || items.iter().any(ListItem::is_multiline) { - definitive_tactic( - &items, - ListTactic::LimitedHorizontalVertical( - context.config.width_heuristics().array_width, - ), - Separator::Comma, - nested_shape.width, - ) - } else { - DefinitiveListTactic::Mixed - }, + IndentStyle::Visual => { + if has_long_item || items.iter().any(ListItem::is_multiline) { + definitive_tactic( + &items, + ListTactic::LimitedHorizontalVertical( + context.config.width_heuristics().array_width, + ), + Separator::Comma, + nested_shape.width, + ) + } else { + DefinitiveListTactic::Mixed + } + } }; let ends_with_newline = tactic.ends_with_newline(context.config.indent_style()); @@ -1501,8 +1503,8 @@ fn flatten_arm_body<'a>(context: &'a RewriteContext, body: &'a ast::Expr) -> (bo if let ast::StmtKind::Expr(ref expr) = block.stmts[0].node { ( !context.config.force_multiline_blocks() - && (can_extend_match_arm_body(expr), &**expr), - &**expr, + && can_extend_match_arm_body(expr), + &*expr, ) } else { (false, &*body) diff --git a/src/issues.rs b/src/issues.rs index be30ff2d86e..f05aa0512da 100644 --- a/src/issues.rs +++ b/src/issues.rs @@ -190,19 +190,25 @@ fn inspect_number( } match part { - NumberPart::OpenParen => if c != '(' { - return IssueClassification::Bad(issue); - } else { - part = NumberPart::Pound; - }, - NumberPart::Pound => if c == '#' { - part = NumberPart::Number; - }, - NumberPart::Number => if c >= '0' && c <= '9' { - part = NumberPart::CloseParen; - } else { - return IssueClassification::Bad(issue); - }, + NumberPart::OpenParen => { + if c != '(' { + return IssueClassification::Bad(issue); + } else { + part = NumberPart::Pound; + } + } + NumberPart::Pound => { + if c == '#' { + part = NumberPart::Number; + } + } + NumberPart::Number => { + if c >= '0' && c <= '9' { + part = NumberPart::CloseParen; + } else { + return IssueClassification::Bad(issue); + } + } NumberPart::CloseParen => {} } diff --git a/src/items.rs b/src/items.rs index 6285811e79e..867051baea0 100644 --- a/src/items.rs +++ b/src/items.rs @@ -550,12 +550,14 @@ fn format_variant(&self, field: &ast::Variant, one_line_width: usize) -> Option< self.block_indent, Some(one_line_width), )?, - ast::VariantData::Unit(..) => if let Some(ref expr) = field.node.disr_expr { - let lhs = format!("{} =", field.node.name); - rewrite_assign_rhs(&context, lhs, &**expr, shape)? - } else { - field.node.name.to_string() - }, + ast::VariantData::Unit(..) => { + if let Some(ref expr) = field.node.disr_expr { + let lhs = format!("{} =", field.node.name); + rewrite_assign_rhs(&context, lhs, &**expr, shape)? + } else { + field.node.name.to_string() + } + } }; let attrs_extendable = attrs_str.is_empty() @@ -643,11 +645,13 @@ pub fn format_impl( _ if last_line_contains_single_line_comment(&result) => result.push_str(&sep), BraceStyle::AlwaysNextLine => result.push_str(&sep), BraceStyle::PreferSameLine => result.push(' '), - BraceStyle::SameLineWhere => if !where_clause_str.is_empty() { - result.push_str(&sep); - } else { - result.push(' '); - }, + BraceStyle::SameLineWhere => { + if !where_clause_str.is_empty() { + result.push_str(&sep); + } else { + result.push(' '); + } + } } result.push('{'); @@ -1039,14 +1043,16 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) result.push_str(&offset.to_string(context.config)); } BraceStyle::PreferSameLine => result.push(' '), - BraceStyle::SameLineWhere => if !where_clause_str.is_empty() - && (!trait_items.is_empty() || result.contains('\n')) - { - result.push('\n'); - result.push_str(&offset.to_string(context.config)); - } else { - result.push(' '); - }, + BraceStyle::SameLineWhere => { + if !where_clause_str.is_empty() + && (!trait_items.is_empty() || result.contains('\n')) + { + result.push('\n'); + result.push_str(&offset.to_string(context.config)); + } else { + result.push(' '); + } + } } result.push('{'); diff --git a/src/macros.rs b/src/macros.rs index 8c8b50b7ca3..9247a75ce86 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -126,11 +126,13 @@ pub fn rewrite_macro( let macro_name = match extra_ident { None => format!("{}!", mac.node.path), - Some(ident) => if ident == symbol::keywords::Invalid.ident() { - format!("{}!", mac.node.path) - } else { - format!("{}! {}", mac.node.path, ident) - }, + Some(ident) => { + if ident == symbol::keywords::Invalid.ident() { + format!("{}!", mac.node.path) + } else { + format!("{}! {}", mac.node.path, ident) + } + } }; let style = if FORCED_BRACKET_MACROS.contains(&¯o_name[..]) { diff --git a/src/patterns.rs b/src/patterns.rs index f4bb59e5127..90a47d785f0 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -51,11 +51,13 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { Some(format!("{}{}{}{}", prefix, mut_infix, id_str, sub_pat)) } - PatKind::Wild => if 1 <= shape.width { - Some("_".to_owned()) - } else { - None - }, + PatKind::Wild => { + if 1 <= shape.width { + Some("_".to_owned()) + } else { + None + } + } PatKind::Range(ref lhs, ref rhs, ref end_kind) => { let infix = match *end_kind { RangeEnd::Included(RangeSyntax::DotDotDot) => "...", diff --git a/src/types.rs b/src/types.rs index 25bbd92b108..72cace33def 100644 --- a/src/types.rs +++ b/src/types.rs @@ -720,11 +720,13 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { SeparatorPlace::Back, ) } - ast::TyKind::Infer => if shape.width >= 1 { - Some("_".to_owned()) - } else { - None - }, + ast::TyKind::Infer => { + if shape.width >= 1 { + Some("_".to_owned()) + } else { + None + } + } ast::TyKind::BareFn(ref bare_fn) => rewrite_bare_fn(bare_fn, self.span, context, shape), ast::TyKind::Never => Some(String::from("!")), ast::TyKind::Mac(..) => None, diff --git a/src/visitor.rs b/src/visitor.rs index 85a8fb38f07..2896b39b09d 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -321,10 +321,12 @@ pub fn visit_item(&mut self, item: &ast::Item) { attrs = &filtered_attrs; } } - _ => if self.visit_attrs(&item.attrs, ast::AttrStyle::Outer) { - self.push_rewrite(item.span, None); - return; - }, + _ => { + if self.visit_attrs(&item.attrs, ast::AttrStyle::Outer) { + self.push_rewrite(item.span, None); + return; + } + } } match item.node { -- 2.44.0