Special case when a code line only has multiline span starts · rust-lang/rust@284437d

4 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -902,7 +902,7 @@ impl HumanEmitter {

902902

// <EMPTY LINE>

903903

//

904904

let mut annotations_position = vec![];

905-

let mut line_len = 0;

905+

let mut line_len: usize = 0;

906906

let mut p = 0;

907907

for (i, annotation) in annotations.iter().enumerate() {

908908

for (j, next) in annotations.iter().enumerate() {

@@ -973,6 +973,31 @@ impl HumanEmitter {

973973

return vec![];

974974

}

975975
976+

if annotations_position

977+

.iter()

978+

.all(|(_, ann)| matches!(ann.annotation_type, AnnotationType::MultilineStart(_)))

979+

&& let Some(max_pos) = annotations_position.iter().map(|(pos, _)| *pos).max()

980+

{

981+

// Special case the following, so that we minimize overlapping multiline spans.

982+

//

983+

// 3 │ X0 Y0 Z0

984+

// │ ┏━━━━━┛ │ │ < We are writing these lines

985+

// │ ┃┌───────┘ │ < by reverting the "depth" of

986+

// │ ┃│┌─────────┘ < their multilne spans.

987+

// 4 │ ┃││ X1 Y1 Z1

988+

// 5 │ ┃││ X2 Y2 Z2

989+

// │ ┃│└────╿──│──┘ `Z` label

990+

// │ ┃└─────│──┤

991+

// │ ┗━━━━━━┥ `Y` is a good letter too

992+

// ╰╴ `X` is a good letter

993+

for (pos, _) in &mut annotations_position {

994+

*pos = max_pos - *pos;

995+

}

996+

// We know then that we don't need an additional line for the span label, saving us

997+

// one line of vertical space.

998+

line_len = line_len.saturating_sub(1);

999+

}

1000+
9761001

// Write the column separator.

9771002

//

9781003

// After this we will have:

Original file line numberDiff line numberDiff line change

@@ -322,9 +322,8 @@ error: foo

322322

--> test.rs:3:3

323323

|

324324

3 | X0 Y0

325-

| ___^__-

326-

| |___|

327-

| ||

325+

| ____^ -

326+

| | ______|

328327

4 | || X1 Y1

329328

5 | || X2 Y2

330329

| ||____^__- `Y` is a good letter too

@@ -361,9 +360,8 @@ error: foo

361360

--> test.rs:3:3

362361

|

363362

3 | X0 Y0

364-

| ___^__-

365-

| |___|

366-

| ||

363+

| ____^ -

364+

| | ______|

367365

4 | || Y1 X1

368366

| ||____-__^ `X` is a good letter

369367

| |____|

@@ -445,10 +443,9 @@ error: foo

445443

--> test.rs:3:3

446444

|

447445

3 | X0 Y0 Z0

448-

| ___^__-__-

449-

| |___|__|

450-

| ||___|

451-

| |||

446+

| _____^ - -

447+

| | _______| |

448+

| || _________|

452449

4 | ||| X1 Y1 Z1

453450

5 | ||| X2 Y2 Z2

454451

| |||____^__-__- `Z` label

Original file line numberDiff line numberDiff line change

@@ -2,9 +2,8 @@ error[E0277]: the type `&mut Context<'_>` may not be safely transferred across a

22

--> $DIR/async-is-unwindsafe.rs:12:5

33

|

44

LL | is_unwindsafe(async {

5-

| _____^_____________-

6-

| |_____|

7-

| ||

5+

| ______^ -

6+

| | ___________________|

87

LL | ||

98

LL | || use std::ptr::null;

109

LL | || use std::task::{Context, RawWaker, RawWakerVTable, Waker};

Original file line numberDiff line numberDiff line change

@@ -41,9 +41,8 @@ warning: variable does not need to be mutable

4141

--> $DIR/suggestions.rs:54:13

4242

|

4343

LL | let mut

44-

| ______________^

45-

| | _____________|

46-

| ||

44+

| _____________^

45+

| |_____________|

4746

LL | || b = 1;

4847

| ||____________-^

4948

| |_____________|