@@ -335,43 +335,56 @@ impl EmitterWriter {
335
335
// which is...less weird, at least. In fact, in general, if
336
336
// the rightmost span overlaps with any other span, we should
337
337
// use the "hang below" version, so we can at least make it
338
- // clear where the span *starts*.
338
+ // clear where the span *starts*. There's an exception for this
339
+ // logic, when the labels do not have a message:
340
+ //
341
+ // fn foo(x: u32) {
342
+ // --------------
343
+ // |
344
+ // x_span
345
+ //
346
+ // instead of:
347
+ //
348
+ // fn foo(x: u32) {
349
+ // --------------
350
+ // | |
351
+ // | x_span
352
+ // <EMPTY LINE>
353
+ //
339
354
let mut annotations_position = vec ! [ ] ;
340
355
let mut line_len = 0 ;
341
356
let mut p = 0 ;
342
357
let mut ann_iter = annotations. iter ( ) . peekable ( ) ;
343
358
while let Some ( annotation) = ann_iter. next ( ) {
344
- let is_line = if let AnnotationType :: MultilineLine ( _) = annotation. annotation_type {
345
- true
346
- } else {
347
- false
348
- } ;
349
359
let peek = ann_iter. peek ( ) ;
350
360
if let Some ( next) = peek {
351
- let next_is_line = if let AnnotationType :: MultilineLine ( _) = next. annotation_type {
352
- true
353
- } else {
354
- false
355
- } ;
356
-
357
- if overlaps ( next, annotation) && !is_line && !next_is_line {
361
+ if overlaps ( next, annotation) && !annotation. is_line ( ) && !next. is_line ( )
362
+ && annotation. has_label ( )
363
+ {
364
+ // This annotation needs a new line in the output.
358
365
p += 1 ;
359
366
}
360
367
}
361
368
annotations_position. push ( ( p, annotation) ) ;
362
369
if let Some ( next) = peek {
363
- let next_is_line = if let AnnotationType :: MultilineLine ( _) = next. annotation_type {
364
- true
365
- } else {
366
- false
367
- } ;
368
370
let l = if let Some ( ref label) = next. label {
369
371
label. len ( ) + 2
370
372
} else {
371
373
0
372
374
} ;
373
- if ( overlaps ( next, annotation) || next. end_col + l > annotation. start_col )
374
- && !is_line && !next_is_line
375
+ if ( overlaps ( next, annotation) // Do not allow two labels to be in the same line
376
+ || next. end_col + l > annotation. start_col ) // if they overlap including
377
+ // padding, to avoid situations like:
378
+ //
379
+ // fn foo(x: u32) {
380
+ // -------^------
381
+ // | |
382
+ // fn_spanx_span
383
+ //
384
+ && !annotation. is_line ( ) // Do not add a new line if this annotation or the
385
+ && !next. is_line ( ) // next are vertical line placeholders.
386
+ && annotation. has_label ( ) // Both labels must have some text, otherwise
387
+ && next. has_label ( ) // they are not overlapping.
375
388
{
376
389
p += 1 ;
377
390
}
@@ -408,6 +421,17 @@ impl EmitterWriter {
408
421
return ;
409
422
}
410
423
424
+ // Write the colunmn separator.
425
+ //
426
+ // After this we will have:
427
+ //
428
+ // 2 | fn foo() {
429
+ // |
430
+ // |
431
+ // |
432
+ // 3 |
433
+ // 4 | }
434
+ // |
411
435
for pos in 0 ..line_len + 1 {
412
436
draw_col_separator ( buffer, line_offset + pos + 1 , width_offset - 2 ) ;
413
437
buffer. putc ( line_offset + pos + 1 ,
@@ -468,7 +492,8 @@ impl EmitterWriter {
468
492
Style :: UnderlineSecondary
469
493
} ;
470
494
let pos = pos + 1 ;
471
- if pos > 1 {
495
+
496
+ if pos > 1 && annotation. has_label ( ) {
472
497
for p in line_offset + 1 ..line_offset + pos + 1 {
473
498
buffer. putc ( p,
474
499
code_offset + annotation. start_col ,
@@ -546,16 +571,8 @@ impl EmitterWriter {
546
571
// | | something about `foo`
547
572
// | something about `fn foo()`
548
573
annotations_position. sort_by ( |a, b| {
549
- fn len ( a : & Annotation ) -> usize {
550
- // Account for usize underflows
551
- if a. end_col > a. start_col {
552
- a. end_col - a. start_col
553
- } else {
554
- a. start_col - a. end_col
555
- }
556
- }
557
574
// Decreasing order
558
- len ( a. 1 ) . cmp ( & len ( b. 1 ) ) . reverse ( )
575
+ a. 1 . len ( ) . cmp ( & b. 1 . len ( ) ) . reverse ( )
559
576
} ) ;
560
577
561
578
// Write the underlines.
0 commit comments