@@ -358,39 +358,45 @@ impl EmitterWriter {
358
358
let mut annotations_position = vec ! [ ] ;
359
359
let mut line_len = 0 ;
360
360
let mut p = 0 ;
361
- let mut ann_iter = annotations. iter ( ) . peekable ( ) ;
362
- while let Some ( annotation ) = ann_iter . next ( ) {
363
- let peek = ann_iter . peek ( ) ;
364
- if let Some ( next ) = peek {
365
- if overlaps ( next , annotation ) && !annotation . is_line ( ) && !next . is_line ( )
361
+ for ( i , annotation ) in annotations. iter ( ) . enumerate ( ) {
362
+ for ( j , next ) in annotations . iter ( ) . enumerate ( ) {
363
+ if overlaps ( next , annotation , 0 ) // This label overlaps with another one and both
364
+ && !annotation . is_line ( ) // take space (they have text and are not
365
+ && !next . is_line ( ) // multiline lines).
366
366
&& annotation. has_label ( )
367
+ && j > i
368
+ && p == 0 // We're currently on the first line, move the label one line down
367
369
{
368
370
// This annotation needs a new line in the output.
369
371
p += 1 ;
372
+ break ;
370
373
}
371
374
}
372
375
annotations_position. push ( ( p, annotation) ) ;
373
- if let Some ( next) = peek {
374
- let l = if let Some ( ref label) = next. label {
375
- label. len ( ) + 2
376
- } else {
377
- 0
378
- } ;
379
- if ( overlaps ( next, annotation) // Do not allow two labels to be in the same line
380
- || next. end_col + l > annotation. start_col ) // if they overlap including
381
- // padding, to avoid situations like:
382
- //
383
- // fn foo(x: u32) {
384
- // -------^------
385
- // | |
386
- // fn_spanx_span
387
- //
388
- && !annotation. is_line ( ) // Do not add a new line if this annotation or the
389
- && !next. is_line ( ) // next are vertical line placeholders.
390
- && annotation. has_label ( ) // Both labels must have some text, otherwise
391
- && next. has_label ( ) // they are not overlapping.
392
- {
393
- p += 1 ;
376
+ for ( j, next) in annotations. iter ( ) . enumerate ( ) {
377
+ if j > i {
378
+ let l = if let Some ( ref label) = next. label {
379
+ label. len ( ) + 2
380
+ } else {
381
+ 0
382
+ } ;
383
+ if overlaps ( next, annotation, l) // Do not allow two labels to be in the same
384
+ // line if they overlap including padding, to
385
+ // avoid situations like:
386
+ //
387
+ // fn foo(x: u32) {
388
+ // -------^------
389
+ // | |
390
+ // fn_spanx_span
391
+ //
392
+ && !annotation. is_line ( ) // Do not add a new line if this annotation
393
+ && !next. is_line ( ) // or the next are vertical line placeholders.
394
+ && annotation. has_label ( ) // Both labels must have some text, otherwise
395
+ && next. has_label ( ) // they are not overlapping.
396
+ {
397
+ p += 1 ;
398
+ break ;
399
+ }
394
400
}
395
401
}
396
402
if line_len < p {
@@ -1088,8 +1094,8 @@ fn num_overlap(a_start: usize, a_end: usize, b_start: usize, b_end:usize, inclus
1088
1094
( b_start..b_end + extra) . contains ( a_start) ||
1089
1095
( a_start..a_end + extra) . contains ( b_start)
1090
1096
}
1091
- fn overlaps ( a1 : & Annotation , a2 : & Annotation ) -> bool {
1092
- num_overlap ( a1. start_col , a1. end_col , a2. start_col , a2. end_col , false )
1097
+ fn overlaps ( a1 : & Annotation , a2 : & Annotation , padding : usize ) -> bool {
1098
+ num_overlap ( a1. start_col , a1. end_col + padding , a2. start_col , a2. end_col , false )
1093
1099
}
1094
1100
1095
1101
fn emit_to_destination ( rendered_buffer : & Vec < Vec < StyledString > > ,
0 commit comments