]> git.lizzy.rs Git - rust.git/commitdiff
Use correct indentaion for vec! with semicolon
authortopecongiro <seuchida@gmail.com>
Fri, 16 Jun 2017 04:57:37 +0000 (13:57 +0900)
committertopecongiro <seuchida@gmail.com>
Fri, 16 Jun 2017 04:57:37 +0000 (13:57 +0900)
src/expr.rs
src/macros.rs
tests/source/issue-1693.rs [new file with mode: 0644]
tests/target/issue-1693.rs [new file with mode: 0644]

index 892e6ef905ead6937eac9c4ccab9434b59a13cd6..1b17ced8a42e195a3a6f6da5aa6b7a282f7395e4 100644 (file)
@@ -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) => {
index cfc14b53adb13e7acfa049df7bbb25ad4d52b44c..88bfb96c5d6a806d9b816bcf5ac72e15e689774b 100644 (file)
@@ -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 (file)
index 0000000..0622ce5
--- /dev/null
@@ -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 (file)
index 0000000..85421a1
--- /dev/null
@@ -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
+    ];
+}