From 594774b4e5044f5700e43f7439bf0575cc6bd6bf Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Wed, 19 Sep 2018 23:19:24 +0900 Subject: [PATCH 1/4] Update tests --- tests/target/chains.rs | 64 ++++++++++++------- tests/target/closure.rs | 3 +- .../target/configs/indent_style/block_call.rs | 6 +- tests/target/expr-block.rs | 3 +- tests/target/file-lines-1.rs | 3 +- tests/target/file-lines-3.rs | 3 +- tests/target/issue-1681.rs | 3 +- tests/target/issue-2759.rs | 3 +- tests/target/issue-2896.rs | 6 +- tests/target/macros.rs | 6 +- tests/target/match.rs | 3 +- tests/target/nested-visual-block.rs | 3 +- 12 files changed, 70 insertions(+), 36 deletions(-) diff --git a/tests/target/chains.rs b/tests/target/chains.rs index 2d945e3c390d..2945f836a6b1 100644 --- a/tests/target/chains.rs +++ b/tests/target/chains.rs @@ -38,7 +38,8 @@ fn main() { .method_call_a(aaaaa, bbbbb, |c| { let x = c; x - }).method_call_b(aaaaa, bbbbb, |c| { + }) + .method_call_b(aaaaa, bbbbb, |c| { let x = c; x }); @@ -55,7 +56,8 @@ fn main() { body.fold(Body::new(), |mut body, chunk| { body.extend(chunk); Ok(body) - }).and_then(move |body| { + }) + .and_then(move |body| { let req = Request::from_parts(parts, body); f(req).map_err(|_| io::Error::new(io::ErrorKind::Other, "")) }); @@ -64,7 +66,8 @@ fn main() { .map(|x| { x += 1; x - }).filter(some_mod::some_filter) + }) + .filter(some_mod::some_filter) } fn floaters() { @@ -76,14 +79,16 @@ fn floaters() { let x = Foo { field1: val1, field2: val2, - }.method_call() + } + .method_call() .method_call(); let y = if cond { val1 } else { val2 - }.method_call(); + } + .method_call(); { match x { @@ -91,9 +96,10 @@ fn floaters() { // params are 1-indexed stack.push( mparams[match cur.to_digit(10) { - Some(d) => d as usize - 1, - None => return Err("bad param number".to_owned()), - }].clone(), + Some(d) => d as usize - 1, + None => return Err("bad param number".to_owned()), + }] + .clone(), ); } } @@ -103,28 +109,34 @@ fn floaters() { some(); } else { none(); - }.bar() + } + .bar() .baz(); Foo { x: val, - }.baz(|| { + } + .baz(|| { force(); multiline(); - }).quux(); + }) + .quux(); Foo { y: i_am_multi_line, z: ok, - }.baz(|| { + } + .baz(|| { force(); multiline(); - }).quux(); + }) + .quux(); a + match x { true => "yay!", false => "boo!", - }.bar() + } + .bar() } fn is_replaced_content() -> bool { @@ -184,7 +196,8 @@ fn issue1392() { else { b(); } - "#.trim(), + "# + .trim(), ); } @@ -234,7 +247,8 @@ impl Foo { } } }) - }).collect(); + }) + .collect(); } } @@ -247,8 +261,10 @@ fn issue2415() { Ok((|| { // stuff Some(value.to_string()) - })().ok_or("")?) - })().unwrap_or_else(|_: Box<::std::error::Error>| String::from("")); + })() + .ok_or("")?) + })() + .unwrap_or_else(|_: Box<::std::error::Error>| String::from("")); } impl issue_2786 { @@ -256,10 +272,12 @@ impl issue_2786 { foo(|a| { println!("a"); println!("b"); - }).bar(|c| { + }) + .bar(|c| { println!("a"); println!("b"); - }).baz(|c| { + }) + .baz(|c| { println!("a"); println!("b"); }) @@ -271,10 +289,12 @@ fn issue_2773() { bar.or_else(|| { // do stuff None - }).or_else(|| { + }) + .or_else(|| { // do other stuff None - }).and_then(|val| { + }) + .and_then(|val| { // do this stuff None }); diff --git a/tests/target/closure.rs b/tests/target/closure.rs index 2360ccfbd2fd..f3107d19c2fb 100644 --- a/tests/target/closure.rs +++ b/tests/target/closure.rs @@ -171,7 +171,8 @@ fn issue1329() { .map(|x| { x += 1; x - }).filter + }) + .filter } fn issue325() { diff --git a/tests/target/configs/indent_style/block_call.rs b/tests/target/configs/indent_style/block_call.rs index 19a45cb9f74e..19c44dc019a2 100644 --- a/tests/target/configs/indent_style/block_call.rs +++ b/tests/target/configs/indent_style/block_call.rs @@ -61,7 +61,8 @@ fn issue1420() { # Getting started ... "#, - ).running(waltz) + ) + .running(waltz) } // #1563 @@ -117,7 +118,8 @@ impl Cursor { debug_assert_eq!(n, -1); None } - }).or_else(|| { + }) + .or_else(|| { let canonical = self.canonical(); if canonical != *self { canonical.num_template_args() diff --git a/tests/target/expr-block.rs b/tests/target/expr-block.rs index d3a45566efa1..3d452cbde39b 100644 --- a/tests/target/expr-block.rs +++ b/tests/target/expr-block.rs @@ -141,7 +141,8 @@ fn issue_1450() { Relaxed, Release, Relaxed, - ).is_ok() + ) + .is_ok() { return; } diff --git a/tests/target/file-lines-1.rs b/tests/target/file-lines-1.rs index 1c63b105b988..13820ec293fa 100644 --- a/tests/target/file-lines-1.rs +++ b/tests/target/file-lines-1.rs @@ -4,7 +4,8 @@ fn floaters() { let x = Foo { field1: val1, field2: val2, - }.method_call() + } + .method_call() .method_call(); let y = if cond { diff --git a/tests/target/file-lines-3.rs b/tests/target/file-lines-3.rs index 9aba967e29dd..77d6fb263558 100644 --- a/tests/target/file-lines-3.rs +++ b/tests/target/file-lines-3.rs @@ -4,7 +4,8 @@ fn floaters() { let x = Foo { field1: val1, field2: val2, - }.method_call() + } + .method_call() .method_call(); let y = if cond { val1 } else { val2 }.method_call(); diff --git a/tests/target/issue-1681.rs b/tests/target/issue-1681.rs index 5734fd5502df..902765302eac 100644 --- a/tests/target/issue-1681.rs +++ b/tests/target/issue-1681.rs @@ -16,5 +16,6 @@ fn foo() { Ok(entry.insert(try!(statement))) } } - }).map(MaybeCached::Cached) + }) + .map(MaybeCached::Cached) } diff --git a/tests/target/issue-2759.rs b/tests/target/issue-2759.rs index 4441b140386e..b7176ec66f85 100644 --- a/tests/target/issue-2759.rs +++ b/tests/target/issue-2759.rs @@ -55,7 +55,8 @@ fn bar() {} /// .resource("/", |r| r.f(|r| HttpResponse::Ok())) /// .boxed(), /// ] -/// }).bind("127.0.0.1:8080") +/// }) +/// .bind("127.0.0.1:8080") /// .unwrap() /// .run() /// # }); diff --git a/tests/target/issue-2896.rs b/tests/target/issue-2896.rs index c750d96aa67c..e2c3247f1441 100644 --- a/tests/target/issue-2896.rs +++ b/tests/target/issue-2896.rs @@ -52,7 +52,8 @@ fn main() { assert!(row_sum_a > 0); (item_b, (item_a, num_cooccurrences, row_sum_a)) }, - ).join_map( + ) + .join_map( &row_sums, |&item_b, &(item_a, num_cooccurrences, row_sum_a), &row_sum_b| { assert!(row_sum_a > 0); @@ -159,5 +160,6 @@ fn main() { worker.step(); } } - }).unwrap(); + }) + .unwrap(); } diff --git a/tests/target/macros.rs b/tests/target/macros.rs index 26ccdd9a1b52..400ae0bcdad8 100644 --- a/tests/target/macros.rs +++ b/tests/target/macros.rs @@ -173,7 +173,8 @@ fn issue1739() { .., init_size[1] - extreeeeeeeeeeeeeeeeeeeeeeeem..init_size[1], .. - ]).par_map_inplace(|el| *el = 0.); + ]) + .par_map_inplace(|el| *el = 0.); } fn issue_1885() { @@ -183,7 +184,8 @@ fn issue_1885() { chan_select! { rx.recv() => {} } - }).collect::>(); + }) + .collect::>(); } fn issue_1917() { diff --git a/tests/target/match.rs b/tests/target/match.rs index e0774ef011ca..cda0ed2abe57 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -381,7 +381,8 @@ fn issue1456() { .iter() .map(|node| { XPathNodeReader::new(node, &context).and_then(|r| ArtistRef::from_xml(&r)) - }).collect(); + }) + .collect(); res? } _ => Vec::new(), diff --git a/tests/target/nested-visual-block.rs b/tests/target/nested-visual-block.rs index ed6c181fc7bf..fe7190d0abaa 100644 --- a/tests/target/nested-visual-block.rs +++ b/tests/target/nested-visual-block.rs @@ -29,7 +29,8 @@ fn main() { expr.rewrite( inner_context, &Constraints::new(try_opt!(v_budget.checked_sub(2)), indent + 2), - ).map(|s| format!("..{}", s)) + ) + .map(|s| format!("..{}", s)) } } }, From 76650174c70ca443936d2187a2edecff6dbd5d25 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Wed, 19 Sep 2018 23:20:43 +0900 Subject: [PATCH 2/4] Combine chain items only when the item will get orphaned --- src/chains.rs | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/src/chains.rs b/src/chains.rs index c57a9b49629f..56bd8574fc9d 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -80,7 +80,6 @@ use utils::{ use std::borrow::Cow; use std::cmp::min; -use std::iter; use syntax::source_map::{BytePos, Span}; use syntax::{ast, ptr}; @@ -132,8 +131,8 @@ impl ChainItemKind { fn is_block_like(&self, context: &RewriteContext, reps: &str) -> bool { match self { ChainItemKind::Parent(ref expr) => is_block_expr(context, expr, reps), - ChainItemKind::MethodCall(..) => reps.contains('\n'), - ChainItemKind::StructField(..) + ChainItemKind::MethodCall(..) + | ChainItemKind::StructField(..) | ChainItemKind::TupleField(..) | ChainItemKind::Comment(..) => false, } @@ -625,12 +624,7 @@ impl<'a> ChainFormatterShared<'a> { Some(()) } - fn join_rewrites( - &self, - context: &RewriteContext, - child_shape: Shape, - block_like_iter: impl Iterator, - ) -> Option { + fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option { let connector = if self.fits_single_line { // Yay, we can put everything on one line. Cow::from("") @@ -645,17 +639,13 @@ impl<'a> ChainFormatterShared<'a> { let mut rewrite_iter = self.rewrites.iter(); let mut result = rewrite_iter.next().unwrap().clone(); let children_iter = self.children.iter(); - let iter = rewrite_iter.zip(block_like_iter).zip(children_iter); + let iter = rewrite_iter.zip(children_iter); - for ((rewrite, prev_is_block_like), chain_item) in iter { + for (rewrite, chain_item) in iter { match chain_item.kind { ChainItemKind::Comment(_, CommentPosition::Back) => result.push(' '), ChainItemKind::Comment(_, CommentPosition::Top) => result.push_str(&connector), - _ => { - if !prev_is_block_like { - result.push_str(&connector); - } - } + _ => result.push_str(&connector), } result.push_str(&rewrite); } @@ -667,15 +657,14 @@ impl<'a> ChainFormatterShared<'a> { // Formats a chain using block indent. struct ChainFormatterBlock<'a> { shared: ChainFormatterShared<'a>, - // For each rewrite, whether the corresponding item is block-like. - is_block_like: Vec, + root_ends_with_block: bool, } impl<'a> ChainFormatterBlock<'a> { fn new(chain: &'a Chain) -> ChainFormatterBlock<'a> { ChainFormatterBlock { shared: ChainFormatterShared::new(chain), - is_block_like: Vec::with_capacity(chain.children.len() + 1), + root_ends_with_block: false, } } } @@ -703,21 +692,21 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> { None => break, } - root_ends_with_block = item.kind.is_block_like(context, &root_rewrite); + root_ends_with_block = last_line_extendable(&root_rewrite); self.shared.children = &self.shared.children[1..]; if self.shared.children.is_empty() { break; } } - self.is_block_like.push(root_ends_with_block); self.shared.rewrites.push(root_rewrite); + self.root_ends_with_block = root_ends_with_block; Some(()) } fn child_shape(&self, context: &RewriteContext, shape: Shape) -> Option { Some( - if self.is_block_like[0] { + if self.root_ends_with_block { shape.block_indent(0) } else { shape.block_indent(context.config.tab_spaces()) @@ -728,8 +717,6 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> { fn format_children(&mut self, context: &RewriteContext, child_shape: Shape) -> Option<()> { for item in &self.shared.children[..self.shared.children.len() - 1] { let rewrite = item.rewrite(context, child_shape)?; - self.is_block_like - .push(item.kind.is_block_like(context, &rewrite)); self.shared.rewrites.push(rewrite); } Some(()) @@ -746,8 +733,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> { } fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option { - self.shared - .join_rewrites(context, child_shape, self.is_block_like.iter().cloned()) + self.shared.join_rewrites(context, child_shape) } fn pure_root(&mut self) -> Option { @@ -841,8 +827,7 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> { } fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option { - self.shared - .join_rewrites(context, child_shape, iter::repeat(false)) + self.shared.join_rewrites(context, child_shape) } fn pure_root(&mut self) -> Option { From d4f7e219dcd74989f695fe261534cc8fef5b1477 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Wed, 19 Sep 2018 23:21:07 +0900 Subject: [PATCH 3/4] Fix shape for index --- src/expr.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/expr.rs b/src/expr.rs index fef4a024cf5e..a5d1cdd55830 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1486,7 +1486,12 @@ fn rewrite_index( .offset_left(offset) .and_then(|shape| shape.sub_width(1 + rhs_overhead)) } else { - shape.visual_indent(offset).sub_width(offset + 1) + match context.config.indent_style() { + IndentStyle::Block => shape + .offset_left(offset) + .and_then(|shape| shape.sub_width(1)), + IndentStyle::Visual => shape.visual_indent(offset).sub_width(offset + 1), + } }; let orig_index_rw = index_shape.and_then(|s| index.rewrite(context, s)); From e2b9c66cc9d3228339d07cb5410f6cabdac97de8 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Wed, 19 Sep 2018 23:22:26 +0900 Subject: [PATCH 4/4] Cargo fmt --- src/attr.rs | 3 ++- src/bin/main.rs | 3 ++- src/cargo-fmt/main.rs | 3 ++- src/chains.rs | 6 ++++-- src/closures.rs | 9 ++++++--- src/comment.rs | 12 ++++++++---- src/config/file_lines.rs | 3 ++- src/config/options.rs | 3 ++- src/expr.rs | 9 ++++++--- src/formatting.rs | 3 ++- src/git-rustfmt/main.rs | 3 ++- src/imports.rs | 12 ++++++++---- src/items.rs | 15 ++++++++++----- src/macros.rs | 15 ++++++++++----- src/overflow.rs | 15 ++++++++++----- src/pairs.rs | 3 ++- src/patterns.rs | 3 ++- src/reorder.rs | 6 ++++-- src/rustfmt_diff.rs | 3 ++- src/test/mod.rs | 9 ++++++--- src/types.rs | 3 ++- src/vertical.rs | 9 ++++++--- src/visitor.rs | 3 ++- 23 files changed, 102 insertions(+), 51 deletions(-) diff --git a/src/attr.rs b/src/attr.rs index f8f6cd1c3760..aa1517167d82 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -229,7 +229,8 @@ impl Rewrite for ast::MetaItem { None, &inner_meta_item.ident, shape, - ).map_or(false, |s| s.len() + path.len() + 2 <= shape.width), + ) + .map_or(false, |s| s.len() + path.len() + 2 <= shape.width), _ => false, } } diff --git a/src/bin/main.rs b/src/bin/main.rs index 7069733cae10..8676e6290e0a 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -421,7 +421,8 @@ fn determine_operation(matches: &Matches) -> Result { // we will do comparison later, so here tries to canonicalize first // to get the expected behavior. p.canonicalize().unwrap_or(p) - }).collect(); + }) + .collect(); Ok(Operation::Format { files, diff --git a/src/cargo-fmt/main.rs b/src/cargo-fmt/main.rs index 1ce5ef2fce84..eee102b6bf8b 100644 --- a/src/cargo-fmt/main.rs +++ b/src/cargo-fmt/main.rs @@ -163,7 +163,8 @@ fn format_crate( if verbosity == Verbosity::Verbose { println!("[{}] {:?}", t.kind, t.path) } - }).map(|t| t.path) + }) + .map(|t| t.path) .collect(); run_rustfmt(&files, &rustfmt_args, verbosity) diff --git a/src/chains.rs b/src/chains.rs index 56bd8574fc9d..36c89eef20db 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -558,7 +558,8 @@ impl<'a> ChainFormatterShared<'a> { shape.width } else { min(shape.width, context.config.width_heuristics().chain_width) - }.saturating_sub(almost_total); + } + .saturating_sub(almost_total); let all_in_one_line = !self.children.iter().any(ChainItem::is_comment) && self.rewrites.iter().all(|s| !s.contains('\n')) @@ -710,7 +711,8 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> { shape.block_indent(0) } else { shape.block_indent(context.config.tab_spaces()) - }.with_max_width(context.config), + } + .with_max_width(context.config), ) } diff --git a/src/closures.rs b/src/closures.rs index 3451fcfe6f46..9546451d7ca9 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -198,7 +198,8 @@ fn rewrite_closure_expr( } else { Some(rw) } - }).map(|rw| format!("{} {}", prefix, rw)) + }) + .map(|rw| format!("{} {}", prefix, rw)) } // Rewrite closure whose body is block. @@ -367,8 +368,10 @@ where .map(|e| match e.node { ast::ExprKind::Closure(..) => true, _ => false, - }).unwrap_or(false) - }).count() + }) + .unwrap_or(false) + }) + .count() > 1 } diff --git a/src/comment.rs b/src/comment.rs index 17ec29c3cbc5..e79b9011cbf4 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -370,7 +370,8 @@ fn rewrite_comment_inner( } line - }).map(|s| left_trim_comment_line(s, &style)) + }) + .map(|s| left_trim_comment_line(s, &style)) .map(|(line, has_leading_whitespace)| { if orig.starts_with("/*") && line_breaks == 0 { ( @@ -542,7 +543,8 @@ fn trim_custom_comment_prefix(s: &str) -> String { } else { line } - }).collect::>() + }) + .collect::>() .join("\n") } @@ -630,7 +632,8 @@ fn light_rewrite_comment( }; // Preserve markdown's double-space line break syntax in doc comment. trim_right_unless_two_whitespaces(left_trimmed, is_doc_comment) - }).collect(); + }) + .collect(); Some(lines.join(&format!("\n{}", offset.to_string(config)))) } @@ -1455,7 +1458,8 @@ mod test { .filter_map(|(s, c)| match s { FullCodeCharKind::Normal | FullCodeCharKind::InString => Some(c), _ => None, - }).collect() + }) + .collect() } #[test] diff --git a/src/config/file_lines.rs b/src/config/file_lines.rs index e113118c6430..84ab0a8fc075 100644 --- a/src/config/file_lines.rs +++ b/src/config/file_lines.rs @@ -216,7 +216,8 @@ impl FileLines { .map(|(file, range)| JsonSpan { file: file.to_owned(), range: (range.lo, range.hi), - }).collect(), + }) + .collect(), } } diff --git a/src/config/options.rs b/src/config/options.rs index e1aec1ddea9e..7dca87e17775 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -394,7 +394,8 @@ impl IgnoreList { path.push(s); path } - }).collect(); + }) + .collect(); } fn skip_file_inner(&self, file: &Path) -> bool { diff --git a/src/expr.rs b/src/expr.rs index a5d1cdd55830..674f719b5c74 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1029,7 +1029,8 @@ 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( @@ -1040,7 +1041,8 @@ 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; @@ -1237,7 +1239,8 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt new_indent.to_string(context.config), line.trim_left() ) - }).collect::>() + }) + .collect::>() .join("\n") .trim_left(), ); diff --git a/src/formatting.rs b/src/formatting.rs index 90fb58990982..d940c35f1c73 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -240,7 +240,8 @@ impl FormattingError { fl.file .get_line(fl.lines[0].line_index) .map(|l| l.into_owned()) - }).unwrap_or_else(String::new), + }) + .unwrap_or_else(String::new), } } diff --git a/src/git-rustfmt/main.rs b/src/git-rustfmt/main.rs index 0042ff353a7c..4ad004d3a8b1 100644 --- a/src/git-rustfmt/main.rs +++ b/src/git-rustfmt/main.rs @@ -46,7 +46,8 @@ fn prune_files(files: Vec<&str>) -> Vec<&str> { return true; } pruned_prefixes.iter().all(|pp| !f.starts_with(pp)) - }).collect() + }) + .collect() } fn git_diff(commits: &str) -> String { diff --git a/src/imports.rs b/src/imports.rs index 3ca063a58e72..962d82868d78 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -44,7 +44,8 @@ impl<'a> FmtVisitor<'a> { Some(item.vis.clone()), Some(item.span.lo()), Some(item.attrs.clone()), - ).rewrite_top_level(&self.get_context(), shape); + ) + .rewrite_top_level(&self.get_context(), shape); match rw { Some(ref s) if s.is_empty() => { // Format up to last newline @@ -291,7 +292,8 @@ impl UseTree { } else { Some(item.attrs.clone()) }, - ).normalize(), + ) + .normalize(), ), _ => None, } @@ -345,13 +347,15 @@ impl UseTree { context.snippet_provider.span_after(a.span, "{"), a.span.hi(), false, - ).collect(); + ) + .collect(); result.path.push(UseSegment::List( list.iter() .zip(items.into_iter()) .map(|(t, list_item)| { Self::from_ast(context, &t.0, Some(list_item), None, None, None) - }).collect(), + }) + .collect(), )); } UseTreeKind::Simple(ref rename, ..) => { diff --git a/src/items.rs b/src/items.rs index 44d8889d832b..18b43972051c 100644 --- a/src/items.rs +++ b/src/items.rs @@ -460,7 +460,8 @@ impl<'a> FmtVisitor<'a> { self.block_indent, mk_sp(span.lo(), body_start), last_line_width(&enum_header), - ).unwrap(); + ) + .unwrap(); self.push_str(&generics_str); self.last_pos = body_start; @@ -517,7 +518,8 @@ impl<'a> FmtVisitor<'a> { body_lo, body_hi, false, - ).collect() + ) + .collect() }; let mut items: Vec<_> = itemize_list_with(self.config.width_heuristics().struct_variant_width); @@ -1705,7 +1707,8 @@ fn rewrite_static( lhs, &**expr, Shape::legacy(remaining_width, offset.block_only()), - ).and_then(|res| recover_comment_removed(res, static_parts.span, context)) + ) + .and_then(|res| recover_comment_removed(res, static_parts.span, context)) .map(|s| if s.ends_with(';') { s } else { s + ";" }) } else { Some(format!("{}{};", prefix, ty_str)) @@ -2233,7 +2236,8 @@ fn rewrite_args( .map(|arg| { arg.rewrite(context, Shape::legacy(multi_line_budget, arg_indent)) .unwrap_or_else(|| context.snippet(arg.span()).to_owned()) - }).collect::>(); + }) + .collect::>(); // Account for sugary self. // FIXME: the comment for the self argument is dropped. This is blocked @@ -2815,7 +2819,8 @@ impl Rewrite for ast::ForeignItem { span, false, false, - ).map(|(s, _)| format!("{};", s)), + ) + .map(|(s, _)| format!("{};", s)), ast::ForeignItemKind::Static(ref ty, is_mutable) => { // FIXME(#21): we're dropping potential comments in between the // function keywords here. diff --git a/src/macros.rs b/src/macros.rs index 736333cf44db..282519286faa 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -287,7 +287,8 @@ pub fn rewrite_macro_inner( } else { Some(SeparatorTactic::Never) }, - ).map(|rw| match position { + ) + .map(|rw| match position { MacroPosition::Item => format!("{};", rw), _ => rw, }) @@ -418,7 +419,8 @@ pub fn rewrite_macro_def( context.snippet_provider.span_after(span, "{"), span.hi(), false, - ).collect::>(); + ) + .collect::>(); let fmt = ListFormatting::new(arm_shape, context.config) .separator(if def.legacy { ";" } else { "" }) @@ -1141,7 +1143,8 @@ fn indent_macro_snippet( FullCodeCharKind::InString | FullCodeCharKind::EndString => None, _ => prefix_space_width, } - }).min()?; + }) + .min()?; Some( first_line + "\n" + &trimmed_lines @@ -1157,7 +1160,8 @@ fn indent_macro_snippet( } None => String::new(), }, - ).collect::>() + ) + .collect::>() .join("\n"), ) } @@ -1322,7 +1326,8 @@ impl MacroBranch { } (s + l + "\n", !kind.is_string() || l.ends_with('\\')) }, - ).0; + ) + .0; // Undo our replacement of macro variables. // FIXME: this could be *much* more efficient. diff --git a/src/overflow.rs b/src/overflow.rs index 674eb14b677b..acf6d7b4d387 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -52,7 +52,8 @@ where item_max_width, force_separator_tactic, None, - ).rewrite(shape) + ) + .rewrite(shape) } pub fn rewrite_with_angle_brackets( @@ -76,7 +77,8 @@ where context.config.max_width(), None, None, - ).rewrite(shape) + ) + .rewrite(shape) } pub fn rewrite_with_square_brackets( @@ -107,7 +109,8 @@ where context.config.width_heuristics().array_width, force_separator_tactic, Some(("[", "]")), - ).rewrite(shape) + ) + .rewrite(shape) } struct Context<'a, T: 'a> { @@ -242,7 +245,8 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> { list_items, self.one_line_shape, self.item_max_width, - ).and_then(|arg_shape| { + ) + .and_then(|arg_shape| { self.rewrite_last_item_with_overflow( &mut list_items[self.items.len() - 1], arg_shape, @@ -495,7 +499,8 @@ where Shape { width: min(args_max_width, shape.width), ..shape - }.offset_left(offset) + } + .offset_left(offset) } fn shape_from_indent_style( diff --git a/src/pairs.rs b/src/pairs.rs index 17b869750226..f078022b9e07 100644 --- a/src/pairs.rs +++ b/src/pairs.rs @@ -124,7 +124,8 @@ fn rewrite_pairs_multiline( let nested_shape = (match context.config.indent_style() { IndentStyle::Visual => shape.visual_indent(0), IndentStyle::Block => shape.block_indent(context.config.tab_spaces()), - }).with_max_width(&context.config) + }) + .with_max_width(&context.config) .sub_width(rhs_offset)?; let indent_str = nested_shape.indent.to_string_with_newline(context.config); diff --git a/src/patterns.rs b/src/patterns.rs index d5c4802904b6..13fea046aafa 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -397,7 +397,8 @@ fn count_wildcard_suffix_len( context.snippet_provider.span_after(span, "("), span.hi() - BytePos(1), false, - ).collect(); + ) + .collect(); for item in items.iter().rev().take_while(|i| match i.item { Some(ref internal_string) if internal_string == "_" => true, diff --git a/src/reorder.rs b/src/reorder.rs index 47aae3bfc2ad..f990e6865659 100644 --- a/src/reorder.rs +++ b/src/reorder.rs @@ -140,7 +140,8 @@ fn rewrite_reorderable_items( .map(|use_tree| ListItem { item: use_tree.rewrite_top_level(context, nested_shape), ..use_tree.list_item.unwrap_or_else(ListItem::empty) - }).collect(); + }) + .collect(); wrap_reorderable_items(context, &item_vec, nested_shape) } @@ -237,7 +238,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { last = current; in_same_group }) - }).count(); + }) + .count(); let items = &items[..item_length]; let at_least_one_in_file_lines = items diff --git a/src/rustfmt_diff.rs b/src/rustfmt_diff.rs index 4e0ac31e312e..dbe1c05406ab 100644 --- a/src/rustfmt_diff.rs +++ b/src/rustfmt_diff.rs @@ -207,7 +207,8 @@ where out, "{} {} {}", mismatch.line_number_orig, num_removed, num_added - ).unwrap(); + ) + .unwrap(); for line in mismatch.lines { match line { diff --git a/src/test/mod.rs b/src/test/mod.rs index f7848dfd737d..a9015cedf6a4 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -514,7 +514,8 @@ fn read_significant_comments(file_name: &Path) -> HashMap { .to_owned(), ) }) - }).collect() + }) + .collect() } // Compare output to input. @@ -882,7 +883,8 @@ fn configuration_snippet_tests() { let mut file_iter = BufReader::new( fs::File::open(Path::new(CONFIGURATIONS_FILE_NAME)) .expect(&format!("Couldn't read file {}", CONFIGURATIONS_FILE_NAME)), - ).lines() + ) + .lines() .map(|l| l.unwrap()) .enumerate(); let mut code_blocks: Vec = Vec::new(); @@ -970,6 +972,7 @@ fn verify_check_works() { rustfmt().to_str().unwrap(), "--check", temp_file.path.to_str().unwrap(), - ]).succeeds() + ]) + .succeeds() .unwrap(); } diff --git a/src/types.rs b/src/types.rs index 07794030ba8d..5f71dd6bdc45 100644 --- a/src/types.rs +++ b/src/types.rs @@ -844,7 +844,8 @@ fn rewrite_lifetime_param( .filter(|p| match p.kind { ast::GenericParamKind::Lifetime => true, _ => false, - }).map(|lt| lt.rewrite(context, shape)) + }) + .map(|lt| lt.rewrite(context, shape)) .collect::>>()? .join(", "); if result.is_empty() { diff --git a/src/vertical.rs b/src/vertical.rs index 3f5339201063..d18fa4b9b758 100644 --- a/src/vertical.rs +++ b/src/vertical.rs @@ -200,12 +200,14 @@ fn struct_field_prefix_max_min_width( Some(field_str.len()) } }) - }).fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) { + }) + .fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) { (Some((max_len, min_len)), Some(len)) => { Some((cmp::max(max_len, len), cmp::min(min_len, len))) } _ => None, - }).unwrap_or((0, 0)) + }) + .unwrap_or((0, 0)) } fn rewrite_aligned_items_inner( @@ -236,7 +238,8 @@ fn rewrite_aligned_items_inner( span.lo(), span.hi(), false, - ).collect::>(); + ) + .collect::>(); let tactic = definitive_tactic( &items, diff --git a/src/visitor.rs b/src/visitor.rs index f27a399beed2..ba87efb50527 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -158,7 +158,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { item.attrs.first() } else { first_stmt.attrs().first() - }.and_then(|attr| { + } + .and_then(|attr| { // Some stmts can have embedded attributes. // e.g. `match { #![attr] ... }` let attr_lo = attr.span.lo();