Skip to content

Commit

Permalink
Auto merge of rust-lang#122029 - estebank:drive-by-ui-test, r=oli-obk
Browse files Browse the repository at this point in the history
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`
```
  • Loading branch information
bors committed Mar 18, 2024
2 parents 3c85e56 + 957c0d3 commit f601f46
Show file tree
Hide file tree
Showing 15 changed files with 323 additions and 35 deletions.
49 changes: 48 additions & 1 deletion compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
},
);
}
}
}
}
}

Expand Down Expand Up @@ -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());
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_expand/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ error: foo
|
2 | fn foo() {
| __________^
3 | |
4 | |
... |
5 | | }
| |___^ test
Expand Down
3 changes: 1 addition & 2 deletions src/tools/clippy/tests/ui/async_yields_async.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
| | ^^^^^^^^^^^^^^^^
| | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
| |_

Expand Down
2 changes: 1 addition & 1 deletion src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4004,7 +4004,7 @@ impl<'test> TestCx<'test> {
};

let stderr = if force_color_svg {
anstyle_svg::Term::new().render_svg(&proc_res.stderr)
anstyle_svg::Term::new().min_width_px(730).render_svg(&proc_res.stderr)
} else if explicit_format {
proc_res.stderr.clone()
} else {
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-ui/lints/check.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -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() {}
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
... |
Expand Down
153 changes: 151 additions & 2 deletions tests/ui/codemap_tests/huge_multispan_highlight.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//@ compile-flags: --error-format=human --color=always
//@ ignore-windows
// Temporary until next release:
//@ ignore-stage2
fn main() {
let x = "foo";
let _ = match true {
true => (
// last line shown in multispan header



Expand Down Expand Up @@ -87,5 +93,148 @@ fn main() {



let y = &mut x; //~ ERROR cannot borrow

),
false => "
",
};
let _ = match true {
true => (

1 // last line shown in multispan header
























































































),
false => "
1 last line shown in multispan
",
};
}
14 changes: 0 additions & 14 deletions tests/ui/codemap_tests/huge_multispan_highlight.stderr

This file was deleted.

Loading

0 comments on commit f601f46

Please sign in to comment.