@@ -109,22 +109,26 @@ impl EmitterWriter {
109
109
fn add_annotation_to_file ( file_vec : & mut Vec < FileWithAnnotatedLines > ,
110
110
file : Rc < FileMap > ,
111
111
line_index : usize ,
112
- ann : Annotation ) {
112
+ annotation : Option < Annotation > ) {
113
113
114
+ let ann = match annotation {
115
+ Some ( ref ann) => vec ! [ ann. clone( ) ] ,
116
+ None => vec ! [ ]
117
+ } ;
114
118
for slot in file_vec. iter_mut ( ) {
115
119
// Look through each of our files for the one we're adding to
116
120
if slot. file . name == file. name {
117
121
// See if we already have a line for it
118
122
for line_slot in & mut slot. lines {
119
- if line_slot. line_index == line_index {
120
- line_slot. annotations . push ( ann ) ;
123
+ if line_slot. line_index == line_index && annotation . is_some ( ) {
124
+ line_slot. annotations . push ( annotation . unwrap ( ) ) ;
121
125
return ;
122
126
}
123
127
}
124
128
// We don't have a line yet, create one
125
129
slot. lines . push ( Line {
126
130
line_index : line_index,
127
- annotations : vec ! [ ann] ,
131
+ annotations : ann,
128
132
} ) ;
129
133
slot. lines . sort ( ) ;
130
134
return ;
@@ -135,7 +139,7 @@ impl EmitterWriter {
135
139
file : file,
136
140
lines : vec ! [ Line {
137
141
line_index: line_index,
138
- annotations: vec! [ ann] ,
142
+ annotations: ann,
139
143
} ] ,
140
144
} ) ;
141
145
}
@@ -169,17 +173,24 @@ impl EmitterWriter {
169
173
hi. col = CharPos ( lo. col . 0 + 1 ) ;
170
174
}
171
175
172
- for line in start..end {
173
- add_annotation_to_file ( & mut output,
174
- lo. file . clone ( ) ,
175
- line,
176
- Annotation {
177
- start_col : lo. col . 0 ,
178
- end_col : hi. col . 0 ,
179
- is_primary : span_label. is_primary ,
180
- is_minimized : is_minimized,
181
- label : span_label. label . clone ( ) ,
182
- } ) ;
176
+ add_annotation_to_file ( & mut output,
177
+ lo. file . clone ( ) ,
178
+ lo. line ,
179
+ Some ( Annotation {
180
+ start_col : lo. col . 0 ,
181
+ end_col : hi. col . 0 ,
182
+ is_primary : span_label. is_primary ,
183
+ is_minimized : is_minimized,
184
+ label : span_label. label . clone ( ) ,
185
+ } ) ) ;
186
+ if start != end {
187
+ // Add the rest of the lines, without any annotation
188
+ for line in start+1 ..end {
189
+ add_annotation_to_file ( & mut output,
190
+ lo. file . clone ( ) ,
191
+ line,
192
+ None ) ;
193
+ }
183
194
}
184
195
}
185
196
}
0 commit comments