Special case when a code line only has multiline span starts

```
3 |       X0 Y0 Z0
  |  _____^  -  -
  | | _______|  |
  | || _________|
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
```
This commit is contained in:
Esteban Küber 2024-06-23 21:33:59 +00:00
parent 33422e72c8
commit 284437d434
4 changed files with 37 additions and 17 deletions

View File

@ -902,7 +902,7 @@ fn render_source_line(
// <EMPTY LINE> // <EMPTY LINE>
// //
let mut annotations_position = vec![]; let mut annotations_position = vec![];
let mut line_len = 0; let mut line_len: usize = 0;
let mut p = 0; let mut p = 0;
for (i, annotation) in annotations.iter().enumerate() { for (i, annotation) in annotations.iter().enumerate() {
for (j, next) in annotations.iter().enumerate() { for (j, next) in annotations.iter().enumerate() {
@ -973,6 +973,31 @@ fn render_source_line(
return vec![]; return vec![];
} }
if annotations_position
.iter()
.all(|(_, ann)| matches!(ann.annotation_type, AnnotationType::MultilineStart(_)))
&& let Some(max_pos) = annotations_position.iter().map(|(pos, _)| *pos).max()
{
// Special case the following, so that we minimize overlapping multiline spans.
//
// 3 │ X0 Y0 Z0
// │ ┏━━━━━┛ │ │ < We are writing these lines
// │ ┃┌───────┘ │ < by reverting the "depth" of
// │ ┃│┌─────────┘ < their multilne spans.
// 4 │ ┃││ X1 Y1 Z1
// 5 │ ┃││ X2 Y2 Z2
// │ ┃│└────╿──│──┘ `Z` label
// │ ┃└─────│──┤
// │ ┗━━━━━━┥ `Y` is a good letter too
// ╰╴ `X` is a good letter
for (pos, _) in &mut annotations_position {
*pos = max_pos - *pos;
}
// We know then that we don't need an additional line for the span label, saving us
// one line of vertical space.
line_len = line_len.saturating_sub(1);
}
// Write the column separator. // Write the column separator.
// //
// After this we will have: // After this we will have:

View File

@ -322,9 +322,8 @@ fn foo() {
--> test.rs:3:3 --> test.rs:3:3
| |
3 | X0 Y0 3 | X0 Y0
| ___^__- | ____^ -
| |___| | | ______|
| ||
4 | || X1 Y1 4 | || X1 Y1
5 | || X2 Y2 5 | || X2 Y2
| ||____^__- `Y` is a good letter too | ||____^__- `Y` is a good letter too
@ -361,9 +360,8 @@ fn foo() {
--> test.rs:3:3 --> test.rs:3:3
| |
3 | X0 Y0 3 | X0 Y0
| ___^__- | ____^ -
| |___| | | ______|
| ||
4 | || Y1 X1 4 | || Y1 X1
| ||____-__^ `X` is a good letter | ||____-__^ `X` is a good letter
| |____| | |____|
@ -445,10 +443,9 @@ fn foo() {
--> test.rs:3:3 --> test.rs:3:3
| |
3 | X0 Y0 Z0 3 | X0 Y0 Z0
| ___^__-__- | _____^ - -
| |___|__| | | _______| |
| ||___| | || _________|
| |||
4 | ||| X1 Y1 Z1 4 | ||| X1 Y1 Z1
5 | ||| X2 Y2 Z2 5 | ||| X2 Y2 Z2
| |||____^__-__- `Z` label | |||____^__-__- `Z` label

View File

@ -2,9 +2,8 @@ error[E0277]: the type `&mut Context<'_>` may not be safely transferred across a
--> $DIR/async-is-unwindsafe.rs:12:5 --> $DIR/async-is-unwindsafe.rs:12:5
| |
LL | is_unwindsafe(async { LL | is_unwindsafe(async {
| _____^_____________- | ______^ -
| |_____| | | ___________________|
| ||
LL | || LL | ||
LL | || use std::ptr::null; LL | || use std::ptr::null;
LL | || use std::task::{Context, RawWaker, RawWakerVTable, Waker}; LL | || use std::task::{Context, RawWaker, RawWakerVTable, Waker};

View File

@ -41,9 +41,8 @@ warning: variable does not need to be mutable
--> $DIR/suggestions.rs:54:13 --> $DIR/suggestions.rs:54:13
| |
LL | let mut LL | let mut
| ______________^ | _____________^
| | _____________| | |_____________|
| ||
LL | || b = 1; LL | || b = 1;
| ||____________-^ | ||____________-^
| |_____________| | |_____________|