@@ -99,8 +99,8 @@ impl Margin {
9999 // ```
100100
101101 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 ) ,
104104 span_right : span_right + 6 ,
105105 computed_left : 0 ,
106106 computed_right : 0 ,
@@ -167,7 +167,7 @@ impl Margin {
167167 }
168168
169169 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 {
171171 line_len
172172 } else if self . computed_right > line_len {
173173 line_len
@@ -941,17 +941,9 @@ impl EmitterWriter {
941941 Style :: LabelSecondary
942942 } ;
943943 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) )
949945 } 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) )
955947 } ;
956948 if let Some ( ref label) = annotation. label {
957949 buffer. puts ( line_offset + pos, code_offset + col, & label, style) ;
@@ -991,11 +983,7 @@ impl EmitterWriter {
991983 for p in annotation. start_col ..annotation. end_col {
992984 buffer. putc (
993985 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) ,
999987 underline,
1000988 style,
1001989 ) ;
0 commit comments