]> git.lizzy.rs Git - rust.git/commitdiff
Fix #550: `if` nested in tuple is indented oddly
authorsinkuu <sinkuupump@gmail.com>
Sat, 10 Sep 2016 05:02:05 +0000 (14:02 +0900)
committersinkuu <sinkuupump@gmail.com>
Sat, 17 Sep 2016 01:46:20 +0000 (10:46 +0900)
src/comment.rs
src/expr.rs
tests/source/tuple.rs [new file with mode: 0644]
tests/target/tuple.rs

index 979d3bef90e230aec9a58eadf5a85c465c7e22db..e67a438cbcce55cb1855dd9995658ff76019254f 100644 (file)
@@ -425,10 +425,10 @@ fn next(&mut self) -> Option<Self::Item> {
             None => &self.slice[start_idx..],
         };
         Some((if kind.is_comment() {
-            CodeCharKind::Comment
-        } else {
-            CodeCharKind::Normal
-        },
+                  CodeCharKind::Comment
+              } else {
+                  CodeCharKind::Normal
+              },
               start_idx,
               slice))
     }
index bece2ef91fe568da0475c02558b40563ca350033..a00baf21a8496c7678a9cb22ea4d687ac0954b09 100644 (file)
@@ -1716,11 +1716,16 @@ pub fn rewrite_tuple<'a, I>(context: &RewriteContext,
           <I::Item as Deref>::Target: Rewrite + Spanned + 'a
 {
     let indent = offset + 1;
+    let aligned = RewriteContext { block_indent: indent, ..context.clone() };
+
     // In case of length 1, need a trailing comma
     if items.len() == 1 {
         // 3 = "(" + ",)"
         let budget = try_opt!(width.checked_sub(3));
-        return items.next().unwrap().rewrite(context, budget, indent).map(|s| format!("({},)", s));
+        return items.next()
+            .unwrap()
+            .rewrite(&aligned, budget, indent)
+            .map(|s| format!("({},)", s));
     }
 
     let list_lo = context.codemap.span_after(span, "(");
@@ -1733,7 +1738,7 @@ pub fn rewrite_tuple<'a, I>(context: &RewriteContext,
                                  let inner_width = try_opt!(context.config
                                      .max_width
                                      .checked_sub(indent.width() + 1));
-                                 item.rewrite(context, inner_width, indent)
+                                 item.rewrite(&aligned, inner_width, indent)
                              },
                              list_lo,
                              span.hi - BytePos(1));
diff --git a/tests/source/tuple.rs b/tests/source/tuple.rs
new file mode 100644 (file)
index 0000000..b28e83d
--- /dev/null
@@ -0,0 +1,34 @@
+// Test tuple litterals
+
+fn foo() {
+    let a = (a, a, a, a, a);
+    let aaaaaaaaaaaaaaaa = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaa, aaaaaaaaaaaaaa);
+    let aaaaaaaaaaaaaaaaaaaaaa = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
+                                  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
+                                  aaaaaaaaaaaaaaaaaaaaaaaaa,
+                                  aaaa);
+    let a = (a,);
+
+    let b = (// This is a comment
+             b, // Comment
+             b /* Trailing comment */);
+}
+
+fn a() {
+    ((aaaaaaaa,
+      aaaaaaaaaaaaa,
+      aaaaaaaaaaaaaaaaa,
+      aaaaaaaaaaaaaa,
+      aaaaaaaaaaaaaaaa,
+      aaaaaaaaaaaaaa),)
+}
+
+fn b() {
+    ((bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb),
+     bbbbbbbbbbbbbbbbbb)
+}
+
+fn issue550() {
+    self.visitor.visit_volume(self.level.sector_id(sector), (floor_y,
+    if is_sky_flat(ceil_tex) {from_wad_height(self.height_range.1)} else {ceil_y}));
+}
index a5bcc7f701a717d71dd4ae510757e7647d946fa2..2d1d0b808d78f0f1bc14970b81d776007da939f9 100644 (file)
@@ -27,3 +27,13 @@ fn b() {
     ((bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb),
      bbbbbbbbbbbbbbbbbb)
 }
+
+fn issue550() {
+    self.visitor.visit_volume(self.level.sector_id(sector),
+                              (floor_y,
+                               if is_sky_flat(ceil_tex) {
+                                   from_wad_height(self.height_range.1)
+                               } else {
+                                   ceil_y
+                               }));
+}