@@ -14,7 +14,7 @@ use syntax_pos::{COMMAND_LINE_SP, DUMMY_SP, FileMap, Span, MultiSpan, CharPos};
14
14
15
15
use { Level , CodeSuggestion , DiagnosticBuilder , SubDiagnostic , CodeMapper } ;
16
16
use RenderSpan :: * ;
17
- use snippet:: { Annotation , AnnotationType , Line , StyledString , Style } ;
17
+ use snippet:: { Annotation , AnnotationType , Line , MultilineAnnotation , StyledString , Style } ;
18
18
use styled_buffer:: StyledBuffer ;
19
19
20
20
use std:: io:: prelude:: * ;
@@ -181,12 +181,17 @@ impl EmitterWriter {
181
181
if is_minimized {
182
182
ann. annotation_type = AnnotationType :: Minimized ;
183
183
} else if lo. line != hi. line {
184
- ann . annotation_type = AnnotationType :: Multiline {
184
+ let ml = MultilineAnnotation {
185
185
depth : 1 ,
186
186
line_start : lo. line ,
187
187
line_end : hi. line ,
188
+ start_col : lo. col . 0 ,
189
+ end_col : hi. col . 0 ,
190
+ is_primary : span_label. is_primary ,
191
+ label : span_label. label . clone ( ) ,
188
192
} ;
189
- multiline_annotations. push ( ( lo. file . clone ( ) , ann. clone ( ) ) ) ;
193
+ ann. annotation_type = AnnotationType :: Multiline ( ml. clone ( ) ) ;
194
+ multiline_annotations. push ( ( lo. file . clone ( ) , ml) ) ;
190
195
} ;
191
196
192
197
if !ann. is_multiline ( ) {
@@ -200,65 +205,34 @@ impl EmitterWriter {
200
205
201
206
// Find overlapping multiline annotations, put them at different depths
202
207
multiline_annotations. sort_by ( |a, b| {
203
- if let AnnotationType :: Multiline {
204
- line_start : a_start,
205
- line_end : a_end,
206
- ..
207
- } = a. 1 . annotation_type {
208
- if let AnnotationType :: Multiline {
209
- line_start : b_start,
210
- line_end : b_end,
211
- ..
212
- } = b. 1 . annotation_type {
213
- ( a_start, a_end) . cmp ( & ( b_start, b_end) )
214
- } else {
215
- panic ! ( "tried to sort multiline annotations, but found `{:?}`" , b)
216
- }
217
- } else {
218
- panic ! ( "tried to sort multiline annotations, but found `{:?}`" , a)
219
- }
208
+ ( a. 1 . line_start , a. 1 . line_end ) . cmp ( & ( b. 1 . line_start , b. 1 . line_end ) )
220
209
} ) ;
221
210
for item in multiline_annotations. clone ( ) {
222
211
let ann = item. 1 ;
223
- if let AnnotationType :: Multiline { line_start, line_end, ..} = ann. annotation_type {
224
- for item in multiline_annotations. iter_mut ( ) {
225
- let ref mut a = item. 1 ;
226
- if let AnnotationType :: Multiline {
227
- line_start : start,
228
- line_end : end,
229
- ..
230
- } = a. annotation_type {
231
- // Move all other multiline annotations overlapping with this one
232
- // one level to the right.
233
- if & ann != a && num_overlap ( line_start, line_end, start, end, true ) {
234
- a. annotation_type . increase_depth ( ) ;
235
- } else {
236
- break ;
237
- }
238
- } else {
239
- panic ! ( "tried to find depth for multiline annotation, but found `{:?}`" ,
240
- ann)
241
- } ;
212
+ for item in multiline_annotations. iter_mut ( ) {
213
+ let ref mut a = item. 1 ;
214
+ // Move all other multiline annotations overlapping with this one
215
+ // one level to the right.
216
+ if & ann != a &&
217
+ num_overlap ( ann. line_start , ann. line_end , a. line_start , a. line_end , true )
218
+ {
219
+ a. increase_depth ( ) ;
220
+ } else {
221
+ break ;
242
222
}
243
- } else {
244
- panic ! ( "tried to find depth for multiline annotation, but found `{:?}`" , ann)
245
- } ;
223
+ }
246
224
}
247
225
248
226
let mut max_depth = 0 ; // max overlapping multiline spans
249
227
for ( file, ann) in multiline_annotations {
250
- if let AnnotationType :: Multiline { line_start, line_end, depth} = ann. annotation_type {
251
- if depth > max_depth {
252
- max_depth = depth;
253
- }
254
- add_annotation_to_file ( & mut output, file. clone ( ) , line_start, ann. as_start ( ) ) ;
255
- for line in line_start + 1 ..line_end {
256
- add_annotation_to_file ( & mut output, file. clone ( ) , line, ann. as_line ( ) ) ;
257
- }
258
- add_annotation_to_file ( & mut output, file, line_end, ann. as_end ( ) ) ;
259
- } else {
260
- panic ! ( "non-multiline annotation `{:?}` in `multiline_annotations`!" , ann) ;
228
+ if ann. depth > max_depth {
229
+ max_depth = ann. depth ;
230
+ }
231
+ add_annotation_to_file ( & mut output, file. clone ( ) , ann. line_start , ann. as_start ( ) ) ;
232
+ for line in ann. line_start + 1 ..ann. line_end {
233
+ add_annotation_to_file ( & mut output, file. clone ( ) , line, ann. as_line ( ) ) ;
261
234
}
235
+ add_annotation_to_file ( & mut output, file, ann. line_end , ann. as_end ( ) ) ;
262
236
}
263
237
for file_vec in output. iter_mut ( ) {
264
238
file_vec. multiline_depth = max_depth;
@@ -572,7 +546,7 @@ impl EmitterWriter {
572
546
// | | something about `foo`
573
547
// | something about `fn foo()`
574
548
annotations_position. sort_by ( |a, b| {
575
- fn len ( a : Annotation ) -> usize {
549
+ fn len ( a : & Annotation ) -> usize {
576
550
// Account for usize underflows
577
551
if a. end_col > a. start_col {
578
552
a. end_col - a. start_col
0 commit comments