@@ -85,44 +85,56 @@ impl<'a> Iterator for DiffLineIterator<'a> {
85
85
self . current_pos += 1 ;
86
86
match hunk {
87
87
diff:: DiffHunk :: Matching ( text) => {
88
- let lines = text. split_inclusive ( |b| * b == b'\n' ) ;
89
- for line in lines {
90
- self . current_line . has_left_content = true ;
91
- self . current_line . has_right_content = true ;
92
- self . current_line . hunks . push ( DiffHunk :: Matching ( line) ) ;
93
- if line. ends_with ( b"\n " ) {
94
- self . queued_lines . push_back ( self . current_line . clone ( ) ) ;
95
- self . current_line . left_line_number += 1 ;
96
- self . current_line . right_line_number += 1 ;
97
- self . current_line . reset_line ( ) ;
88
+ // TODO: Remove this check once https://github.com/rust-lang/rust/issues/89716
89
+ // has been fixed and released for long enough.
90
+ if !text. is_empty ( ) {
91
+ let lines = text. split_inclusive ( |b| * b == b'\n' ) ;
92
+ for line in lines {
93
+ self . current_line . has_left_content = true ;
94
+ self . current_line . has_right_content = true ;
95
+ self . current_line . hunks . push ( DiffHunk :: Matching ( line) ) ;
96
+ if line. ends_with ( b"\n " ) {
97
+ self . queued_lines . push_back ( self . current_line . clone ( ) ) ;
98
+ self . current_line . left_line_number += 1 ;
99
+ self . current_line . right_line_number += 1 ;
100
+ self . current_line . reset_line ( ) ;
101
+ }
98
102
}
99
103
}
100
104
}
101
105
diff:: DiffHunk :: Different ( contents) => {
102
106
let left = contents[ 0 ] ;
103
107
let right = contents[ 1 ] ;
104
- let left_lines = left. split_inclusive ( |b| * b == b'\n' ) ;
105
- for left_line in left_lines {
106
- self . current_line . has_left_content = true ;
107
- self . current_line
108
- . hunks
109
- . push ( DiffHunk :: Different ( vec ! [ left_line, b"" ] ) ) ;
110
- if left_line. ends_with ( b"\n " ) {
111
- self . queued_lines . push_back ( self . current_line . clone ( ) ) ;
112
- self . current_line . left_line_number += 1 ;
113
- self . current_line . reset_line ( ) ;
108
+ // TODO: Remove this check once https://github.com/rust-lang/rust/issues/89716
109
+ // has been fixed and released for long enough.
110
+ if !left. is_empty ( ) {
111
+ let left_lines = left. split_inclusive ( |b| * b == b'\n' ) ;
112
+ for left_line in left_lines {
113
+ self . current_line . has_left_content = true ;
114
+ self . current_line
115
+ . hunks
116
+ . push ( DiffHunk :: Different ( vec ! [ left_line, b"" ] ) ) ;
117
+ if left_line. ends_with ( b"\n " ) {
118
+ self . queued_lines . push_back ( self . current_line . clone ( ) ) ;
119
+ self . current_line . left_line_number += 1 ;
120
+ self . current_line . reset_line ( ) ;
121
+ }
114
122
}
115
123
}
116
- let right_lines = right. split_inclusive ( |b| * b == b'\n' ) ;
117
- for right_line in right_lines {
118
- self . current_line . has_right_content = true ;
119
- self . current_line
120
- . hunks
121
- . push ( DiffHunk :: Different ( vec ! [ b"" , right_line] ) ) ;
122
- if right_line. ends_with ( b"\n " ) {
123
- self . queued_lines . push_back ( self . current_line . clone ( ) ) ;
124
- self . current_line . right_line_number += 1 ;
125
- self . current_line . reset_line ( ) ;
124
+ // TODO: Remove this check once https://github.com/rust-lang/rust/issues/89716
125
+ // has been fixed and released for long enough.
126
+ if !right. is_empty ( ) {
127
+ let right_lines = right. split_inclusive ( |b| * b == b'\n' ) ;
128
+ for right_line in right_lines {
129
+ self . current_line . has_right_content = true ;
130
+ self . current_line
131
+ . hunks
132
+ . push ( DiffHunk :: Different ( vec ! [ b"" , right_line] ) ) ;
133
+ if right_line. ends_with ( b"\n " ) {
134
+ self . queued_lines . push_back ( self . current_line . clone ( ) ) ;
135
+ self . current_line . right_line_number += 1 ;
136
+ self . current_line . reset_line ( ) ;
137
+ }
126
138
}
127
139
}
128
140
}
0 commit comments