]> git.lizzy.rs Git - rust.git/commitdiff
Inherit alignment to last else
authortopecongiro <seuchida@gmail.com>
Tue, 9 May 2017 08:33:45 +0000 (17:33 +0900)
committertopecongiro <seuchida@gmail.com>
Tue, 9 May 2017 08:33:45 +0000 (17:33 +0900)
src/expr.rs
tests/source/issue-1468.rs [new file with mode: 0644]
tests/target/issue-1468.rs [new file with mode: 0644]

index 8dfc29c38cc35770ee60d81741bbc0d269945494..6a63e1733d97142ac1a27d6340500346ded53eb3 100644 (file)
@@ -988,8 +988,11 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
 
         if let Some(else_block) = self.else_block {
             // Since this is an else block, we should not indent for the assignment preceding
-            // the original if, so set shape.offset to 0.
-            let shape = Shape { offset: 0, ..shape };
+            // the original if, so set shape.offset to shape.indent.alignment.
+            let shape = Shape {
+                offset: shape.indent.alignment,
+                ..shape
+            };
             let mut last_in_chain = false;
             let rewrite = match else_block.node {
                 // If the else expression is another if-else expression, prevent it
diff --git a/tests/source/issue-1468.rs b/tests/source/issue-1468.rs
new file mode 100644 (file)
index 0000000..1b45aa5
--- /dev/null
@@ -0,0 +1,27 @@
+fn issue1468() {
+euc_jp_decoder_functions!({
+let trail_minus_offset = byte.wrapping_sub(0xA1);
+// Fast-track Hiragana (60% according to Lunde)
+// and Katakana (10% acconding to Lunde).
+if jis0208_lead_minus_offset == 0x03 &&
+trail_minus_offset < 0x53 {
+// Hiragana
+handle.write_upper_bmp(0x3041 + trail_minus_offset as u16)
+} else if jis0208_lead_minus_offset == 0x04 &&
+trail_minus_offset < 0x56 {
+// Katakana
+handle.write_upper_bmp(0x30A1 + trail_minus_offset as u16)
+} else if trail_minus_offset > (0xFE - 0xA1) {
+if byte < 0x80 {
+return (DecoderResult::Malformed(1, 0),
+unread_handle_trail.unread(),
+handle.written());
+}
+return (DecoderResult::Malformed(2, 0),
+unread_handle_trail.consumed(),
+handle.written());
+} else {
+unreachable!();
+}
+});
+}
diff --git a/tests/target/issue-1468.rs b/tests/target/issue-1468.rs
new file mode 100644 (file)
index 0000000..518c31b
--- /dev/null
@@ -0,0 +1,27 @@
+fn issue1468() {
+    euc_jp_decoder_functions!({
+                                  let trail_minus_offset = byte.wrapping_sub(0xA1);
+                                  // Fast-track Hiragana (60% according to Lunde)
+                                  // and Katakana (10% acconding to Lunde).
+                                  if jis0208_lead_minus_offset == 0x03 &&
+                                     trail_minus_offset < 0x53 {
+                                      // Hiragana
+                                      handle.write_upper_bmp(0x3041 + trail_minus_offset as u16)
+                                  } else if jis0208_lead_minus_offset == 0x04 &&
+                                            trail_minus_offset < 0x56 {
+                                      // Katakana
+                                      handle.write_upper_bmp(0x30A1 + trail_minus_offset as u16)
+                                  } else if trail_minus_offset > (0xFE - 0xA1) {
+                                      if byte < 0x80 {
+                                          return (DecoderResult::Malformed(1, 0),
+                                                  unread_handle_trail.unread(),
+                                                  handle.written());
+                                      }
+                                      return (DecoderResult::Malformed(2, 0),
+                                              unread_handle_trail.consumed(),
+                                              handle.written());
+                                  } else {
+                                      unreachable!();
+                                  }
+                              });
+}