From 4a5871eccc5994366b76627c8f240167e7b12cd6 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Fri, 16 Jun 2017 13:57:37 +0900 Subject: [PATCH] Use correct indentaion for vec! with semicolon --- src/expr.rs | 5 ++--- src/macros.rs | 12 ++++++------ tests/source/issue-1693.rs | 3 +++ tests/target/issue-1693.rs | 10 ++++++++++ 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 tests/source/issue-1693.rs create mode 100644 tests/target/issue-1693.rs diff --git a/src/expr.rs b/src/expr.rs index 892e6ef905e..1b17ced8a42 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -157,9 +157,8 @@ fn format_expr( ast::ExprKind::Loop(..) | ast::ExprKind::While(..) | ast::ExprKind::WhileLet(..) => { - to_control_flow(expr, expr_type).and_then(|control_flow| { - control_flow.rewrite(context, shape) - }) + to_control_flow(expr, expr_type) + .and_then(|control_flow| control_flow.rewrite(context, shape)) } ast::ExprKind::Block(ref block) => block.rewrite(context, shape), ast::ExprKind::Match(ref cond, ref arms) => { diff --git a/src/macros.rs b/src/macros.rs index cfc14b53adb..88bfb96c5d6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -184,7 +184,7 @@ pub fn rewrite_macro( ) } MacroStyle::Brackets => { - let mac_shape = try_opt!(shape.shrink_left(macro_name.len())); + let mac_shape = try_opt!(shape.offset_left(macro_name.len())); // Handle special case: `vec![expr; expr]` if vec_with_semi { let (lbr, rbr) = if context.config.spaces_within_square_brackets() { @@ -194,21 +194,21 @@ pub fn rewrite_macro( }; // 6 = `vec!` + `; ` let total_overhead = lbr.len() + rbr.len() + 6; - let lhs = try_opt!(expr_vec[0].rewrite(context, mac_shape)); - let rhs = try_opt!(expr_vec[1].rewrite(context, mac_shape)); + let nested_shape = mac_shape.block_indent(context.config.tab_spaces()); + let lhs = try_opt!(expr_vec[0].rewrite(context, nested_shape)); + let rhs = try_opt!(expr_vec[1].rewrite(context, nested_shape)); if !lhs.contains('\n') && !rhs.contains('\n') && lhs.len() + rhs.len() + total_overhead <= shape.width { Some(format!("{}{}{}; {}{}", macro_name, lbr, lhs, rhs, rbr)) } else { - let nested_indent = shape.indent.block_indent(context.config); Some(format!( "{}{}\n{}{};\n{}{}\n{}{}", macro_name, lbr, - nested_indent.to_string(context.config), + nested_shape.indent.to_string(context.config), lhs, - nested_indent.to_string(context.config), + nested_shape.indent.to_string(context.config), rhs, shape.indent.to_string(context.config), rbr diff --git a/tests/source/issue-1693.rs b/tests/source/issue-1693.rs new file mode 100644 index 00000000000..0622ce50235 --- /dev/null +++ b/tests/source/issue-1693.rs @@ -0,0 +1,3 @@ +fn issue1693() { + let pixel_data = vec![(f16::from_f32(0.82), f16::from_f32(1.78), f16::from_f32(0.21)); 256 * 256]; +} diff --git a/tests/target/issue-1693.rs b/tests/target/issue-1693.rs new file mode 100644 index 00000000000..85421a123bb --- /dev/null +++ b/tests/target/issue-1693.rs @@ -0,0 +1,10 @@ +fn issue1693() { + let pixel_data = vec![ + ( + f16::from_f32(0.82), + f16::from_f32(1.78), + f16::from_f32(0.21) + ); + 256 * 256 + ]; +}