about summary refs log tree commit diff
path: root/src
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 /src
parentc408245e5dbe777836b391aa3ecdacc710749ebe (diff)
Fix empty trim_newline panic, add impl macro test
Diffstat (limited to 'src')
-rw-r--r--src/utils.rs6
1 files changed, 5 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]