When displaying multispans, ignore empty lines adjacent to `...`

```
error[E0308]: `match` arms have incompatible types
   --> tests/ui/codemap_tests/huge_multispan_highlight.rs:98:18
    |
6   |       let _ = match true {
    |               ---------- `match` arms have incompatible types
7   |           true => (
    |  _________________-
8   | |             // last line shown in multispan header
...   |
96  | |
97  | |         ),
    | |_________- this is found to be of type `()`
98  |           false => "
    |  __________________^
...   |
119 | |
120 | |         ",
    | |_________^ expected `()`, found `&str`

error[E0308]: `match` arms have incompatible types
   --> tests/ui/codemap_tests/huge_multispan_highlight.rs:215:18
    |
122 |       let _ = match true {
    |               ---------- `match` arms have incompatible types
123 |           true => (
    |  _________________-
124 | |
125 | |         1 // last line shown in multispan header
...   |
213 | |
214 | |         ),
    | |_________- this is found to be of type `{integer}`
215 |           false => "
    |  __________________^
216 | |
217 | |
218 | |         1 last line shown in multispan
...   |
237 | |
238 | |         ",
    | |_________^ expected integer, found `&str`
```
This commit is contained in:
Esteban Küber 2024-03-05 16:24:30 +00:00
parent 8ea7177af7
commit cc9631a371
12 changed files with 252 additions and 60 deletions

View File

