From 554605d47cc2546f32871de5f41ef4008f5d5ecf Mon Sep 17 00:00:00 2001 From: topecongiro Date: Fri, 26 May 2017 16:36:15 +0900 Subject: [PATCH] Format source codes and add tests --- src/chains.rs | 7 +++---- src/expr.rs | 2 +- src/items.rs | 4 +--- tests/source/configs-fn_call_style-block.rs | 4 ++++ tests/target/closure-block-inside-macro.rs | 14 ++++++-------- tests/target/configs-fn_call_style-block.rs | 10 ++++++++++ 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/chains.rs b/src/chains.rs index 9a8a6914440..1c66306022d 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -168,10 +168,9 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) - .into_iter() .chain(::std::iter::repeat(other_child_shape).take(subexpr_list.len() - 1)); let iter = subexpr_list.iter().rev().zip(child_shape_iter); - let mut rewrites = try_opt!(iter.map(|(e, shape)| { - rewrite_chain_subexpr(e, total_span, context, shape) - }) - .collect::>>()); + let mut rewrites = + try_opt!(iter.map(|(e, shape)| rewrite_chain_subexpr(e, total_span, context, shape)) + .collect::>>()); // Total of all items excluding the last. let last_non_try_index = rewrites.len() - (1 + trailing_try_num); diff --git a/src/expr.rs b/src/expr.rs index 0abeafaefc2..21a872489d8 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1782,7 +1782,7 @@ fn rewrite_call_args(context: &RewriteContext, // and not rewriting macro. Some(ref s) if context.config.fn_call_style() == IndentStyle::Block && !context.inside_macro && - ((!can_be_overflowed(&context, args) && last_char_is_not_comma && + ((!can_be_overflowed(context, args) && last_char_is_not_comma && s.contains('\n')) || first_line_width(s) > one_line_budget) => { fmt.trailing_separator = SeparatorTactic::Vertical; diff --git a/src/items.rs b/src/items.rs index 34d2b6ea530..2d9499445cc 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1783,9 +1783,7 @@ fn rewrite_args(context: &RewriteContext, -> Option { let mut arg_item_strs = try_opt!(args.iter() - .map(|arg| { - arg.rewrite(&context, Shape::legacy(multi_line_budget, arg_indent)) - }) + .map(|arg| arg.rewrite(&context, Shape::legacy(multi_line_budget, arg_indent))) .collect::>>()); // Account for sugary self. diff --git a/tests/source/configs-fn_call_style-block.rs b/tests/source/configs-fn_call_style-block.rs index aae6693f43f..2068216d18e 100644 --- a/tests/source/configs-fn_call_style-block.rs +++ b/tests/source/configs-fn_call_style-block.rs @@ -16,6 +16,10 @@ fn main() { .client_credentials(&self.config.auth.oauth2.id, &self.config.auth.oauth2.secret)?; } } + + // nesting macro and function call + try!(foo(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)); + try!(foo(try!(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx))); } // #1521 diff --git a/tests/target/closure-block-inside-macro.rs b/tests/target/closure-block-inside-macro.rs index 5d1e1de0f68..d567008c2ad 100644 --- a/tests/target/closure-block-inside-macro.rs +++ b/tests/target/closure-block-inside-macro.rs @@ -1,13 +1,11 @@ // rustfmt-fn_call_style: Block // #1547 -fuzz_target!(|data: &[u8]| { - if let Some(first) = data.first() { - let index = *first as usize; - if index >= ENCODINGS.len() { - return; - } - let encoding = ENCODINGS[index]; - dispatch_test(encoding, &data[1..]); +fuzz_target!(|data: &[u8]| if let Some(first) = data.first() { + let index = *first as usize; + if index >= ENCODINGS.len() { + return; } + let encoding = ENCODINGS[index]; + dispatch_test(encoding, &data[1..]); }); diff --git a/tests/target/configs-fn_call_style-block.rs b/tests/target/configs-fn_call_style-block.rs index 2ac5340059c..3da4f648527 100644 --- a/tests/target/configs-fn_call_style-block.rs +++ b/tests/target/configs-fn_call_style-block.rs @@ -32,6 +32,16 @@ fn main() { )?; } } + + // nesting macro and function call + try!(foo( + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, + )); + try!(foo(try!( + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + ))); } // #1521