@@ -99,8 +99,8 @@ impl Margin {
99
99
// ```
100
100
101
101
let mut m = Margin {
102
- whitespace_left : if whitespace_left >= 6 { whitespace_left - 6 } else { 0 } ,
103
- span_left : if span_left >= 6 { span_left - 6 } else { 0 } ,
102
+ whitespace_left : whitespace_left. saturating_sub ( 6 ) ,
103
+ span_left : span_left. saturating_sub ( 6 ) ,
104
104
span_right : span_right + 6 ,
105
105
computed_left : 0 ,
106
106
computed_right : 0 ,
@@ -167,7 +167,7 @@ impl Margin {
167
167
}
168
168
169
169
fn right ( & self , line_len : usize ) -> usize {
170
- if max ( line_len, self . computed_left ) - self . computed_left <= self . column_width {
170
+ if line_len. saturating_sub ( self . computed_left ) <= self . column_width {
171
171
line_len
172
172
} else if self . computed_right > line_len {
173
173
line_len
@@ -941,17 +941,9 @@ impl EmitterWriter {
941
941
Style :: LabelSecondary
942
942
} ;
943
943
let ( pos, col) = if pos == 0 {
944
- ( pos + 1 , if annotation. end_col + 1 > left {
945
- annotation. end_col + 1 - left
946
- } else {
947
- 0
948
- } )
944
+ ( pos + 1 , ( annotation. end_col + 1 ) . saturating_sub ( left) )
949
945
} else {
950
- ( pos + 2 , if annotation. start_col > left {
951
- annotation. start_col - left
952
- } else {
953
- 0
954
- } )
946
+ ( pos + 2 , annotation. start_col . saturating_sub ( left) )
955
947
} ;
956
948
if let Some ( ref label) = annotation. label {
957
949
buffer. puts ( line_offset + pos, code_offset + col, & label, style) ;
@@ -991,11 +983,7 @@ impl EmitterWriter {
991
983
for p in annotation. start_col ..annotation. end_col {
992
984
buffer. putc (
993
985
line_offset + 1 ,
994
- if code_offset + p > left {
995
- code_offset + p - left
996
- } else {
997
- 0
998
- } ,
986
+ ( code_offset + p) . saturating_sub ( left) ,
999
987
underline,
1000
988
style,
1001
989
) ;
0 commit comments