Skip to content

Commit 880113e

Browse files
authored
Rollup merge of #144657 - Muscraft:fix-unicode-close-window, r=fee1-dead
fix: Only "close the window" when its the last annotated file While comparing the Unicode theme output of `rustc` and `annotate-snippets`, I found that `rustc` would ["close the window"](https://github.com/rust-lang/rust/blob/686bc1c5f9c06762b18082434c04d514acf6707e/compiler/rustc_errors/src/emitter.rs#L1025-L1027) (draw a `╰╴`), even though there were other annotated files that followed the current one. This PR makes it so the emitter will only "close the window" on the last annotated file. Before: ``` 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 ``` After: ``` 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 ```
2 parents 32e7a4b + 761c4e3 commit 880113e

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,8 +1597,9 @@ impl HumanEmitter {
15971597
annotated_files.swap(0, pos);
15981598
}
15991599

1600+
let annotated_files_len = annotated_files.len();
16001601
// Print out the annotate source lines that correspond with the error
1601-
for annotated_file in annotated_files {
1602+
for (file_idx, annotated_file) in annotated_files.into_iter().enumerate() {
16021603
// we can't annotate anything if the source is unavailable.
16031604
if !should_show_source_code(
16041605
&self.ignored_directories_in_source_blocks,
@@ -1855,7 +1856,9 @@ impl HumanEmitter {
18551856
width_offset,
18561857
code_offset,
18571858
margin,
1858-
!is_cont && line_idx + 1 == annotated_file.lines.len(),
1859+
!is_cont
1860+
&& file_idx + 1 == annotated_files_len
1861+
&& line_idx + 1 == annotated_file.lines.len(),
18591862
);
18601863

18611864
let mut to_add = FxHashMap::default();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub struct S;
2+
impl S {
3+
fn method(&self) {}
4+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0624]: method `method` is private
2+
--> $DIR/close_window.rs:9:7
3+
|
4+
LL | s.method();
5+
| ^^^^^^ private method
6+
|
7+
::: $DIR/auxiliary/close_window.rs:3:5
8+
|
9+
LL | fn method(&self) {}
10+
| ---------------- private method defined here
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0624`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ aux-build:close_window.rs
2+
//@ revisions: ascii unicode
3+
//@[unicode] compile-flags: -Zunstable-options --error-format=human-unicode
4+
5+
extern crate close_window;
6+
7+
fn main() {
8+
let s = close_window::S;
9+
s.method();
10+
//[ascii]~^ ERROR method `method` is private
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0624]: method `method` is private
2+
╭▸ $DIR/close_window.rs:9:7
3+
4+
LL │ s.method();
5+
│ ━━━━━━ private method
6+
7+
⸬ $DIR/auxiliary/close_window.rs:3:5
8+
9+
LL │ fn method(&self) {}
10+
╰╴ ──────────────── private method defined here
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0624`.

0 commit comments

Comments
 (0)