about summary refs log tree commit diff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorShotaro Yamada <sinkuu@sinkuu.xyz>2018-05-14 21:58:57 +0900
committerShotaro Yamada <sinkuu@sinkuu.xyz>2018-05-15 20:41:43 +0900
commitd1e2b80fb9d3e48a63f7c3c97fc966869da60a2c (patch)
tree628262ab09f44f3399c7e9e9fa85d0d09cf05105 /src/utils.rs
parent45c0b47e6daedcca449cc1e82592e0329fa7d8c0 (diff)
Use saturating_sub
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs5
1 files changed, 1 insertions, 4 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 991ebf16bf2..6c8862b9bf5 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -29,10 +29,7 @@ pub const SKIP_ANNOTATION: &str = "rustfmt::skip";
 pub fn extra_offset(text: &str, shape: Shape) -> usize {
     match text.rfind('\n') {
         // 1 for newline character
-        Some(idx) => text
-            .len()
-            .checked_sub(idx + 1 + shape.used_width())
-            .unwrap_or(0),
+        Some(idx) => text.len().saturating_sub(idx + 1 + shape.used_width()),
         None => text.len(),
     }
 }