]> git.lizzy.rs Git - rust.git/commitdiff
Fix off-by-one error in pattern formatting
authorMarcus Klaas <mail@marcusklaas.nl>
Sat, 16 Apr 2016 20:42:15 +0000 (22:42 +0200)
committerMarcus Klaas <mail@marcusklaas.nl>
Sat, 16 Apr 2016 20:42:52 +0000 (22:42 +0200)
src/patterns.rs
tests/source/issue-913.rs [new file with mode: 0644]
tests/target/issue-913.rs [new file with mode: 0644]

index 4285b592fbc652ce8235c3daadf54780b6ba471d..3cec98bb93af2d03dc6753a058e743e1c80d178c 100644 (file)
@@ -76,8 +76,9 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
                         if pat_vec.is_empty() {
                             Some(path_str)
                         } else {
-                            // 1 = (
-                            let width = try_opt!(width.checked_sub(path_str.len() + 1));
+                            // 2 = "()".len()
+                            let width = try_opt!(width.checked_sub(path_str.len() + 2));
+                            // 1 = "(".len()
                             let offset = offset + path_str.len() + 1;
                             let items = itemize_list(context.codemap,
                                                      pat_vec.iter(),
diff --git a/tests/source/issue-913.rs b/tests/source/issue-913.rs
new file mode 100644 (file)
index 0000000..f58a8b0
--- /dev/null
@@ -0,0 +1,20 @@
+mod client {
+    impl Client {
+        fn test(self) -> Result<()> {
+            let next_state = match self.state {
+                State::V5(v5::State::Command(v5::coand::State::WriteVersion(ref mut response))) => {
+                         let x   =   reformat . meeee()  ; 
+                }
+            };
+
+            let next_state = match self.state {
+                State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => {
+                    // The pattern cannot be formatted in a way that the match stays
+                    // within the column limit. The rewrite should therefore be 
+                    // skipped.
+                    let x =  dont . reformat . meeee();
+                }
+            };
+        }
+    }
+}
diff --git a/tests/target/issue-913.rs b/tests/target/issue-913.rs
new file mode 100644 (file)
index 0000000..c7aee5f
--- /dev/null
@@ -0,0 +1,20 @@
+mod client {
+    impl Client {
+        fn test(self) -> Result<()> {
+            let next_state = match self.state {
+                State::V5(v5::State::Command(v5::coand::State::WriteVersion(ref mut response))) => {
+                    let x = reformat.meeee();
+                }
+            };
+
+            let next_state = match self.state {
+                State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => {
+                    // The pattern cannot be formatted in a way that the match stays
+                    // within the column limit. The rewrite should therefore be 
+                    // skipped.
+                    let x =  dont . reformat . meeee();
+                }
+            };
+        }
+    }
+}