@ -1638,6 +1638,27 @@ impl HumanEmitter {
*style,
);
}
if let Some(line) = annotated_file.lines.get(line_idx) {
for ann in &line.annotations {
if let AnnotationType::MultilineStart(pos) = ann.annotation_type
{
// In the case where we have elided the entire start of the
// multispan because those lines were empty, we still need
// to draw the `|`s across the `...`.
draw_multiline_line(
&mut buffer,
last_buffer_line_num,
width_offset,
pos,
if ann.is_primary {
Style::UnderlinePrimary
} else {
Style::UnderlineSecondary
},
);
}
}
}
} else if line_idx_delta == 2 {
let unannotated_line = annotated_file
.file
@ -1665,6 +1686,24 @@ impl HumanEmitter {
*style,
);
}
if let Some(line) = annotated_file.lines.get(line_idx) {
for ann in &line.annotations {
if let AnnotationType::MultilineStart(pos) = ann.annotation_type
{
draw_multiline_line(
&mut buffer,
last_buffer_line_num,
width_offset,
pos,
if ann.is_primary {
Style::UnderlinePrimary
} else {
Style::UnderlineSecondary
},
);
}
}
}
}
}
@ -2417,7 +2456,15 @@ impl FileWithAnnotatedLines {
// the beginning doesn't have an underline, but the current logic seems to be
// working correctly.
let middle = min(ann.line_start + 4, ann.line_end);
for line in ann.line_start + 1..middle {
// We'll show up to 4 lines past the beginning of the multispan start.
// We will *not* include the tail of lines that are only whitespace.
let until = (ann.line_start..middle)
.rev()
.filter_map(|line| file.get_line(line - 1).map(|s| (line + 1, s)))
.find(|(_, s)| !s.trim().is_empty())
.map(|(line, _)| line)
.unwrap_or(ann.line_start);
for line in ann.line_start + 1..until {
// Every `|` that joins the beginning of the span (`___^`) to the end (`|__^`).
add_annotation_to_file(&mut output, file.clone(), line, ann.as_line());
}

View File

@ -276,8 +276,7 @@ error: foo
|
2 | fn foo() {
| __________^
3 | |
4 | |
... |
5 | | }
| |___^ test

View File

@ -81,8 +81,7 @@ LL | let _m = async || {
| _______________________-
LL | | println!("I'm bored");
LL | | // Some more stuff
LL | |
LL | | // Finally something to await
... |
LL | | CustomFutureType
| | ^^^^^^^^^^^^^^^^
| | |

View File

@ -22,8 +22,7 @@ error: found an empty line after an outer attribute. Perhaps you forgot to add a
--> tests/ui/empty_line_after_outer_attribute.rs:28:1
|
LL | / #[crate_type = "lib"]
LL | |
LL | |
... |
LL | | fn with_two_newlines() { assert!(true) }
| |_

View File

@ -4,7 +4,6 @@ warning: missing documentation for the crate
LL | / #![feature(rustdoc_missing_doc_code_examples)]
LL | |
LL | |
LL | |
... |
LL | |
LL | | pub fn foo() {}
@ -39,7 +38,6 @@ warning: missing code example in this documentation
LL | / #![feature(rustdoc_missing_doc_code_examples)]
LL | |
LL | |
LL | |
... |
LL | |
LL | | pub fn foo() {}

View File

@ -42,8 +42,7 @@ LL | v.call(|(), this: &mut S| {
| |
LL | |
LL | |
LL | |
LL | | _ = v;
... |
LL | | v.set();
| | - first borrow occurs due to use of `v` in closure
... |

View File

@ -5,6 +5,7 @@
fn main() {
let _ = match true {
true => (
// last line shown in multispan header
@ -95,27 +96,145 @@ fn main() {
),
false => "
",
};
let _ = match true {
true => (
1 // last line shown in multispan header
),
false => "
1 last line shown in multispan
",
};
}

View File

@ -1,4 +1,4 @@
<svg width="740px" height="524px" xmlns="http://www.w3.org/2000/svg">
<svg width="743px" height="848px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
@ -21,7 +21,7 @@
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-ansi256-009 bold">error[E0308]</tspan><tspan class="bold">: `match` arms have incompatible types</tspan>
</tspan>
<tspan x="10px" y="46px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">--&gt; </tspan><tspan>$DIR/huge_multispan_highlight.rs:97:18</tspan>
<tspan x="10px" y="46px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">--&gt; </tspan><tspan>$DIR/huge_multispan_highlight.rs:98:18</tspan>
</tspan>
<tspan x="10px" y="64px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
</tspan>
@ -33,47 +33,83 @@
</tspan>
<tspan x="10px" y="136px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">_________________-</tspan>
</tspan>
<tspan x="10px" y="154px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
<tspan x="10px" y="154px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> // last line shown in multispan header</tspan>
</tspan>
<tspan x="10px" y="172px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
<tspan x="10px" y="172px"><tspan class="fg-ansi256-012 bold">...</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
</tspan>
<tspan x="10px" y="190px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
</tspan>
<tspan x="10px" y="208px"><tspan class="fg-ansi256-012 bold">...</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
<tspan x="10px" y="208px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> ),</tspan>
</tspan>
<tspan x="10px" y="226px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
<tspan x="10px" y="226px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan class="fg-ansi256-012 bold">|_________-</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">this is found to be of type `()`</tspan>
</tspan>
<tspan x="10px" y="244px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> ),</tspan>
<tspan x="10px" y="244px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> false =&gt; "</tspan>
</tspan>
<tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan class="fg-ansi256-012 bold">|_________-</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">this is found to be of type `()`</tspan>
<tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">__________________^</tspan>
</tspan>
<tspan x="10px" y="280px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> false =&gt; "</tspan>
<tspan x="10px" y="280px"><tspan class="fg-ansi256-012 bold">...</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan>
</tspan>
<tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">__________________^</tspan>
<tspan x="10px" y="298px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan>
</tspan>
<tspan x="10px" y="316px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan><tspan> </tspan>
<tspan x="10px" y="316px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan><tspan> ",</tspan>
</tspan>
<tspan x="10px" y="334px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan><tspan> </tspan>
<tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan class="fg-ansi256-009 bold">|_________^</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">expected `()`, found `&amp;str`</tspan>
</tspan>
<tspan x="10px" y="352px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan><tspan> </tspan>
<tspan x="10px" y="352px">
</tspan>
<tspan x="10px" y="370px"><tspan class="fg-ansi256-012 bold">...</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan>
<tspan x="10px" y="370px"><tspan class="fg-ansi256-009 bold">error[E0308]</tspan><tspan class="bold">: `match` arms have incompatible types</tspan>
</tspan>
<tspan x="10px" y="388px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan><tspan> </tspan>
<tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">--&gt; </tspan><tspan>$DIR/huge_multispan_highlight.rs:215:18</tspan>
</tspan>
<tspan x="10px" y="406px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan><tspan> ",</tspan>
<tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
</tspan>
<tspan x="10px" y="424px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan class="fg-ansi256-009 bold">|_________^</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">expected `()`, found `&amp;str`</tspan>
<tspan x="10px" y="424px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> let _ = match true {</tspan>
</tspan>
<tspan x="10px" y="442px">
<tspan x="10px" y="442px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">----------</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">`match` arms have incompatible types</tspan>
</tspan>
<tspan x="10px" y="460px"><tspan class="fg-ansi256-009 bold">error</tspan><tspan class="bold">: aborting due to 1 previous error</tspan>
<tspan x="10px" y="460px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> true =&gt; (</tspan>
</tspan>
<tspan x="10px" y="478px">
<tspan x="10px" y="478px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">_________________-</tspan>
</tspan>
<tspan x="10px" y="496px"><tspan class="bold">For more information about this error, try `rustc --explain E0308`.</tspan>
<tspan x="10px" y="496px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
</tspan>
<tspan x="10px" y="514px">
<tspan x="10px" y="514px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> 1 // last line shown in multispan header</tspan>
</tspan>
<tspan x="10px" y="532px"><tspan class="fg-ansi256-012 bold">...</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
</tspan>
<tspan x="10px" y="550px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
</tspan>
<tspan x="10px" y="568px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> ),</tspan>
</tspan>
<tspan x="10px" y="586px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan class="fg-ansi256-012 bold">|_________-</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">this is found to be of type `{integer}`</tspan>
</tspan>
<tspan x="10px" y="604px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> false =&gt; "</tspan>
</tspan>
<tspan x="10px" y="622px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">__________________^</tspan>
</tspan>
<tspan x="10px" y="640px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan>
</tspan>
<tspan x="10px" y="658px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan>
</tspan>
<tspan x="10px" y="676px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan><tspan> 1 last line shown in multispan</tspan>
</tspan>
<tspan x="10px" y="694px"><tspan class="fg-ansi256-012 bold">...</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan>
</tspan>
<tspan x="10px" y="712px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan>
</tspan>
<tspan x="10px" y="730px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan><tspan> ",</tspan>
</tspan>
<tspan x="10px" y="748px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan class="fg-ansi256-009 bold">|_________^</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">expected integer, found `&amp;str`</tspan>
</tspan>
<tspan x="10px" y="766px">
</tspan>
<tspan x="10px" y="784px"><tspan class="fg-ansi256-009 bold">error</tspan><tspan class="bold">: aborting due to 2 previous errors</tspan>
</tspan>
<tspan x="10px" y="802px">
</tspan>
<tspan x="10px" y="820px"><tspan class="bold">For more information about this error, try `rustc --explain E0308`.</tspan>
</tspan>
<tspan x="10px" y="838px">
</tspan>
</text>

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -4,8 +4,7 @@ error: format argument must be a string literal
LL | / {
LL | | #[derive(Clone)]
LL | | struct S;
LL | |
LL | | ""
... |
LL | | }
| |_____^
...

View File

@ -202,7 +202,6 @@ LL | offset_of!(((u8, u16), (u32, u16, u8)), 0.2);
| | in this macro invocation
LL | | offset_of!(((u8, u16), (u32, u16, u8)), 1.2);
LL | | offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0);
LL | |
... |
|
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -15,7 +15,6 @@ error: module has missing stability attribute
LL | / #![feature(staged_api)]
LL | |
LL | | pub mod m {}
LL | |
... |
LL | |
LL | | fn main() {}

View File

@ -5,8 +5,7 @@ LL | / match i {
LL | | // Add `bool` to the overall `coercion`.
LL | | 0 => true,
| | ---- this is found to be of type `bool`
LL | |
LL | | // Necessary to cause the ICE:
... |
LL | | 1 => true,
| | ---- this is found to be of type `bool`
... |