Merge pull request #1061 from marcusklaas/fix-subtract2

Fix integer underflow in extra_offset
This commit is contained in:
Nick Cameron 2016-06-10 17:23:40 +02:00 committed by GitHub
commit 1743f5caf6
2 changed files with 5 additions and 2 deletions

View File

@ -23,11 +23,10 @@ use rewrite::{Rewrite, RewriteContext};
use SKIP_ANNOTATION;
// Computes the length of a string's last line, minus offset.
#[inline]
pub fn extra_offset(text: &str, offset: Indent) -> usize {
match text.rfind('\n') {
// 1 for newline character
Some(idx) => text.len() - idx - 1 - offset.width(),
Some(idx) => text.len().checked_sub(idx + 1 + offset.width()).unwrap_or(0),
None => text.len(),
}
}

View File

@ -0,0 +1,4 @@
fn issue_1055() {
let foo = (|| {
})();
}