Skip to content

Commit 79fe15c

Browse files
authoredNov 28, 2022
Rollup merge of #104795 - estebank:multiline-spans, r=TaKO8Ki
Change multiline span ASCII art visual order Tweak the ASCII art for nested multiline spans so that we minimize line overlaps. Partially addresses #61017.
2 parents f90484d + 136ffa2 commit 79fe15c

12 files changed

+108
-106
lines changed
 

Diff for: ‎compiler/rustc_errors/src/emitter.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@ impl FileWithAnnotatedLines {
22822282
}
22832283

22842284
// Find overlapping multiline annotations, put them at different depths
2285-
multiline_annotations.sort_by_key(|&(_, ref ml)| (ml.line_start, ml.line_end));
2285+
multiline_annotations.sort_by_key(|&(_, ref ml)| (ml.line_start, usize::MAX - ml.line_end));
22862286
for (_, ann) in multiline_annotations.clone() {
22872287
for (_, a) in multiline_annotations.iter_mut() {
22882288
// Move all other multiline annotations overlapping with this one
@@ -2300,8 +2300,14 @@ impl FileWithAnnotatedLines {
23002300
}
23012301

23022302
let mut max_depth = 0; // max overlapping multiline spans
2303-
for (file, ann) in multiline_annotations {
2303+
for (_, ann) in &multiline_annotations {
23042304
max_depth = max(max_depth, ann.depth);
2305+
}
2306+
// Change order of multispan depth to minimize the number of overlaps in the ASCII art.
2307+
for (_, a) in multiline_annotations.iter_mut() {
2308+
a.depth = max_depth - a.depth + 1;
2309+
}
2310+
for (file, ann) in multiline_annotations {
23052311
let mut end_ann = ann.as_end();
23062312
if !ann.overlaps_exactly {
23072313
// avoid output like

Diff for: ‎compiler/rustc_expand/src/tests.rs

+54-54
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ error: foo
272272
--> test.rs:3:3
273273
|
274274
3 | X0 Y0
275-
| ____^__-
276-
| | ___|
275+
| ___^__-
276+
| |___|
277277
| ||
278278
4 | || X1 Y1
279279
5 | || X2 Y2
280280
| ||____^__- `Y` is a good letter too
281-
| |____|
281+
| |_____|
282282
| `X` is a good letter
283283
284284
"#,
@@ -311,12 +311,12 @@ error: foo
311311
--> test.rs:3:3
312312
|
313313
3 | X0 Y0
314-
| ____^__-
315-
| | ___|
314+
| ___^__-
315+
| |___|
316316
| ||
317317
4 | || Y1 X1
318318
| ||____-__^ `X` is a good letter
319-
| |_____|
319+
| |____|
320320
| `Y` is a good letter too
321321
322322
"#,
@@ -351,13 +351,13 @@ error: foo
351351
--> test.rs:3:6
352352
|
353353
3 | X0 Y0 Z0
354-
| ______^
355-
4 | | X1 Y1 Z1
356-
| |_________-
354+
| _______^
355+
4 | | X1 Y1 Z1
356+
| | _________-
357357
5 | || X2 Y2 Z2
358358
| ||____^ `X` is a good letter
359-
6 | | X3 Y3 Z3
360-
| |_____- `Y` is a good letter too
359+
6 | | X3 Y3 Z3
360+
| |____- `Y` is a good letter too
361361
362362
"#,
363363
);
@@ -395,15 +395,15 @@ error: foo
395395
--> test.rs:3:3
396396
|
397397
3 | X0 Y0 Z0
398-
| _____^__-__-
399-
| | ____|__|
400-
| || ___|
398+
| ___^__-__-
399+
| |___|__|
400+
| ||___|
401401
| |||
402402
4 | ||| X1 Y1 Z1
403403
5 | ||| X2 Y2 Z2
404404
| |||____^__-__- `Z` label
405-
| ||____|__|
406-
| |____| `Y` is a good letter too
405+
| ||_____|__|
406+
| |______| `Y` is a good letter too
407407
| `X` is a good letter
408408
409409
"#,
@@ -487,17 +487,17 @@ error: foo
487487
--> test.rs:3:6
488488
|
489489
3 | X0 Y0 Z0
490-
| ______^
491-
4 | | X1 Y1 Z1
492-
| |____^_-
490+
| _______^
491+
4 | | X1 Y1 Z1
492+
| | ____^_-
493493
| ||____|
494-
| | `X` is a good letter
495-
5 | | X2 Y2 Z2
496-
| |____-______- `Y` is a good letter too
497-
| ____|
498-
| |
499-
6 | | X3 Y3 Z3
500-
| |________- `Z`
494+
| | `X` is a good letter
495+
5 | | X2 Y2 Z2
496+
| |___-______- `Y` is a good letter too
497+
| ___|
498+
| |
499+
6 | | X3 Y3 Z3
500+
| |_______- `Z`
501501
502502
"#,
503503
);
@@ -570,14 +570,14 @@ error: foo
570570
--> test.rs:3:6
571571
|
572572
3 | X0 Y0 Z0
573-
| ______^
574-
4 | | X1 Y1 Z1
575-
| |____^____-
573+
| _______^
574+
4 | | X1 Y1 Z1
575+
| | ____^____-
576576
| ||____|
577-
| | `X` is a good letter
578-
5 | | X2 Y2 Z2
579-
6 | | X3 Y3 Z3
580-
| |___________- `Y` is a good letter too
577+
| | `X` is a good letter
578+
5 | | X2 Y2 Z2
579+
6 | | X3 Y3 Z3
580+
| |__________- `Y` is a good letter too
581581
582582
"#,
583583
);
@@ -941,18 +941,18 @@ error: foo
941941
--> test.rs:3:6
942942
|
943943
3 | X0 Y0 Z0
944-
| ______^
945-
4 | | X1 Y1 Z1
946-
| |____^____-
944+
| _______^
945+
4 | | X1 Y1 Z1
946+
| | ____^____-
947947
| ||____|
948-
| | `X` is a good letter
949-
5 | | 1
950-
6 | | 2
951-
7 | | 3
952-
... |
953-
15 | | X2 Y2 Z2
954-
16 | | X3 Y3 Z3
955-
| |___________- `Y` is a good letter too
948+
| | `X` is a good letter
949+
5 | | 1
950+
6 | | 2
951+
7 | | 3
952+
... |
953+
15 | | X2 Y2 Z2
954+
16 | | X3 Y3 Z3
955+
| |__________- `Y` is a good letter too
956956
957957
"#,
958958
);
@@ -996,21 +996,21 @@ error: foo
996996
--> test.rs:3:6
997997
|
998998
3 | X0 Y0 Z0
999-
| ______^
1000-
4 | | 1
1001-
5 | | 2
1002-
6 | | 3
1003-
7 | | X1 Y1 Z1
1004-
| |_________-
999+
| _______^
1000+
4 | | 1
1001+
5 | | 2
1002+
6 | | 3
1003+
7 | | X1 Y1 Z1
1004+
| | _________-
10051005
8 | || 4
10061006
9 | || 5
10071007
10 | || 6
10081008
11 | || X2 Y2 Z2
10091009
| ||__________- `Z` is a good letter too
1010-
... |
1011-
15 | | 10
1012-
16 | | X3 Y3 Z3
1013-
| |_______^ `Y` is a good letter
1010+
... |
1011+
15 | | 10
1012+
16 | | X3 Y3 Z3
1013+
| |________^ `Y` is a good letter
10141014
10151015
"#,
10161016
);

