]> git.lizzy.rs Git - rust.git/commitdiff
Fix empty trim_newline panic, add impl macro test
authorKevin Yeh <kevinyeah@utexas.edu>
Tue, 24 Nov 2015 20:37:31 +0000 (14:37 -0600)
committerKevin Yeh <kevinyeah@utexas.edu>
Tue, 24 Nov 2015 20:37:31 +0000 (14:37 -0600)
src/utils.rs
tests/source/impls.rs
tests/target/impls.rs

index 195ca265c1fb43a51e186b0268cbef19938e6362..aaa838bf043c179f9dabe1530ec5d15817b99d7d 100644 (file)
@@ -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]
index c15ae12325e0927f4a4c7b42680219f0173f5033..4382c4fd0e61899464945e284321945caf20babb 100644 (file)
@@ -51,3 +51,10 @@ fn foo() {}
         }
     }
 }
+
+impl Foo { add_fun!(); }
+
+impl Blah {
+    fn boop() {}
+    add_fun!();
+}
index 972991572a50aa10e112e97ebd55a69c9da77d94..35ddc23a20a5e669ee19566fca1598e913f87247 100644 (file)
@@ -63,3 +63,12 @@ fn foo() {}
         }
     }
 }
+
+impl Foo {
+    add_fun!();
+}
+
+impl Blah {
+    fn boop() {}
+    add_fun!();
+}