From 4643d9ad6d09631b663c4f6879103b4d399b1cd8 Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Tue, 22 Jul 2025 05:14:37 -0600 Subject: test: Check close window rendering --- tests/ui/error-emitter/auxiliary/close_window.rs | 4 ++++ tests/ui/error-emitter/close_window.ascii.stderr | 14 ++++++++++++++ tests/ui/error-emitter/close_window.rs | 11 +++++++++++ tests/ui/error-emitter/close_window.unicode.stderr | 14 ++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 tests/ui/error-emitter/auxiliary/close_window.rs create mode 100644 tests/ui/error-emitter/close_window.ascii.stderr create mode 100644 tests/ui/error-emitter/close_window.rs create mode 100644 tests/ui/error-emitter/close_window.unicode.stderr (limited to 'tests') diff --git a/tests/ui/error-emitter/auxiliary/close_window.rs b/tests/ui/error-emitter/auxiliary/close_window.rs new file mode 100644 index 00000000000..e41313b6ab3 --- /dev/null +++ b/tests/ui/error-emitter/auxiliary/close_window.rs @@ -0,0 +1,4 @@ +pub struct S; +impl S { + fn method(&self) {} +} diff --git a/tests/ui/error-emitter/close_window.ascii.stderr b/tests/ui/error-emitter/close_window.ascii.stderr new file mode 100644 index 00000000000..e208b709393 --- /dev/null +++ b/tests/ui/error-emitter/close_window.ascii.stderr @@ -0,0 +1,14 @@ +error[E0624]: method `method` is private + --> $DIR/close_window.rs:9:7 + | +LL | s.method(); + | ^^^^^^ private method + | + ::: $DIR/auxiliary/close_window.rs:3:5 + | +LL | fn method(&self) {} + | ---------------- private method defined here + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0624`. diff --git a/tests/ui/error-emitter/close_window.rs b/tests/ui/error-emitter/close_window.rs new file mode 100644 index 00000000000..879507c287a --- /dev/null +++ b/tests/ui/error-emitter/close_window.rs @@ -0,0 +1,11 @@ +//@ aux-build:close_window.rs +//@ revisions: ascii unicode +//@[unicode] compile-flags: -Zunstable-options --error-format=human-unicode + +extern crate close_window; + +fn main() { + let s = close_window::S; + s.method(); + //[ascii]~^ ERROR method `method` is private +} diff --git a/tests/ui/error-emitter/close_window.unicode.stderr b/tests/ui/error-emitter/close_window.unicode.stderr new file mode 100644 index 00000000000..c24b6939af5 --- /dev/null +++ b/tests/ui/error-emitter/close_window.unicode.stderr @@ -0,0 +1,14 @@ +error[E0624]: method `method` is private + ╭▸ $DIR/close_window.rs:9:7 + │ +LL │ s.method(); + ╰╴ ━━━━━━ private method + │ + ⸬ $DIR/auxiliary/close_window.rs:3:5 + │ +LL │ fn method(&self) {} + ╰╴ ──────────────── private method defined here + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0624`. -- cgit 1.4.1-3-g733a5 From 761c4e308ca17c1d6d893c7d512f579728b1552f Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Tue, 22 Jul 2025 07:55:31 -0600 Subject: fix: Only "close the window" when its the last annotated file --- compiler/rustc_errors/src/emitter.rs | 7 +++++-- tests/ui/error-emitter/close_window.unicode.stderr | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 46a4a186824..3fe525df94f 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1597,8 +1597,9 @@ impl HumanEmitter { annotated_files.swap(0, pos); } + let annotated_files_len = annotated_files.len(); // Print out the annotate source lines that correspond with the error - for annotated_file in annotated_files { + for (file_idx, annotated_file) in annotated_files.into_iter().enumerate() { // we can't annotate anything if the source is unavailable. if !should_show_source_code( &self.ignored_directories_in_source_blocks, @@ -1855,7 +1856,9 @@ impl HumanEmitter { width_offset, code_offset, margin, - !is_cont && line_idx + 1 == annotated_file.lines.len(), + !is_cont + && file_idx + 1 == annotated_files_len + && line_idx + 1 == annotated_file.lines.len(), ); let mut to_add = FxHashMap::default(); diff --git a/tests/ui/error-emitter/close_window.unicode.stderr b/tests/ui/error-emitter/close_window.unicode.stderr index c24b6939af5..56ab6daa278 100644 --- a/tests/ui/error-emitter/close_window.unicode.stderr +++ b/tests/ui/error-emitter/close_window.unicode.stderr @@ -2,7 +2,7 @@ error[E0624]: method `method` is private ╭▸ $DIR/close_window.rs:9:7 │ LL │ s.method(); - ╰╴ ━━━━━━ private method + │ ━━━━━━ private method │ ⸬ $DIR/auxiliary/close_window.rs:3:5 │ -- cgit 1.4.1-3-g733a5