Diff for: ‎src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
44
LL | #[alloc_error_handler]
55
| ---------------------- in this procedural macro expansion
66
LL | fn oom(
7-
| _^
8-
| |_|
7+
| __^
8+
| | _|
99
| ||
1010
LL | || info: &Layout,
1111
LL | || ) -> ()
@@ -30,8 +30,8 @@ error[E0308]: mismatched types
3030
LL | #[alloc_error_handler]
3131
| ---------------------- in this procedural macro expansion
3232
LL | fn oom(
33-
| _^
34-
| |_|
33+
| __^
34+
| | _|
3535
| ||
3636
LL | || info: &Layout,
3737
LL | || ) -> ()

Diff for: ‎src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr

+6-10
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ error[E0308]: mismatched types
44
LL | #[alloc_error_handler]
55
| ---------------------- in this procedural macro expansion
66
LL | fn oom(
7-
| _^
8-
| |_|
7+
| __^
8+
| | _|
99
| ||
1010
LL | || info: Layout,
1111
LL | || ) {
12-
| || -
13-
| ||_|
14-
| | arguments to this function are incorrect
12+
| ||_- arguments to this function are incorrect
1513
LL | | loop {}
1614
LL | | }
1715
| |__^ expected struct `Layout`, found struct `core::alloc::Layout`
@@ -42,14 +40,12 @@ error[E0308]: mismatched types
4240
LL | #[alloc_error_handler]
4341
| ---------------------- in this procedural macro expansion
4442
LL | fn oom(
45-
| _^
46-
| |_|
43+
| __^
44+
| | _|
4745
| ||
4846
LL | || info: Layout,
4947
LL | || ) {
50-
| || ^
51-
| ||_|
52-
| | expected `!`, found `()`
48+
| ||_^ expected `!`, found `()`
5349
LL | | loop {}
5450
LL | | }
5551
| |__- expected `!` because of return type

