From 3e0bf9498a662c3c67f78d583d64a8f9e76ef511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 3 Mar 2024 19:18:25 +0000 Subject: [PATCH 1/4] Fix test for multiline span ui display The compiler output changed in such a way that this test was no longer testing what it was meant to. --- .../codemap_tests/huge_multispan_highlight.rs | 30 +++++++++++++++-- .../huge_multispan_highlight.stderr | 33 +++++++++++++------ 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/tests/ui/codemap_tests/huge_multispan_highlight.rs b/tests/ui/codemap_tests/huge_multispan_highlight.rs index 623c59081d0fe..9e445f73ec742 100644 --- a/tests/ui/codemap_tests/huge_multispan_highlight.rs +++ b/tests/ui/codemap_tests/huge_multispan_highlight.rs @@ -1,5 +1,6 @@ fn main() { - let x = "foo"; + let _ = match true { + true => ( @@ -87,5 +88,30 @@ fn main() { - let y = &mut x; //~ ERROR cannot borrow + + ), + false => " + + + + + + + + + + + + + + + + + + + + + + ", //~^^^^^^^^^^^^^^^^^^^^^^ ERROR `match` arms have incompatible types + }; } diff --git a/tests/ui/codemap_tests/huge_multispan_highlight.stderr b/tests/ui/codemap_tests/huge_multispan_highlight.stderr index d2923875c94cf..6c5f965099dd7 100644 --- a/tests/ui/codemap_tests/huge_multispan_highlight.stderr +++ b/tests/ui/codemap_tests/huge_multispan_highlight.stderr @@ -1,14 +1,27 @@ -error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable - --> $DIR/huge_multispan_highlight.rs:90:13 +error[E0308]: `match` arms have incompatible types + --> $DIR/huge_multispan_highlight.rs:93:18 | -LL | let y = &mut x; - | ^^^^^^ cannot borrow as mutable - | -help: consider changing this to be mutable - | -LL | let mut x = "foo"; - | +++ +LL | let _ = match true { + | ---------- `match` arms have incompatible types +LL | true => ( + | _________________- +LL | | +LL | | +LL | | +... | +LL | | +LL | | ), + | |_________- this is found to be of type `()` +LL | false => " + | __________________^ +LL | | +LL | | +LL | | +... | +LL | | +LL | | ", + | |_________^ expected `()`, found `&str` error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0596`. +For more information about this error, try `rustc --explain E0308`. From 8ea7177af7c267bbe778c387026f657cae5271dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 3 Mar 2024 19:21:44 +0000 Subject: [PATCH 2/4] Move multispan test to svg output --- .../codemap_tests/huge_multispan_highlight.rs | 6 +- .../huge_multispan_highlight.stderr | 27 ------- .../huge_multispan_highlight.svg | 80 +++++++++++++++++++ 3 files changed, 85 insertions(+), 28 deletions(-) delete mode 100644 tests/ui/codemap_tests/huge_multispan_highlight.stderr create mode 100644 tests/ui/codemap_tests/huge_multispan_highlight.svg diff --git a/tests/ui/codemap_tests/huge_multispan_highlight.rs b/tests/ui/codemap_tests/huge_multispan_highlight.rs index 9e445f73ec742..6bf4afb8ebd97 100644 --- a/tests/ui/codemap_tests/huge_multispan_highlight.rs +++ b/tests/ui/codemap_tests/huge_multispan_highlight.rs @@ -1,3 +1,7 @@ +//@ compile-flags: --error-format=human --color=always +//@ ignore-windows +// Temporary until next release: +//@ ignore-stage2 fn main() { let _ = match true { true => ( @@ -112,6 +116,6 @@ fn main() { - ", //~^^^^^^^^^^^^^^^^^^^^^^ ERROR `match` arms have incompatible types + ", }; } diff --git a/tests/ui/codemap_tests/huge_multispan_highlight.stderr b/tests/ui/codemap_tests/huge_multispan_highlight.stderr deleted file mode 100644 index 6c5f965099dd7..0000000000000 --- a/tests/ui/codemap_tests/huge_multispan_highlight.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0308]: `match` arms have incompatible types - --> $DIR/huge_multispan_highlight.rs:93:18 - | -LL | let _ = match true { - | ---------- `match` arms have incompatible types -LL | true => ( - | _________________- -LL | | -LL | | -LL | | -... | -LL | | -LL | | ), - | |_________- this is found to be of type `()` -LL | false => " - | __________________^ -LL | | -LL | | -LL | | -... | -LL | | -LL | | ", - | |_________^ expected `()`, found `&str` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/codemap_tests/huge_multispan_highlight.svg b/tests/ui/codemap_tests/huge_multispan_highlight.svg new file mode 100644 index 0000000000000..cc3449f936890 --- /dev/null +++ b/tests/ui/codemap_tests/huge_multispan_highlight.svg @@ -0,0 +1,80 @@ + + + + + + + error[E0308]: `match` arms have incompatible types + + --> $DIR/huge_multispan_highlight.rs:97:18 + + | + + LL | let _ = match true { + + | ---------- `match` arms have incompatible types + + LL | true => ( + + | _________________- + + LL | | + + LL | | + + LL | | + + ... | + + LL | | + + LL | | ), + + | |_________- this is found to be of type `()` + + LL | false => " + + | __________________^ + + LL | | + + LL | | + + LL | | + + ... | + + LL | | + + LL | | ", + + | |_________^ expected `()`, found `&str` + + + + error: aborting due to 1 previous error + + + + For more information about this error, try `rustc --explain E0308`. + + + + + + From cc9631a371b67ddbe9d2e10668f49e229c2e73eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 5 Mar 2024 16:24:30 +0000 Subject: [PATCH 3/4] 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` ``` --- compiler/rustc_errors/src/emitter.rs | 49 +++++- compiler/rustc_expand/src/tests.rs | 3 +- .../clippy/tests/ui/async_yields_async.stderr | 3 +- .../empty_line_after_outer_attribute.stderr | 3 +- tests/rustdoc-ui/lints/check.stderr | 2 - ...issue-109271-pass-self-into-closure.stderr | 3 +- .../codemap_tests/huge_multispan_highlight.rs | 161 +++++++++++++++--- .../huge_multispan_highlight.svg | 80 ++++++--- .../derive-in-eager-expansion-hang.stderr | 3 +- tests/ui/offset-of/offset-of-tuple.stderr | 1 - .../effective_visibilities_invariants.stderr | 1 - ...-match-prior-arm-bool-expected-unit.stderr | 3 +- 12 files changed, 252 insertions(+), 60 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 4f033e3fefa0f..fceccb7e9b6e5 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -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()); } diff --git a/compiler/rustc_expand/src/tests.rs b/compiler/rustc_expand/src/tests.rs index a3510dc9bff4d..2b0b58eb1d924 100644 --- a/compiler/rustc_expand/src/tests.rs +++ b/compiler/rustc_expand/src/tests.rs @@ -276,8 +276,7 @@ error: foo | 2 | fn foo() { | __________^ -3 | | -4 | | +... | 5 | | } | |___^ test diff --git a/src/tools/clippy/tests/ui/async_yields_async.stderr b/src/tools/clippy/tests/ui/async_yields_async.stderr index f1fae6549de4c..991ad7ae0ae2f 100644 --- a/src/tools/clippy/tests/ui/async_yields_async.stderr +++ b/src/tools/clippy/tests/ui/async_yields_async.stderr @@ -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 | | ^^^^^^^^^^^^^^^^ | | | diff --git a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr index 1b5b00a4a83bb..b43e6e30da220 100644 --- a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr +++ b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr @@ -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) } | |_ diff --git a/tests/rustdoc-ui/lints/check.stderr b/tests/rustdoc-ui/lints/check.stderr index c5ed5d0c3efbe..acdb8128443fd 100644 --- a/tests/rustdoc-ui/lints/check.stderr +++ b/tests/rustdoc-ui/lints/check.stderr @@ -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() {} diff --git a/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr b/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr index 4e3bf1d70429d..a66281a188d72 100644 --- a/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr +++ b/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr @@ -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 ... | diff --git a/tests/ui/codemap_tests/huge_multispan_highlight.rs b/tests/ui/codemap_tests/huge_multispan_highlight.rs index 6bf4afb8ebd97..c2bd393589e01 100644 --- a/tests/ui/codemap_tests/huge_multispan_highlight.rs +++ b/tests/ui/codemap_tests/huge_multispan_highlight.rs @@ -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 + + + + + + + + + + + + + + + + + + + ", }; } diff --git a/tests/ui/codemap_tests/huge_multispan_highlight.svg b/tests/ui/codemap_tests/huge_multispan_highlight.svg index cc3449f936890..403e9961102d5 100644 --- a/tests/ui/codemap_tests/huge_multispan_highlight.svg +++ b/tests/ui/codemap_tests/huge_multispan_highlight.svg @@ -1,4 +1,4 @@ - +