From f5fac4c54fda910c33dad2a22cb6d4d59784b00c Mon Sep 17 00:00:00 2001 From: Kevin Yeh Date: Tue, 24 Nov 2015 14:37:31 -0600 Subject: [PATCH] Fix empty trim_newline panic, add impl macro test --- src/utils.rs | 6 +++++- tests/source/impls.rs | 7 +++++++ tests/target/impls.rs | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index 195ca265c1fb..aaa838bf043c 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 c15ae12325e0..4382c4fd0e61 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 972991572a50..35ddc23a20a5 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!(); +}