Diff for: ‎src/test/ui/inference/deref-suggestion.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,19 @@ error[E0308]: `if` and `else` have incompatible types
157157
--> $DIR/deref-suggestion.rs:69:12
158158
|
159159
LL | let val = if true {
160-
| _______________-
161-
LL | | *a
162-
| | -- expected because of this
163-
LL | | } else if true {
164-
| |____________^
160+
| ________________-
161+
LL | | *a
162+
| | -- expected because of this
163+
LL | | } else if true {
164+
| | ____________^
165165
LL | ||
166166
LL | || b
167167
LL | || } else {
168168
LL | || &0
169169
LL | || };
170170
| || ^
171171
| ||_____|
172-
| |______`if` and `else` have incompatible types
172+
| |_____`if` and `else` have incompatible types
173173
| expected `i32`, found `&{integer}`
174174

175175
error: aborting due to 13 previous errors

Diff for: ‎src/test/ui/issues/issue-13497-2.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ error[E0515]: cannot return value referencing local variable `rawLines`
22
--> $DIR/issue-13497-2.rs:3:5
33
|
44
LL | rawLines
5-
| _____^
6-
| |_____|
5+
| ______^
6+
| | _____|
77
| ||
88
LL | || .iter().map(|l| l.trim()).collect()
99
| ||_______________-___________________________^ returns a value referencing data owned by the current function
10-
| |________________|
10+
| |_______________|
1111
| `rawLines` is borrowed here
1212

1313
error: aborting due to previous error

Diff for: ‎src/test/ui/lint/suggestions.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ warning: variable does not need to be mutable
4141
--> $DIR/suggestions.rs:54:13
4242
|
4343
LL | let mut
44-
| _____________^
45-
| |_____________|
44+
| ______________^
45+
| | _____________|
4646
| ||
4747
LL | || b = 1;
4848
| ||____________-^
49-
| |____________|
49+
| |_____________|
5050
| help: remove this `mut`
5151

5252
error: const items should never be `#[no_mangle]`

Diff for: ‎src/test/ui/return/issue-86188-return-not-in-fn-body.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ LL | | }
3535
error[E0572]: return statement outside of function body
3636
--> $DIR/issue-86188-return-not-in-fn-body.rs:36:10
3737
|
38-
LL | / fn main() {
39-
LL | |
40-
LL | | [(); return || {
41-
| |__________^
38+
LL | / fn main() {
39+
LL | |
40+
LL | | [(); return || {
41+
| | __________^
4242
LL | ||
4343
LL | ||
4444
LL | || let tx;
4545
LL | || }];
4646
| ||_____^ the return is part of this body...
47-
LL | | }
48-
| |_- ...not the enclosing function body
47+
LL | | }
48+
| |__- ...not the enclosing function body
4949

5050
error: aborting due to 4 previous errors
5151

Diff for: ‎src/test/ui/suggestions/issue-99240-2.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ LL | Unit,
55
| ---- enum variant `Alias::Unit` defined here
66
...
77
LL | Alias::
8-
| _____^
9-
| |_____|
8+
| ______^
9+
| | _____|
1010
| ||
1111
LL | || Unit();
1212
| ||________^_- call expression requires function
13-
| |_________|
13+
| |________|
1414
|
1515
|
1616
help: `Alias::Unit` is a unit enum variant, and does not take parentheses to be constructed

Diff for: ‎src/test/ui/suggestions/suggest-remove-refs-3.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ error[E0277]: `&&&&&Enumerate<std::slice::Iter<'_, {integer}>>` is not an iterat
22
--> $DIR/suggest-remove-refs-3.rs:6:19
33
|
44
LL | for (i, _) in & & &
5-
| ___________________^
6-
| |___________________|
5+
| ____________________^
6+
| | ___________________|
77
| ||
88
LL | || & &v
99
| ||___________- help: consider removing 5 leading `&`-references

0 commit comments

Comments
 (0)