Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit cf0be8b

Browse files
committed
Replace conditional with min()
1 parent df1bba0 commit cf0be8b

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,8 @@ fn parse_snippet(span: &DiagnosticSpan) -> Option<Snippet> {
116116
let last = &span.text[span.text.len() - 1];
117117

118118
// If we get a DiagnosticSpanLine where highlight_end > text.len(), we prevent an 'out of
119-
// bounds' access by using text.len() - 1 instead.
120-
let last_tail_index = if (last.highlight_end - 1) > last.text.len() {
121-
last.text.len() - 1
122-
} else {
123-
last.highlight_end - 1
124-
};
119+
// bounds' access by making sure the index is within the array bounds.
120+
let last_tail_index = last.highlight_end.min(last.text.len()) - 1;
125121

126122
if span.text.len() > 1 {
127123
body.push('\n');

0 commit comments

Comments
 (0)