diff --git a/src/utils.rs b/src/utils.rs index 82fbb8d5925ad..5807d4c158cac 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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(), } } diff --git a/tests/target/issue-1055.rs b/tests/target/issue-1055.rs new file mode 100644 index 0000000000000..fed7d7de393fa --- /dev/null +++ b/tests/target/issue-1055.rs @@ -0,0 +1,4 @@ +fn issue_1055() { + let foo = (|| { + })(); +}