Skip to content

fix: Only "close the window" when its the last annotated file #144657

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

Merged
merged 2 commits into from
Jul 31, 2025
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
7 changes: 5 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/error-emitter/auxiliary/close_window.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub struct S;
impl S {
fn method(&self) {}
}
14 changes: 14 additions & 0 deletions tests/ui/error-emitter/close_window.ascii.stderr
Original file line number Diff line number Diff line change
@@ -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`.
11 changes: 11 additions & 0 deletions tests/ui/error-emitter/close_window.rs
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions tests/ui/error-emitter/close_window.unicode.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading