@@ -358,39 +358,45 @@ impl EmitterWriter {
358358 let mut annotations_position = vec ! [ ] ;
359359 let mut line_len = 0 ;
360360 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).
366366 && annotation. has_label ( )
367+ && j > i
368+ && p == 0 // We're currently on the first line, move the label one line down
367369 {
368370 // This annotation needs a new line in the output.
369371 p += 1 ;
372+ break ;
370373 }
371374 }
372375 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+ }
394400 }
395401 }
396402 if line_len < p {
@@ -1088,8 +1094,8 @@ fn num_overlap(a_start: usize, a_end: usize, b_start: usize, b_end:usize, inclus
10881094 ( b_start..b_end + extra) . contains ( a_start) ||
10891095 ( a_start..a_end + extra) . contains ( b_start)
10901096}
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 )
10931099}
10941100
10951101fn emit_to_destination ( rendered_buffer : & Vec < Vec < StyledString > > ,
0 commit comments