Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit bb76ba0

Browse files
committed
Prefer saturating_sub
1 parent d394f86 commit bb76ba0

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

rls/src/actions/format.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ impl Rustfmt {
8686
.map(|item| {
8787
// Rustfmt's line indices are 1-based
8888
let start_line = u64::from(item.line_number_orig) - 1;
89-
let removed = u64::from(item.lines_removed);
90-
// If there is only one line and we add them, we may underflow.
91-
let removed = if removed == 0 { 0 } else { removed - 1 };
89+
// Could underflow if we don't remove lines and there's only one
90+
let removed = u64::from(item.lines_removed).saturating_sub(1);
9291
TextEdit {
9392
range: Range {
9493
start: Position::new(start_line, 0),

0 commit comments

Comments
 (0)