Skip to content

Commit 83c635c

Browse files
committed
Account for multiple multiline spans with empty padding
Instead of ``` LL | fn oom( | __^ | | _| | || LL | || ) { | ||_- LL | | } | |__^ ``` emit ``` LL | // fn oom( LL | || ) { | ||_- LL | | } | |__^ ```
1 parent caa64e5 commit 83c635c

File tree

6 files changed

+26
-33
lines changed

6 files changed

+26
-33
lines changed

compiler/rustc_errors/src/emitter.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -845,18 +845,34 @@ impl EmitterWriter {
845845
// 3 | |
846846
// 4 | | }
847847
// | |_^ test
848-
if let [ann] = &line.annotations[..] {
848+
let mut buffer_ops = vec![];
849+
let mut annotations = vec![];
850+
let mut short_start = true;
851+
for ann in &line.annotations {
849852
if let AnnotationType::MultilineStart(depth) = ann.annotation_type {
850853
if source_string.chars().take(ann.start_col).all(|c| c.is_whitespace()) {
851854
let style = if ann.is_primary {
852855
Style::UnderlinePrimary
853856
} else {
854857
Style::UnderlineSecondary
855858
};
856-
buffer.putc(line_offset, width_offset + depth - 1, '/', style);
857-
return vec![(depth, style)];
859+
annotations.push((depth, style));
860+
buffer_ops.push((line_offset, width_offset + depth - 1, '/', style));
861+
} else {
862+
short_start = false;
863+
break;
858864
}
865+
} else if let AnnotationType::MultilineLine(_) = ann.annotation_type {
866+
} else {
867+
short_start = false;
868+
break;
869+
}
870+
}
871+
if short_start {
872+
for (y, x, c, s) in buffer_ops {
873+
buffer.putc(y, x, c, s);
859874
}
875+
return annotations;
860876
}
861877

862878
// We want to display like this:

src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ error[E0308]: mismatched types
33
|
44
LL | #[alloc_error_handler]
55
| ---------------------- in this procedural macro expansion
6-
LL | fn oom(
7-
| __^
8-
| | _|
9-
| ||
6+
LL | // fn oom(
107
LL | || info: &Layout,
118
LL | || ) -> ()
129
| ||_______- arguments to this function are incorrect
@@ -29,10 +26,7 @@ error[E0308]: mismatched types
2926
|
3027
LL | #[alloc_error_handler]
3128
| ---------------------- in this procedural macro expansion
32-
LL | fn oom(
33-
| __^
34-
| | _|
35-
| ||
29+
LL | // fn oom(
3630
LL | || info: &Layout,
3731
LL | || ) -> ()
3832
| ||_______^ expected `!`, found `()`

src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ error[E0308]: mismatched types
33
|
44
LL | #[alloc_error_handler]
55
| ---------------------- in this procedural macro expansion
6-
LL | fn oom(
7-
| __^
8-
| | _|
9-
| ||
6+
LL | // fn oom(
107
LL | || info: Layout,
118
LL | || ) {
129
| ||_- arguments to this function are incorrect
@@ -36,10 +33,7 @@ error[E0308]: mismatched types
3633
|
3734
LL | #[alloc_error_handler]
3835
| ---------------------- in this procedural macro expansion
39-
LL | fn oom(
40-
| __^
41-
| | _|
42-
| ||
36+
LL | // fn oom(
4337
LL | || info: Layout,
4438
LL | || ) {
4539
| ||_^ expected `!`, found `()`

src/test/ui/asm/x86_64/interpolated-idents.stderr

+1-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ error: asm outputs are not allowed with the `noreturn` option
3030
LL | asm!("", $in(x) x, $out(x) x, $lateout(x) x, $inout(x) x, $inlateout(x) x,
3131
| ^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^
3232
...
33-
LL | m!(in out lateout inout inlateout const sym
34-
| _____-
35-
| |_____|
36-
| |_____|
37-
| |_____|
38-
| |
33+
LL | / m!(in out lateout inout inlateout const sym
3934
LL | | pure nomem readonly preserves_flags
4035
LL | | noreturn nostack att_syntax options);
4136
| | -

src/test/ui/issues/issue-13497-2.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
error[E0515]: cannot return value referencing local variable `rawLines`
22
--> $DIR/issue-13497-2.rs:3:5
33
|
4-
LL | rawLines
5-
| ______^
6-
| | _____|
7-
| ||
4+
LL | // rawLines
85
LL | || .iter().map(|l| l.trim()).collect()
96
| ||_______________-___________________________^ returns a value referencing data owned by the current function
107
| |_______________|

src/test/ui/suggestions/issue-99240-2.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ error[E0618]: expected function, found enum variant `Alias::Unit`
44
LL | Unit,
55
| ---- enum variant `Alias::Unit` defined here
66
...
7-
LL | Alias::
8-
| ______^
9-
| | _____|
10-
| ||
7+
LL | // Alias::
118
LL | || Unit();
129
| ||________^_- call expression requires function
1310
| |________|

0 commit comments

Comments
 (0)