about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Yeh <kevinyeah@utexas.edu>2015-11-24 14:37:31 -0600
committerKevin Yeh <kevinyeah@utexas.edu>2015-11-24 14:37:31 -0600
commitf5fac4c54fda910c33dad2a22cb6d4d59784b00c (patch)
tree6321db82b0bb0daa7c2d3d1daf059ba7898c27d7
parentc408245e5dbe777836b391aa3ecdacc710749ebe (diff)
Fix empty trim_newline panic, add impl macro test
-rw-r--r--src/utils.rs6
-rw-r--r--tests/source/impls.rs7
-rw-r--r--tests/target/impls.rs9
3 files changed, 21 insertions, 1 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 195ca265c1f..aaa838bf043 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -146,7 +146,11 @@ pub fn semicolon_for_stmt(stmt: &ast::Stmt) -> bool {
 pub fn trim_newlines(input: &str) -> &str {
     let start = input.find(|c| c != '\n' && c != '\r').unwrap_or(0);
     let end = input.rfind(|c| c != '\n' && c != '\r').unwrap_or(0) + 1;
-    &input[start..end]
+    if start == 0 && end == 1 {
+        input
+    } else {
+        &input[start..end]
+    }
 }
 
 #[inline]
diff --git a/tests/source/impls.rs b/tests/source/impls.rs
index c15ae12325e..4382c4fd0e6 100644
--- a/tests/source/impls.rs
+++ b/tests/source/impls.rs
@@ -51,3 +51,10 @@ mod b {
         }
     }
 }
+
+impl Foo { add_fun!(); }
+
+impl Blah {
+    fn boop() {}
+    add_fun!();
+}
diff --git a/tests/target/impls.rs b/tests/target/impls.rs
index 972991572a5..35ddc23a20a 100644
--- a/tests/target/impls.rs
+++ b/tests/target/impls.rs
@@ -63,3 +63,12 @@ mod b {
         }
     }
 }
+
+impl Foo {
+    add_fun!();
+}
+
+impl Blah {
+    fn boop() {}
+    add_fun!();
+}