Skip to content

Commit

Permalink
Fix empty trim_newline panic, add impl macro test
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeah committed Nov 24, 2015
1 parent c408245 commit f5fac4c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/utils.rs
Expand Up @@ -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 {

This comment has been minimized.

Copy link
@nrc

nrc Nov 26, 2015

I believe that either start and end will both be None or neither will, so if you want the whole span in the None case you can change the 0 in the unwrap_or case to input.len() - 1. Or you could match on the input.find results.

input
} else {
&input[start..end]
}
}

#[inline]
Expand Down
7 changes: 7 additions & 0 deletions tests/source/impls.rs
Expand Up @@ -51,3 +51,10 @@ mod b {
}
}
}

impl Foo { add_fun!(); }

impl Blah {
fn boop() {}
add_fun!();
}
9 changes: 9 additions & 0 deletions tests/target/impls.rs
Expand Up @@ -63,3 +63,12 @@ mod b {
}
}
}

impl Foo {
add_fun!();
}

impl Blah {
fn boop() {}
add_fun!();
}

0 comments on commit f5fac4c

Please sign in to comment.