From 68c6fe70fdf441b46d5b88bc344e6d68f8f0068d Mon Sep 17 00:00:00 2001 From: topecongiro Date: Fri, 21 Jul 2017 17:55:52 +0900 Subject: [PATCH] Format source codes and update tests --- src/expr.rs | 11 +++++------ src/items.rs | 11 +++++------ src/visitor.rs | 14 ++++++-------- tests/target/chains-visual.rs | 11 +++++------ tests/target/chains.rs | 9 ++++----- tests/target/issue-831.rs | 9 +++++++++ 6 files changed, 34 insertions(+), 31 deletions(-) create mode 100644 tests/target/issue-831.rs diff --git a/src/expr.rs b/src/expr.rs index 2ba08cd3390..c1d5e8ccc39 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -2899,12 +2899,11 @@ pub fn rewrite_assign_rhs>( shape: Shape, ) -> Option { let lhs = lhs.into(); - let last_line_width = last_line_width(&lhs) - - if lhs.contains('\n') { - shape.indent.width() - } else { - 0 - }; + let last_line_width = last_line_width(&lhs) - if lhs.contains('\n') { + shape.indent.width() + } else { + 0 + }; // 1 = space between operator and rhs. let orig_shape = try_opt!(shape.offset_left(last_line_width + 1)); let rhs = try_opt!(choose_rhs( diff --git a/src/items.rs b/src/items.rs index 22ac1354e34..087b5615f02 100644 --- a/src/items.rs +++ b/src/items.rs @@ -829,12 +829,11 @@ fn rewrite_trait_ref( result_len: usize, ) -> Option { // 1 = space between generics and trait_ref - let used_space = 1 + polarity_str.len() + - if generics_str.contains('\n') { - last_line_width(&generics_str) - } else { - result_len + generics_str.len() - }; + let used_space = 1 + polarity_str.len() + if generics_str.contains('\n') { + last_line_width(&generics_str) + } else { + result_len + generics_str.len() + }; let shape = Shape::indented(offset + used_space, context.config); if let Some(trait_ref_str) = trait_ref.rewrite(context, shape) { if !(retry && trait_ref_str.contains('\n')) { diff --git a/src/visitor.rs b/src/visitor.rs index e6e7f038ce7..e3233e1dba3 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -630,14 +630,12 @@ impl<'a> FmtVisitor<'a> { let use_item_length = items_left .iter() .take_while(|ppi| { - is_use_item(&***ppi) && - (!reorder_imports_in_group || - { - let current = self.codemap.lookup_line_range(item_bound(&ppi)); - let in_same_group = current.lo < last.hi + 2; - last = current; - in_same_group - }) + is_use_item(&***ppi) && (!reorder_imports_in_group || { + let current = self.codemap.lookup_line_range(item_bound(&ppi)); + let in_same_group = current.lo < last.hi + 2; + last = current; + in_same_group + }) }) .count(); let (use_items, rest) = items_left.split_at(use_item_length); diff --git a/tests/target/chains-visual.rs b/tests/target/chains-visual.rs index 3962bdcbbcd..c2aecd26105 100644 --- a/tests/target/chains-visual.rs +++ b/tests/target/chains-visual.rs @@ -118,12 +118,11 @@ fn floaters() { }) .quux(); - a + - match x { - true => "yay!", - false => "boo!", - } - .bar() + a + match x { + true => "yay!", + false => "boo!", + } + .bar() } fn is_replaced_content() -> bool { diff --git a/tests/target/chains.rs b/tests/target/chains.rs index d930f0a49ba..4955817da5c 100644 --- a/tests/target/chains.rs +++ b/tests/target/chains.rs @@ -114,11 +114,10 @@ fn floaters() { }) .quux(); - a + - match x { - true => "yay!", - false => "boo!", - }.bar() + a + match x { + true => "yay!", + false => "boo!", + }.bar() } fn is_replaced_content() -> bool { diff --git a/tests/target/issue-831.rs b/tests/target/issue-831.rs new file mode 100644 index 00000000000..1d6327c2158 --- /dev/null +++ b/tests/target/issue-831.rs @@ -0,0 +1,9 @@ +fn main() { + let y = a.iter().any(|x| { + println!("a"); + }) || b.iter().any(|x| { + println!("b"); + }) || c.iter().any(|x| { + println!("c"); + }); +}