@@ -269,7 +269,7 @@ impl<'a> DisplaySet<'a> {
269
269
}
270
270
}
271
271
272
- // Adapted from https://github.com/rust-lang/rust/blob/894f7a4ba6554d3797404bbf550d9919df060b97 /compiler/rustc_errors/src/emitter.rs#L706-L1155
272
+ // Adapted from https://github.com/rust-lang/rust/blob/d371d17496f2ce3a56da76aa083f4ef157572c20 /compiler/rustc_errors/src/emitter.rs#L706-L1211
273
273
#[ inline]
274
274
fn format_line (
275
275
& self ,
@@ -366,7 +366,7 @@ impl<'a> DisplaySet<'a> {
366
366
annotations. sort_by_key ( |a| Reverse ( a. range . 0 ) ) ;
367
367
368
368
let mut annotations_positions = vec ! [ ] ;
369
- let mut line_len = 0 ;
369
+ let mut line_len: usize = 0 ;
370
370
let mut p = 0 ;
371
371
for ( i, annotation) in annotations. iter ( ) . enumerate ( ) {
372
372
for ( j, next) in annotations. iter ( ) . enumerate ( ) {
@@ -442,6 +442,36 @@ impl<'a> DisplaySet<'a> {
442
442
line_len += 1 ;
443
443
}
444
444
445
+ if annotations_positions. iter ( ) . all ( |( _, ann) | {
446
+ matches ! (
447
+ ann. annotation_part,
448
+ DisplayAnnotationPart :: MultilineStart ( _)
449
+ )
450
+ } ) {
451
+ if let Some ( max_pos) =
452
+ annotations_positions. iter ( ) . map ( |( pos, _) | * pos) . max ( )
453
+ {
454
+ // Special case the following, so that we minimize overlapping multiline spans.
455
+ //
456
+ // 3 │ X0 Y0 Z0
457
+ // │ ┏━━━━━┛ │ │ < We are writing these lines
458
+ // │ ┃┌───────┘ │ < by reverting the "depth" of
459
+ // │ ┃│┌─────────┘ < their multilne spans.
460
+ // 4 │ ┃││ X1 Y1 Z1
461
+ // 5 │ ┃││ X2 Y2 Z2
462
+ // │ ┃│└────╿──│──┘ `Z` label
463
+ // │ ┃└─────│──┤
464
+ // │ ┗━━━━━━┥ `Y` is a good letter too
465
+ // ╰╴ `X` is a good letter
466
+ for ( pos, _) in & mut annotations_positions {
467
+ * pos = max_pos - * pos;
468
+ }
469
+ // We know then that we don't need an additional line for the span label, saving us
470
+ // one line of vertical space.
471
+ line_len = line_len. saturating_sub ( 1 ) ;
472
+ }
473
+ }
474
+
445
475
// This is a special case where we have a multiline
446
476
// annotation that is at the start of the line disregarding
447
477
// any leading whitespace, and no other multiline
0 commit comments