Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When displaying multispans, ignore empty lines adjacent to ... #122029

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | |
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
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
Loading